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` (#6432)

Part of #6406
  • Loading branch information
zanieb authored Aug 22, 2024
1 parent 3dd39e6 commit 0c86613
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 @@ -269,6 +269,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 @@ -416,6 +418,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 @@ -526,8 +530,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 @@ -578,8 +582,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 @@ -710,8 +714,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 @@ -809,8 +813,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 0c86613

Please sign in to comment.