Skip to content

Commit

Permalink
Add support for configuring the python-preference with `UV_PYTHON_P…
Browse files Browse the repository at this point in the history
…REFERENCE`
  • Loading branch information
zanieb committed Aug 22, 2024
1 parent fc9fdd2 commit b35b9a6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
3 changes: 2 additions & 1 deletion crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PythonPreference>,

Expand Down
32 changes: 18 additions & 14 deletions crates/uv/tests/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ fn help() {
Python options:
--python-preference <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
Expand Down Expand Up @@ -101,8 +101,8 @@ fn help_flag() {
Python options:
--python-preference <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
Expand Down Expand Up @@ -162,8 +162,8 @@ fn help_short_flag() {
Python options:
--python-preference <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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -531,8 +535,8 @@ fn help_flag_subcommand() {
Python options:
--python-preference <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
Expand Down Expand Up @@ -583,8 +587,8 @@ fn help_flag_subsubcommand() {
Python options:
--python-preference <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
Expand Down Expand Up @@ -715,8 +719,8 @@ fn help_with_global_option() {
Python options:
--python-preference <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
Expand Down Expand Up @@ -814,8 +818,8 @@ fn help_with_no_pager() {
Python options:
--python-preference <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
Expand Down
2 changes: 2 additions & 0 deletions docs/configuration/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit b35b9a6

Please sign in to comment.