diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index f4850ac21..bb8179001 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -5265,7 +5265,12 @@ pub struct ToolUpgradeArgs { /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git, /// URL, or local path sources. - #[arg(long, help_heading = "Resolver options")] + #[arg( + long, + env = EnvVars::UV_NO_SOURCES, + value_parser = clap::builder::BoolishValueParser::new(), + help_heading = "Resolver options", + )] pub no_sources: bool, #[command(flatten)] @@ -6183,7 +6188,12 @@ pub struct InstallerArgs { /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git, /// URL, or local path sources. - #[arg(long, help_heading = "Resolver options")] + #[arg( + long, + env = EnvVars::UV_NO_SOURCES, + value_parser = clap::builder::BoolishValueParser::new(), + help_heading = "Resolver options" + )] pub no_sources: bool, } @@ -6371,7 +6381,12 @@ pub struct ResolverArgs { /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git, /// URL, or local path sources. - #[arg(long, help_heading = "Resolver options")] + #[arg( + long, + env = EnvVars::UV_NO_SOURCES, + value_parser = clap::builder::BoolishValueParser::new(), + help_heading = "Resolver options", + )] pub no_sources: bool, } @@ -6609,7 +6624,12 @@ pub struct ResolverInstallerArgs { /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git, /// URL, or local path sources. - #[arg(long, help_heading = "Resolver options")] + #[arg( + long, + env = EnvVars::UV_NO_SOURCES, + value_parser = clap::builder::BoolishValueParser::new(), + help_heading = "Resolver options", + )] pub no_sources: bool, } diff --git a/crates/uv-static/src/env_vars.rs b/crates/uv-static/src/env_vars.rs index 60a6079ee..c0ddd6f20 100644 --- a/crates/uv-static/src/env_vars.rs +++ b/crates/uv-static/src/env_vars.rs @@ -50,6 +50,11 @@ impl EnvVars { #[attr_added_in("0.4.19")] pub const UV_FIND_LINKS: &'static str = "UV_FIND_LINKS"; + /// Equivalent to the `--no-sources` command-line argument. If set, uv will ignore + /// `[tool.uv.sources]` annotations when resolving dependencies. + #[attr_added_in("0.9.8")] + pub const UV_NO_SOURCES: &'static str = "UV_NO_SOURCES"; + /// Equivalent to the `--cache-dir` command-line argument. If set, uv will use this /// directory for caching instead of the default cache directory. #[attr_added_in("0.0.5")] diff --git a/crates/uv/tests/it/pip_install.rs b/crates/uv/tests/it/pip_install.rs index 2440f9acf..3048f32fe 100644 --- a/crates/uv/tests/it/pip_install.rs +++ b/crates/uv/tests/it/pip_install.rs @@ -10528,10 +10528,12 @@ fn directory_and_group() -> Result<()> { Ok(()) } -/// Regression test that we don't discover workspaces with `--no-sources`. +/// Regression test that we don't discover workspaces with `--no-sources` or the `UV_NO_SOURCES` +/// environment variable. /// /// We have a workspace dependency shadowing a PyPI package and using this package's version to -/// check that by default we respect workspace package, but with `--no-sources`, we ignore them. +/// check that by default we respect workspace package, but with `--no-sources` or `UV_NO_SOURCES=true`, +/// we ignore them. #[test] fn no_sources_workspace_discovery() -> Result<()> { let context = TestContext::new("3.12"); @@ -10633,6 +10635,67 @@ fn no_sources_workspace_discovery() -> Result<()> { "### ); + // Test with UV_NO_SOURCES=true environment variable (should behave same as flag) + uv_snapshot!(context.filters(), context.pip_install() + .arg("--upgrade") + .arg(".") + .env("UV_NO_SOURCES", "true"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved 4 packages in [TIME] + Prepared 2 packages in [TIME] + Uninstalled 2 packages in [TIME] + Installed 2 packages in [TIME] + - anyio==2.0.0 (from file://[TEMP_DIR]/anyio) + + anyio==4.3.0 + ~ foo==1.0.0 (from file://[TEMP_DIR]/) + "### + ); + + // Test UV_NO_SOURCES=false doesn't activate no-sources + uv_snapshot!(context.filters(), context.pip_install() + .arg("--upgrade") + .arg(".") + .env("UV_NO_SOURCES", "false"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved 2 packages in [TIME] + Prepared 2 packages in [TIME] + Uninstalled 2 packages in [TIME] + Installed 2 packages in [TIME] + - anyio==4.3.0 + + anyio==2.0.0 (from file://[TEMP_DIR]/anyio) + ~ foo==1.0.0 (from file://[TEMP_DIR]/) + "### + ); + + // Test that CLI flag overrides env var + uv_snapshot!(context.filters(), context.pip_install() + .arg("--upgrade") + .arg("--no-sources") + .arg(".") + .env("UV_NO_SOURCES", "False"), @r" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved 4 packages in [TIME] + Prepared 2 packages in [TIME] + Uninstalled 2 packages in [TIME] + Installed 2 packages in [TIME] + - anyio==2.0.0 (from file://[TEMP_DIR]/anyio) + + anyio==4.3.0 + ~ foo==1.0.0 (from file://[TEMP_DIR]/) + " + ); + Ok(()) } diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 4f1f447ce..1c0f55461 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -505,7 +505,7 @@ uv run [OPTIONS] [COMMAND]
If a virtual environment is active or found in a current or parent directory, it will be used as if there was no project or workspace.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--no-syncAvoid syncing the virtual environment.
+May also be set with the UV_NO_SOURCES environment variable.
--no-syncAvoid syncing the virtual environment.
Implies --frozen, as the project dependencies will be ignored (i.e., the lockfile will not be updated, since the environment will not be synced regardless).
May also be set with the UV_NO_SYNC environment variable.
--offlineDisable network access.
When disabled, uv will only use locally cached data and locally available files.
@@ -908,7 +908,7 @@ uv add [OPTIONS]For example, spinners or progress bars.
May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--no-syncAvoid syncing the virtual environment
+May also be set with the UV_NO_SOURCES environment variable.
--no-syncAvoid syncing the virtual environment
May also be set with the UV_NO_SYNC environment variable.
--no-workspaceDon't add the dependency as a workspace member.
By default, when adding a dependency that's a local path and is within the workspace directory, uv will add it as a workspace member; pass --no-workspace to add the package as direct path dependency instead.
--offlineDisable network access.
@@ -1102,7 +1102,7 @@ uv remove [OPTIONS]For example, spinners or progress bars.
May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--no-syncAvoid syncing the virtual environment after re-locking the project
+May also be set with the UV_NO_SOURCES environment variable.
--no-syncAvoid syncing the virtual environment after re-locking the project
May also be set with the UV_NO_SYNC environment variable.
--offlineDisable network access.
When disabled, uv will only use locally cached data and locally available files.
May also be set with the UV_OFFLINE environment variable.
--optional optionalRemove the packages from the project's optional dependencies for the specified extra
@@ -1284,7 +1284,7 @@ uv version [OPTIONS] [VALUE]For example, spinners or progress bars.
May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--no-syncAvoid syncing the virtual environment after re-locking the project
+May also be set with the UV_NO_SOURCES environment variable.
--no-syncAvoid syncing the virtual environment after re-locking the project
May also be set with the UV_NO_SYNC environment variable.
--offlineDisable network access.
When disabled, uv will only use locally cached data and locally available files.
May also be set with the UV_OFFLINE environment variable.
--output-format output-formatThe format of the output
@@ -1500,7 +1500,7 @@ uv sync [OPTIONS]For example, spinners or progress bars.
May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--offlineDisable network access.
+May also be set with the UV_NO_SOURCES environment variable.
--offlineDisable network access.
When disabled, uv will only use locally cached data and locally available files.
May also be set with the UV_OFFLINE environment variable.
--only-devOnly include the development dependency group.
The project and its dependencies will be omitted.
@@ -1733,7 +1733,7 @@ uv lock [OPTIONS]For example, spinners or progress bars.
May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--offlineDisable network access.
+May also be set with the UV_NO_SOURCES environment variable.
--offlineDisable network access.
When disabled, uv will only use locally cached data and locally available files.
May also be set with the UV_OFFLINE environment variable.
--prerelease prereleaseThe strategy to use when considering pre-release versions.
By default, uv will accept pre-releases for packages that only publish pre-releases, along with first-party requirements that contain an explicit pre-release marker in the declared specifiers (if-necessary-or-explicit).
For example, spinners or progress bars.
May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--offlineDisable network access.
+May also be set with the UV_NO_SOURCES environment variable.
--offlineDisable network access.
When disabled, uv will only use locally cached data and locally available files.
May also be set with the UV_OFFLINE environment variable.
--only-devOnly include the development dependency group.
The project and its dependencies will be omitted.
@@ -2116,7 +2116,7 @@ uv tree [OPTIONS]For example, spinners or progress bars.
May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--offlineDisable network access.
+May also be set with the UV_NO_SOURCES environment variable.
--offlineDisable network access.
When disabled, uv will only use locally cached data and locally available files.
May also be set with the UV_OFFLINE environment variable.
--only-devOnly include the development dependency group.
The project and its dependencies will be omitted.
@@ -2456,7 +2456,7 @@ uv tool run [OPTIONS] [COMMAND]For example, spinners or progress bars.
May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--offlineDisable network access.
+May also be set with the UV_NO_SOURCES environment variable.
--offlineDisable network access.
When disabled, uv will only use locally cached data and locally available files.
May also be set with the UV_OFFLINE environment variable.
--overrides, --override overridesOverride versions using the given requirements files.
Overrides files are requirements.txt-like files that force a specific version of a requirement to be installed, regardless of the requirements declared by any constituent package, and regardless of whether this would be considered an invalid resolution.
For example, spinners or progress bars.
May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--offlineDisable network access.
+May also be set with the UV_NO_SOURCES environment variable.
--offlineDisable network access.
When disabled, uv will only use locally cached data and locally available files.
May also be set with the UV_OFFLINE environment variable.
--overrides, --override overridesOverride versions using the given requirements files.
Overrides files are requirements.txt-like files that force a specific version of a requirement to be installed, regardless of the requirements declared by any constituent package, and regardless of whether this would be considered an invalid resolution.
For example, spinners or progress bars.
May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--offlineDisable network access.
+May also be set with the UV_NO_SOURCES environment variable.
--offlineDisable network access.
When disabled, uv will only use locally cached data and locally available files.
May also be set with the UV_OFFLINE environment variable.
--prerelease prereleaseThe strategy to use when considering pre-release versions.
By default, uv will accept pre-releases for packages that only publish pre-releases, along with first-party requirements that contain an explicit pre-release marker in the declared specifiers (if-necessary-or-explicit).
For example, spinners or progress bars.
May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--no-strip-extrasInclude extras in the output file.
+May also be set with the UV_NO_SOURCES environment variable.
--no-strip-extrasInclude extras in the output file.
By default, uv strips extras, as any packages pulled in by the extras are already included as dependencies in the output file directly. Further, output files generated with --no-strip-extras cannot be used as constraints files in install and sync invocations.
--no-strip-markersInclude environment markers in the output file.
By default, uv strips environment markers, as the resolution generated by compile is only guaranteed to be correct for the target environment.
For example, spinners or progress bars.
May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--no-verify-hashesDisable validation of hashes in the requirements file.
+May also be set with the UV_NO_SOURCES environment variable.
--no-verify-hashesDisable validation of hashes in the requirements file.
By default, uv will verify any available hashes in the requirements file, but will not require that all requirements have an associated hash. To enforce hash validation, use --require-hashes.
May also be set with the UV_NO_VERIFY_HASHES environment variable.
--offlineDisable network access.
When disabled, uv will only use locally cached data and locally available files.
@@ -4728,7 +4728,7 @@ uv pip install [OPTIONS]May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--no-verify-hashesDisable validation of hashes in the requirements file.
+May also be set with the UV_NO_SOURCES environment variable.
--no-verify-hashesDisable validation of hashes in the requirements file.
By default, uv will verify any available hashes in the requirements file, but will not require that all requirements have an associated hash. To enforce hash validation, use --require-hashes.
May also be set with the UV_NO_VERIFY_HASHES environment variable.
--offlineDisable network access.
When disabled, uv will only use locally cached data and locally available files.
@@ -5745,7 +5745,7 @@ uv build [OPTIONS] [SRC]For example, spinners or progress bars.
May also be set with the UV_NO_PROGRESS environment variable.
--no-python-downloadsDisable automatic downloads of Python.
--no-sourcesIgnore the tool.uv.sources table when resolving dependencies. Used to lock against the standards-compliant, publishable package metadata, as opposed to using any workspace, Git, URL, or local path sources
--no-verify-hashesDisable validation of hashes in the requirements file.
+May also be set with the UV_NO_SOURCES environment variable.
--no-verify-hashesDisable validation of hashes in the requirements file.
By default, uv will verify any available hashes in the requirements file, but will not require that all requirements have an associated hash. To enforce hash validation, use --require-hashes.
May also be set with the UV_NO_VERIFY_HASHES environment variable.
--offlineDisable network access.
When disabled, uv will only use locally cached data and locally available files.
diff --git a/docs/reference/environment.md b/docs/reference/environment.md index a0ff012c8..5c0711549 100644 --- a/docs/reference/environment.md +++ b/docs/reference/environment.md @@ -386,6 +386,12 @@ alias, for backwards compatibility. Equivalent to the `--no-progress` command-line argument. Disables all progress output. For example, spinners and progress bars. +### `UV_NO_SOURCES` +added in `0.9.8` + +Equivalent to the `--no-sources` command-line argument. If set, uv will ignore +`[tool.uv.sources]` annotations when resolving dependencies. + ### `UV_NO_SYNC` added in `0.4.18`