Skip to content

Commit

Permalink
Make uv.sources without --preview non-fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jun 26, 2024
1 parent 963a7b2 commit 7933ac7
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 35 deletions.
4 changes: 1 addition & 3 deletions crates/uv-distribution/src/metadata/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ pub enum LoweringError {
ForbiddenFragment(Url),
#[error("`workspace = false` is not yet supported")]
WorkspaceFalse,
#[error("`tool.uv.sources` is a preview feature; use `--preview` or set `UV_PREVIEW=1` to enable it")]
MissingPreview,
#[error("Editable must refer to a local directory, not a file: `{0}`")]
EditableFile(String),
#[error(transparent)] // Function attaches the context
Expand Down Expand Up @@ -95,7 +93,7 @@ pub(crate) fn lower_requirement(
};

if preview.is_disabled() {
return Err(LoweringError::MissingPreview);
warn_user_once!("`uv.sources` is experimental and may change without warning.");
}

let source = match source {
Expand Down
14 changes: 7 additions & 7 deletions crates/uv/src/commands/project/add.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use anyhow::{Context, Result};

use uv_cache::Cache;
use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode, SetupPyStrategy};
use uv_dispatch::BuildDispatch;
use uv_distribution::pyproject::{Source, SourceError};
use uv_distribution::pyproject_mut::PyProjectTomlMut;
use uv_distribution::{DistributionDatabase, ProjectWorkspace, Workspace};
use uv_git::GitResolver;
use uv_normalize::PackageName;
use uv_requirements::{NamedRequirementsResolver, RequirementsSource, RequirementsSpecification};
use uv_resolver::{FlatIndex, InMemoryIndex};
use uv_toolchain::{ToolchainPreference, ToolchainRequest};
use uv_types::{BuildIsolation, HashStrategy, InFlight};

use uv_cache::Cache;
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode, SetupPyStrategy};
use uv_distribution::{DistributionDatabase, ProjectWorkspace, Workspace};
use uv_normalize::PackageName;
use uv_warnings::warn_user;
use uv_warnings::warn_user_once;

