diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 1a3d1a9a07ae..b13161174b67 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -115,7 +115,8 @@ pub struct GlobalArgs { global = true, long, help_heading = "Python options", - display_order = 700 + display_order = 700, + env = "UV_PYTHON_PREFERENCE" )] pub python_preference: Option, diff --git a/crates/uv/tests/help.rs b/crates/uv/tests/help.rs index a69c5312a6de..8e7fa6f727b7 100644 --- a/crates/uv/tests/help.rs +++ b/crates/uv/tests/help.rs @@ -39,8 +39,8 @@ fn help() { Python options: --python-preference - Whether to prefer uv-managed or system Python installations [possible values: - only-managed, managed, system, only-system] + Whether to prefer uv-managed or system Python installations [env: UV_PYTHON_PREFERENCE=] + [possible values: only-managed, managed, system, only-system] --no-python-downloads Disable automatic downloads of Python @@ -101,8 +101,8 @@ fn help_flag() { Python options: --python-preference - Whether to prefer uv-managed or system Python installations [possible values: - only-managed, managed, system, only-system] + Whether to prefer uv-managed or system Python installations [env: UV_PYTHON_PREFERENCE=] + [possible values: only-managed, managed, system, only-system] --no-python-downloads Disable automatic downloads of Python @@ -162,8 +162,8 @@ fn help_short_flag() { Python options: --python-preference - Whether to prefer uv-managed or system Python installations [possible values: - only-managed, managed, system, only-system] + Whether to prefer uv-managed or system Python installations [env: UV_PYTHON_PREFERENCE=] + [possible values: only-managed, managed, system, only-system] --no-python-downloads Disable automatic downloads of Python @@ -274,6 +274,8 @@ fn help_subcommand() { By default, uv prefers using Python versions it manages. However, it will use system Python installations if a uv-managed Python is not installed. This option allows prioritizing or ignoring system Python installations. + + [env: UV_PYTHON_PREFERENCE=] Possible values: - only-managed: Only use managed Python installations; never use system Python @@ -421,6 +423,8 @@ fn help_subsubcommand() { By default, uv prefers using Python versions it manages. However, it will use system Python installations if a uv-managed Python is not installed. This option allows prioritizing or ignoring system Python installations. + + [env: UV_PYTHON_PREFERENCE=] Possible values: - only-managed: Only use managed Python installations; never use system Python @@ -531,8 +535,8 @@ fn help_flag_subcommand() { Python options: --python-preference - Whether to prefer uv-managed or system Python installations [possible values: - only-managed, managed, system, only-system] + Whether to prefer uv-managed or system Python installations [env: UV_PYTHON_PREFERENCE=] + [possible values: only-managed, managed, system, only-system] --no-python-downloads Disable automatic downloads of Python @@ -583,8 +587,8 @@ fn help_flag_subsubcommand() { Python options: --python-preference - Whether to prefer uv-managed or system Python installations [possible values: - only-managed, managed, system, only-system] + Whether to prefer uv-managed or system Python installations [env: UV_PYTHON_PREFERENCE=] + [possible values: only-managed, managed, system, only-system] --no-python-downloads Disable automatic downloads of Python @@ -715,8 +719,8 @@ fn help_with_global_option() { Python options: --python-preference - Whether to prefer uv-managed or system Python installations [possible values: - only-managed, managed, system, only-system] + Whether to prefer uv-managed or system Python installations [env: UV_PYTHON_PREFERENCE=] + [possible values: only-managed, managed, system, only-system] --no-python-downloads Disable automatic downloads of Python @@ -814,8 +818,8 @@ fn help_with_no_pager() { Python options: --python-preference - Whether to prefer uv-managed or system Python installations [possible values: - only-managed, managed, system, only-system] + Whether to prefer uv-managed or system Python installations [env: UV_PYTHON_PREFERENCE=] + [possible values: only-managed, managed, system, only-system] --no-python-downloads Disable automatic downloads of Python diff --git a/docs/configuration/environment.md b/docs/configuration/environment.md index 38f789714e66..37c07d5aabe2 100644 --- a/docs/configuration/environment.md +++ b/docs/configuration/environment.md @@ -56,6 +56,8 @@ uv accepts the following command-line arguments as environment variables: directories. - `UV_EXCLUDE_NEWER`: Equivalent to the `--exclude-newer` command-line argument. If set, uv will exclude distributions published after the specified date. +- `UV_PYTHON_PREFERENCE`: Equivalent to the `--python-preference` command-line argument. Whether uv + should prefer system or managed Python versions. In each case, the corresponding command-line argument takes precedence over an environment variable.