Add env UV_SYSTEM as alias to --system (#2354)

## Summary

Add a new env variable `UV_SYSTEM` as alias for the cli argument
`--system`.
Use cases:
- No need to specify on each uv call inside the docker container the
`--system` flag
- It allows installing and configuring uv in a base container and in the
child containers nobody needs to know if you need the `--system` cli
flag
- The Home Assistant development env can be set up via devcontainer or a
venv. Both use some common scripts. Instead of adding duplicate or
special code to identify the dev container to set the `--system` flag,
it would be nicer to set it via an env variable.

I'm unfamiliar with Rust and tried to add the support by looking at the
code.

## Test Plan

I did test it manually
`UV_SYSTEM_PYTHON=true uv pip install requests`
This commit is contained in:
Robert Resch 2024-03-11 21:56:45 +01:00 committed by GitHub
parent a292817d57
commit 85483e88a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 7 deletions

View file

@ -399,6 +399,10 @@ uv accepts the following command-line arguments as environment variables:
cache for any operations. cache for any operations.
- `UV_PRERELEASE`: Equivalent to the `--prerelease` command-line argument. If set to `allow`, uv - `UV_PRERELEASE`: Equivalent to the `--prerelease` command-line argument. If set to `allow`, uv
will allow pre-release versions for all dependencies. will allow pre-release versions for all dependencies.
- `UV_SYSTEM_PYTHON`: Equivalent to the `--system` command-line argument. If set to `true`, uv
will use the first Python interpreter found in the system `PATH`.
WARNING: `UV_SYSTEM=true` is intended for use in continuous integration (CI) environments and
should be used with caution, as it can modify the system Python installation.
In each case, the corresponding command-line argument takes precedence over an environment variable. In each case, the corresponding command-line argument takes precedence over an environment variable.

View file

@ -542,7 +542,12 @@ struct PipSyncArgs {
/// ///
/// WARNING: `--system` is intended for use in continuous integration (CI) environments and /// WARNING: `--system` is intended for use in continuous integration (CI) environments and
/// should be used with caution, as it can modify the system Python installation. /// should be used with caution, as it can modify the system Python installation.
#[clap(long, conflicts_with = "python", group = "discovery")] #[clap(
long,
conflicts_with = "python",
env = "UV_SYSTEM_PYTHON",
group = "discovery"
)]
system: bool, system: bool,
/// Allow `uv` to modify an `EXTERNALLY-MANAGED` Python installation. /// Allow `uv` to modify an `EXTERNALLY-MANAGED` Python installation.
@ -788,7 +793,12 @@ struct PipInstallArgs {
/// ///
/// WARNING: `--system` is intended for use in continuous integration (CI) environments and /// WARNING: `--system` is intended for use in continuous integration (CI) environments and
/// should be used with caution, as it can modify the system Python installation. /// should be used with caution, as it can modify the system Python installation.
#[clap(long, conflicts_with = "python", group = "discovery")] #[clap(
long,
conflicts_with = "python",
env = "UV_SYSTEM_PYTHON",
group = "discovery"
)]
system: bool, system: bool,
/// Allow `uv` to modify an `EXTERNALLY-MANAGED` Python installation. /// Allow `uv` to modify an `EXTERNALLY-MANAGED` Python installation.
@ -916,7 +926,12 @@ struct PipUninstallArgs {
/// ///
/// WARNING: `--system` is intended for use in continuous integration (CI) environments and /// WARNING: `--system` is intended for use in continuous integration (CI) environments and
/// should be used with caution, as it can modify the system Python installation. /// should be used with caution, as it can modify the system Python installation.
#[clap(long, conflicts_with = "python", group = "discovery")] #[clap(
long,
conflicts_with = "python",
env = "UV_SYSTEM_PYTHON",
group = "discovery"
)]
system: bool, system: bool,
/// Allow `uv` to modify an `EXTERNALLY-MANAGED` Python installation. /// Allow `uv` to modify an `EXTERNALLY-MANAGED` Python installation.
@ -970,7 +985,12 @@ struct PipFreezeArgs {
/// ///
/// WARNING: `--system` is intended for use in continuous integration (CI) environments and /// WARNING: `--system` is intended for use in continuous integration (CI) environments and
/// should be used with caution. /// should be used with caution.
#[clap(long, conflicts_with = "python", group = "discovery")] #[clap(
long,
conflicts_with = "python",
env = "UV_SYSTEM_PYTHON",
group = "discovery"
)]
system: bool, system: bool,
} }
@ -1027,7 +1047,12 @@ struct PipListArgs {
/// ///
/// WARNING: `--system` is intended for use in continuous integration (CI) environments and /// WARNING: `--system` is intended for use in continuous integration (CI) environments and
/// should be used with caution. /// should be used with caution.
#[clap(long, conflicts_with = "python", group = "discovery")] #[clap(
long,
conflicts_with = "python",
env = "UV_SYSTEM_PYTHON",
group = "discovery"
)]
system: bool, system: bool,
} }
@ -1071,7 +1096,12 @@ struct PipShowArgs {
/// ///
/// WARNING: `--system` is intended for use in continuous integration (CI) environments and /// WARNING: `--system` is intended for use in continuous integration (CI) environments and
/// should be used with caution. /// should be used with caution.
#[clap(long, conflicts_with = "python", group = "discovery")] #[clap(
long,
conflicts_with = "python",
env = "UV_SYSTEM_PYTHON",
group = "discovery"
)]
system: bool, system: bool,
} }
@ -1105,7 +1135,12 @@ struct VenvArgs {
/// ///
/// WARNING: `--system` is intended for use in continuous integration (CI) environments and /// WARNING: `--system` is intended for use in continuous integration (CI) environments and
/// should be used with caution, as it can modify the system Python installation. /// should be used with caution, as it can modify the system Python installation.
#[clap(long, conflicts_with = "python", group = "discovery")] #[clap(
long,
conflicts_with = "python",
env = "UV_SYSTEM_PYTHON",
group = "discovery"
)]
system: bool, system: bool,
/// Install seed packages (`pip`, `setuptools`, and `wheel`) into the virtual environment. /// Install seed packages (`pip`, `setuptools`, and `wheel`) into the virtual environment.