Skip to content

Commit

Permalink
Expose --python as an environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Apr 26, 2024
1 parent 2af80c2 commit f01019e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ uv accepts the following command-line arguments as environment variables:
WARNING: `UV_SYSTEM_PYTHON=true` is intended for use in continuous integration (CI) or
containerized environments and should be used with caution, as modifying the system Python
can lead to unexpected behavior.
- `UV_USE_PYTHON`: Equivalent to the `--python` command-line argument. If set to a path, uv will
use this Python interpreter for all operations.
- `UV_BREAK_SYSTEM_PACKAGES`: Equivalent to the `--break-system-packages` command-line argument. If
set to `true`, uv will allow the installation of packages that conflict with system-installed
packages.
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-interpreter/src/find_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ fn find_python(
Ok(None)
}

/// Find the Python interpreter in `PATH` matching the given name (e.g., `python3`, respecting
/// Find the Python interpreter in `PATH` matching the given name (e.g., `python3`), respecting
/// `UV_PYTHON_PATH`.
///
/// Returns `Ok(None)` if not found.
Expand Down
72 changes: 63 additions & 9 deletions crates/uv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,13 @@ pub(crate) struct PipSyncArgs {
/// `python3.10` on Linux and macOS.
/// - `python3.10` or `python.exe` looks for a binary with the given name in `PATH`.
/// - `/home/ferris/.local/bin/python3.10` uses the exact Python at the given path.
#[arg(long, short, verbatim_doc_comment, group = "discovery")]
#[arg(
long,
short,
env = "UV_USE_PYTHON",
verbatim_doc_comment,
group = "discovery"
)]
pub(crate) python: Option<String>,

/// Install packages into the system Python.
Expand Down Expand Up @@ -1096,7 +1102,13 @@ pub(crate) struct PipInstallArgs {
/// `python3.10` on Linux and macOS.
/// - `python3.10` or `python.exe` looks for a binary with the given name in `PATH`.
/// - `/home/ferris/.local/bin/python3.10` uses the exact Python at the given path.
#[arg(long, short, verbatim_doc_comment, group = "discovery")]
#[arg(
long,
short,
env = "UV_USE_PYTHON",
verbatim_doc_comment,
group = "discovery"
)]
pub(crate) python: Option<String>,

/// Install packages into the system Python.
Expand Down Expand Up @@ -1295,7 +1307,13 @@ pub(crate) struct PipUninstallArgs {
/// `python3.10` on Linux and macOS.
/// - `python3.10` or `python.exe` looks for a binary with the given name in `PATH`.
/// - `/home/ferris/.local/bin/python3.10` uses the exact Python at the given path.
#[arg(long, short, verbatim_doc_comment, group = "discovery")]
#[arg(
long,
short,
env = "UV_USE_PYTHON",
verbatim_doc_comment,
group = "discovery"
)]
pub(crate) python: Option<String>,

/// Attempt to use `keyring` for authentication for remote requirements files.
Expand Down Expand Up @@ -1384,7 +1402,13 @@ pub(crate) struct PipFreezeArgs {
/// `python3.10` on Linux and macOS.
/// - `python3.10` or `python.exe` looks for a binary with the given name in `PATH`.
/// - `/home/ferris/.local/bin/python3.10` uses the exact Python at the given path.
#[arg(long, short, verbatim_doc_comment, group = "discovery")]
#[arg(
long,
short,
env = "UV_USE_PYTHON",
verbatim_doc_comment,
group = "discovery"
)]
pub(crate) python: Option<String>,

/// List packages for the system Python.
Expand Down Expand Up @@ -1447,7 +1471,13 @@ pub(crate) struct PipListArgs {
/// `python3.10` on Linux and macOS.
/// - `python3.10` or `python.exe` looks for a binary with the given name in `PATH`.
/// - `/home/ferris/.local/bin/python3.10` uses the exact Python at the given path.
#[arg(long, short, verbatim_doc_comment, group = "discovery")]
#[arg(
long,
short,
env = "UV_USE_PYTHON",
verbatim_doc_comment,
group = "discovery"
)]
pub(crate) python: Option<String>,

/// List packages for the system Python.
Expand Down Expand Up @@ -1489,7 +1519,13 @@ pub(crate) struct PipCheckArgs {
/// `python3.10` on Linux and macOS.
/// - `python3.10` or `python.exe` looks for a binary with the given name in `PATH`.
/// - `/home/ferris/.local/bin/python3.10` uses the exact Python at the given path.
#[arg(long, short, verbatim_doc_comment, group = "discovery")]
#[arg(
long,
short,
env = "UV_USE_PYTHON",
verbatim_doc_comment,
group = "discovery"
)]
pub(crate) python: Option<String>,

/// List packages for the system Python.
Expand Down Expand Up @@ -1539,7 +1575,13 @@ pub(crate) struct PipShowArgs {
/// `python3.10` on Linux and macOS.
/// - `python3.10` or `python.exe` looks for a binary with the given name in `PATH`.
/// - `/home/ferris/.local/bin/python3.10` uses the exact Python at the given path.
#[arg(long, short, verbatim_doc_comment, group = "discovery")]
#[arg(
long,
short,
env = "UV_USE_PYTHON",
verbatim_doc_comment,
group = "discovery"
)]
pub(crate) python: Option<String>,

/// List packages for the system Python.
Expand Down Expand Up @@ -1577,7 +1619,13 @@ pub(crate) struct VenvArgs {
///
/// Note that this is different from `--python-version` in `pip compile`, which takes `3.10` or `3.10.13` and
/// doesn't look for a Python interpreter on disk.
#[arg(long, short, verbatim_doc_comment, group = "discovery")]
#[arg(
long,
short,
env = "UV_USE_PYTHON",
verbatim_doc_comment,
group = "discovery"
)]
pub(crate) python: Option<String>,

/// Use the system Python to uninstall packages.
Expand Down Expand Up @@ -1732,7 +1780,13 @@ pub(crate) struct RunArgs {
/// `python3.10` on Linux and macOS.
/// - `python3.10` or `python.exe` looks for a binary with the given name in `PATH`.
/// - `/home/ferris/.local/bin/python3.10` uses the exact Python at the given path.
#[arg(long, short, verbatim_doc_comment, group = "discovery")]
#[arg(
long,
short,
env = "UV_USE_PYTHON",
verbatim_doc_comment,
group = "discovery"
)]
pub(crate) python: Option<String>,

/// Run without the current workspace installed.
Expand Down

0 comments on commit f01019e

Please sign in to comment.