From d3606e5e78fe34f44da90cec39ce1b1ff3ccfe8a Mon Sep 17 00:00:00 2001 From: Pedro Avalos Jimenez Date: Thu, 12 Jun 2025 12:29:38 -0400 Subject: [PATCH 1/2] Add UV_PACKAGE environment variable --- crates/uv-cli/src/lib.rs | 14 +++++++------- crates/uv-static/src/env_vars.rs | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 0b96875e5..3c7f5bdab 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -594,7 +594,7 @@ pub struct VersionArgs { pub refresh: RefreshArgs, /// Update the version of a specific package in the workspace. - #[arg(long, conflicts_with = "isolated")] + #[arg(long, env = EnvVars::UV_PACKAGE, conflicts_with = "isolated")] pub package: Option, /// The Python interpreter to use for resolving and syncing. @@ -2397,7 +2397,7 @@ pub struct BuildArgs { /// directory if no source directory is provided. /// /// If the workspace member does not exist, uv will exit with an error. - #[arg(long, conflicts_with("all_packages"))] + #[arg(long, env = EnvVars::UV_PACKAGE, conflicts_with("all_packages"))] pub package: Option, /// Builds all packages in the workspace. @@ -3124,7 +3124,7 @@ pub struct RunArgs { /// Run the command in a specific package in the workspace. /// /// If the workspace member does not exist, uv will exit with an error. - #[arg(long, conflicts_with = "all_packages")] + #[arg(long, env = EnvVars::UV_PACKAGE, conflicts_with = "all_packages")] pub package: Option, /// Avoid discovering the project or workspace. @@ -3368,7 +3368,7 @@ pub struct SyncArgs { /// declared by the specified workspace member package. /// /// If the workspace member does not exist, uv will exit with an error. - #[arg(long, conflicts_with = "all_packages")] + #[arg(long, env = EnvVars::UV_PACKAGE, conflicts_with = "all_packages")] pub package: Option, /// Sync the environment for a Python script, rather than the current project. @@ -3642,7 +3642,7 @@ pub struct AddArgs { pub refresh: RefreshArgs, /// Add the dependency to a specific package in the workspace. - #[arg(long, conflicts_with = "isolated")] + #[arg(long, env = EnvVars::UV_PACKAGE, conflicts_with = "isolated")] pub package: Option, /// Add the dependency to the specified Python script, rather than to a project. @@ -3744,7 +3744,7 @@ pub struct RemoveArgs { pub refresh: RefreshArgs, /// Remove the dependencies from a specific package in the workspace. - #[arg(long, conflicts_with = "isolated")] + #[arg(long, env = EnvVars::UV_PACKAGE, conflicts_with = "isolated")] pub package: Option, /// Remove the dependency from the specified Python script, rather than from a project. @@ -3933,7 +3933,7 @@ pub struct ExportArgs { /// Export the dependencies for a specific package in the workspace. /// /// If the workspace member does not exist, uv will exit with an error. - #[arg(long, conflicts_with = "all_packages")] + #[arg(long, env = EnvVars::UV_PACKAGE, conflicts_with = "all_packages")] pub package: Option, /// Prune the given package from the dependency tree. diff --git a/crates/uv-static/src/env_vars.rs b/crates/uv-static/src/env_vars.rs index aff56df45..838f3111f 100644 --- a/crates/uv-static/src/env_vars.rs +++ b/crates/uv-static/src/env_vars.rs @@ -100,6 +100,10 @@ impl EnvVars { /// file as the constraints file. Uses space-separated list of files. pub const UV_CONSTRAINT: &'static str = "UV_CONSTRAINT"; + /// Equivalent to the `--package` command-line argument. If set, uv + /// will run the command in this workspace member. + pub const UV_PACKAGE: &'static str = "UV_PACKAGE"; + /// Equivalent to the `--build-constraint` command-line argument. If set, uv will use this file /// as constraints for any source distribution builds. Uses space-separated list of files. pub const UV_BUILD_CONSTRAINT: &'static str = "UV_BUILD_CONSTRAINT"; From 7446620b88b028ba720cfcdc93d0b3e6244aca3a Mon Sep 17 00:00:00 2001 From: Pedro Avalos Jimenez Date: Thu, 12 Jun 2025 13:10:16 -0400 Subject: [PATCH 2/2] Generate docs --- docs/reference/cli.md | 14 +++++++------- docs/reference/environment.md | 5 +++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/reference/cli.md b/docs/reference/cli.md index d434b954b..1c0e0bd34 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -208,7 +208,7 @@ uv run [OPTIONS] [COMMAND]

May be provided multiple times. Implies --no-default-groups.

--package package

Run the command in a specific package in the workspace.

If the workspace member does not exist, uv will exit with an error.

-
--prerelease prerelease

The strategy to use when considering pre-release versions.

+

May also be set with the UV_PACKAGE environment variable.

--prerelease prerelease

The 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).