use crate::commands::pip::operations::Modifications;
use crate::commands::pip::resolution_environment;
Expand Down Expand Up @@ -45,7 +45,7 @@ pub(crate) async fn add(
printer: Printer,
) -> Result<ExitStatus> {
if preview.is_disabled() {
warn_user!("`uv add` is experimental and may change without warning.");
warn_user_once!("`uv add` is experimental and may change without warning.");
}

// Find the project in the workspace.
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/project/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use uv_resolver::{
};
use uv_toolchain::{Interpreter, ToolchainPreference, ToolchainRequest};
use uv_types::{BuildIsolation, EmptyInstalledPackages, HashStrategy, InFlight};
use uv_warnings::warn_user;
use uv_warnings::{warn_user, warn_user_once};

use crate::commands::project::{find_requires_python, ProjectError};
use crate::commands::{pip, project, ExitStatus};
Expand All @@ -36,7 +36,7 @@ pub(crate) async fn lock(
printer: Printer,
) -> anyhow::Result<ExitStatus> {
if preview.is_disabled() {
warn_user!("`uv lock` is experimental and may change without warning.");
warn_user_once!("`uv lock` is experimental and may change without warning.");
}

// Find the project requirements.
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/project/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode};
use uv_distribution::pyproject_mut::PyProjectTomlMut;
use uv_distribution::{ProjectWorkspace, Workspace};
use uv_toolchain::{ToolchainPreference, ToolchainRequest};
use uv_warnings::warn_user;
use uv_warnings::{warn_user, warn_user_once};

use crate::commands::pip::operations::Modifications;
use crate::commands::{project, ExitStatus};
Expand All @@ -30,7 +30,7 @@ pub(crate) async fn remove(
printer: Printer,
) -> Result<ExitStatus> {
if preview.is_disabled() {
warn_user!("`uv remove` is experimental and may change without warning.");
warn_user_once!("`uv remove` is experimental and may change without warning.");
}

// Find the project in the workspace.
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use uv_requirements::RequirementsSource;
use uv_toolchain::{
EnvironmentPreference, PythonEnvironment, Toolchain, ToolchainPreference, ToolchainRequest,
};
use uv_warnings::warn_user;
use uv_warnings::warn_user_once;

use crate::commands::pip::operations::Modifications;
use crate::commands::{project, ExitStatus};
Expand All @@ -43,7 +43,7 @@ pub(crate) async fn run(
printer: Printer,
) -> Result<ExitStatus> {
if preview.is_disabled() {
warn_user!("`uv run` is experimental and may change without warning.");
warn_user_once!("`uv run` is experimental and may change without warning.");
}

// Discover and sync the base environment.
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/project/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use uv_normalize::PackageName;
use uv_resolver::{FlatIndex, InMemoryIndex, Lock};
use uv_toolchain::{PythonEnvironment, ToolchainPreference, ToolchainRequest};
use uv_types::{BuildIsolation, HashStrategy, InFlight};
use uv_warnings::warn_user;
use uv_warnings::warn_user_once;

use crate::commands::pip::operations::Modifications;
use crate::commands::project::ProjectError;
Expand All @@ -38,7 +38,7 @@ pub(crate) async fn sync(
printer: Printer,
) -> Result<ExitStatus> {
if preview.is_disabled() {
warn_user!("`uv sync` is experimental and may change without warning.");
warn_user_once!("`uv sync` is experimental and may change without warning.");
}

// Find the project requirements.
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/tool/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use uv_installer::SitePackages;
use uv_requirements::RequirementsSource;
use uv_tool::{entrypoint_paths, find_executable_directory, InstalledTools, Tool};
use uv_toolchain::{EnvironmentPreference, Toolchain, ToolchainPreference, ToolchainRequest};
use uv_warnings::warn_user;
use uv_warnings::warn_user_once;

use crate::commands::project::update_environment;
use crate::commands::ExitStatus;
Expand All @@ -39,7 +39,7 @@ pub(crate) async fn install(
printer: Printer,
) -> Result<ExitStatus> {
if preview.is_disabled() {
warn_user!("`uv tool install` is experimental and may change without warning.");
warn_user_once!("`uv tool install` is experimental and may change without warning.");
}

let installed_tools = InstalledTools::from_settings()?;
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/tool/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use uv_requirements::RequirementsSource;
use uv_toolchain::{
EnvironmentPreference, PythonEnvironment, Toolchain, ToolchainPreference, ToolchainRequest,
};
use uv_warnings::warn_user;
use uv_warnings::warn_user_once;

use crate::commands::project::update_environment;
use crate::commands::ExitStatus;
Expand All @@ -38,7 +38,7 @@ pub(crate) async fn run(
printer: Printer,
) -> Result<ExitStatus> {
if preview.is_disabled() {
warn_user!("`uv tool run` is experimental and may change without warning.");
warn_user_once!("`uv tool run` is experimental and may change without warning.");
}

let (target, args) = command.split();
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/toolchain/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use uv_cache::Cache;
use uv_configuration::PreviewMode;
use uv_fs::Simplified;
use uv_toolchain::{EnvironmentPreference, Toolchain, ToolchainPreference, ToolchainRequest};
use uv_warnings::warn_user;
use uv_warnings::warn_user_once;

use crate::commands::ExitStatus;
use crate::printer::Printer;
Expand All @@ -19,7 +19,7 @@ pub(crate) async fn find(
printer: Printer,
) -> Result<ExitStatus> {
if preview.is_disabled() {
warn_user!("`uv toolchain find` is experimental and may change without warning.");
warn_user_once!("`uv toolchain find` is experimental and may change without warning.");
}

let request = match request {
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/toolchain/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use uv_fs::Simplified;
use uv_toolchain::downloads::{self, DownloadResult, PythonDownload, PythonDownloadRequest};
use uv_toolchain::managed::{InstalledToolchain, InstalledToolchains};
use uv_toolchain::{requests_from_version_file, ToolchainRequest};
use uv_warnings::warn_user;
use uv_warnings::warn_user_once;

use crate::commands::ExitStatus;
use crate::printer::Printer;
Expand All @@ -25,7 +25,7 @@ pub(crate) async fn install(
printer: Printer,
) -> Result<ExitStatus> {
if preview.is_disabled() {
warn_user!("`uv toolchain install` is experimental and may change without warning.");
warn_user_once!("`uv toolchain install` is experimental and may change without warning.");
}

let start = std::time::Instant::now();
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/toolchain/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use uv_toolchain::{
find_toolchains, DiscoveryError, EnvironmentPreference, Toolchain, ToolchainNotFound,
ToolchainPreference, ToolchainRequest, ToolchainSource,
};
use uv_warnings::warn_user;
use uv_warnings::warn_user_once;

use crate::commands::ExitStatus;
use crate::printer::Printer;
Expand All @@ -35,7 +35,7 @@ pub(crate) async fn list(
printer: Printer,
) -> Result<ExitStatus> {
if preview.is_disabled() {
warn_user!("`uv toolchain list` is experimental and may change without warning.");
warn_user_once!("`uv toolchain list` is experimental and may change without warning.");
}

let download_request = match kinds {
Expand Down
15 changes: 8 additions & 7 deletions crates/uv/tests/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5495,16 +5495,17 @@ fn tool_uv_sources_is_in_preview() -> Result<()> {
// Install the editable packages.
uv_snapshot!(context.filters(), windows_filters=false, context.pip_install()
.arg("-r")
.arg("pyproject.toml")
.arg("--extra")
.arg("utils"), @r###"
success: false
exit_code: 2
.arg("pyproject.toml"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
error: Failed to parse entry for: `tqdm`
Caused by: `tool.uv.sources` is a preview feature; use `--preview` or set `UV_PREVIEW=1` to enable it
warning: `uv.sources` is experimental and may change without warning.
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ tqdm==4.66.0 (from https://files.pythonhosted.org/packages/a5/d6/502a859bac4ad5e274255576cd3e15ca273cdb91731bc39fb840dd422ee9/tqdm-4.66.0-py3-none-any.whl)
"###
);

Expand Down

0 comments on commit 7933ac7

Please sign in to comment.