May also be set with the UV_PRERELEASE environment variable.

Possible values:

    @@ -539,7 +539,7 @@ uv add [OPTIONS] >

    The group may then be activated when installing the project with the --extra flag.

    To enable an optional extra for this requirement instead, see --extra.

--package package

Add the dependency to a specific package in the workspace

-
--prerelease prerelease

The strategy to use when considering pre-release versions.

+

May also be set with the UV_PACKAGE environment variable.

--prerelease prerelease

The 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).

May also be set with the UV_PRERELEASE environment variable.

Possible values:

    @@ -720,7 +720,7 @@ uv remove [OPTIONS] ...

    When disabled, uv will only use locally cached data and locally available files.

    May also be set with the UV_OFFLINE environment variable.

--optional optional

Remove the packages from the project's optional dependencies for the specified extra

--package package

Remove the dependencies from a specific package in the workspace

-
--prerelease prerelease

The strategy to use when considering pre-release versions.

+

May also be set with the UV_PACKAGE environment variable.

--prerelease prerelease

The 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).

May also be set with the UV_PRERELEASE environment variable.

Possible values:

    @@ -893,7 +893,7 @@ uv version [OPTIONS] [VALUE]
  • text: Display the version as plain text
  • json: Display the version as JSON
--package package

Update the version of a specific package in the workspace

-
--prerelease prerelease

The strategy to use when considering pre-release versions.

+

May also be set with the UV_PACKAGE environment variable.

--prerelease prerelease

The 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).

May also be set with the UV_PRERELEASE environment variable.

Possible values:

    @@ -1103,7 +1103,7 @@ uv sync [OPTIONS]
--package package

Sync for a specific package in the workspace.

The workspace's environment (.venv) is updated to reflect the subset of dependencies declared by the specified workspace member package.

If the workspace member does not exist, uv will exit with an error.

-
--prerelease prerelease

The strategy to use when considering pre-release versions.

+

May also be set with the UV_PACKAGE environment variable.

--prerelease prerelease

The 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).

May also be set with the UV_PRERELEASE environment variable.

Possible values:

    @@ -1466,7 +1466,7 @@ uv export [OPTIONS]
--output-file, -o output-file

Write the exported requirements to the given file

--package package

Export the dependencies for a specific package in the workspace.

If the workspace member does not exist, uv will exit with an error.

-
--prerelease prerelease

The strategy to use when considering pre-release versions.

+

May also be set with the UV_PACKAGE environment variable.

--prerelease prerelease

The 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).

May also be set with the UV_PRERELEASE environment variable.

Possible values:

    @@ -4648,7 +4648,7 @@ uv build [OPTIONS] [SRC]
--package package

Build a specific package in the workspace.

The workspace will be discovered from the provided source directory, or the current directory if no source directory is provided.

If the workspace member does not exist, uv will exit with an error.

-
--prerelease prerelease

The strategy to use when considering pre-release versions.

+

May also be set with the UV_PACKAGE environment variable.

--prerelease prerelease

The 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).

May also be set with the UV_PRERELEASE environment variable.

Possible values:

    diff --git a/docs/reference/environment.md b/docs/reference/environment.md index 61889ddb3..6e10d54d9 100644 --- a/docs/reference/environment.md +++ b/docs/reference/environment.md @@ -275,6 +275,11 @@ Equivalent to the `--offline` command-line argument. If set, uv will disable net Equivalent to the `--override` command-line argument. If set, uv will use this file as the overrides file. Uses space-separated list of files. +### `UV_PACKAGE` + +Equivalent to the `--package` command-line argument. If set, uv +will run the command in this workspace member. + ### `UV_PRERELEASE` Equivalent to the `--prerelease` command-line argument. For example, if set to