mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
Support transparent Python patch version upgrades (#13954)
> NOTE: The PRs that were merged into this feature branch have all been independently reviewed. But it's also useful to see all of the changes in their final form. I've added comments to significant changes throughout the PR to aid discussion. This PR introduces transparent Python version upgrades to uv, allowing for a smoother experience when upgrading to new patch versions. Previously, upgrading Python patch versions required manual updates to each virtual environment. Now, virtual environments can transparently upgrade to newer patch versions. Due to significant changes in how uv installs and executes managed Python executables, this functionality is initially available behind a `--preview` flag. Once an installation has been made upgradeable through `--preview`, subsequent operations (like `uv venv -p 3.10` or patch upgrades) will work without requiring the flag again. This is accomplished by checking for the existence of a minor version symlink directory (or junction on Windows). ### Features * New `uv python upgrade` command to upgrade installed Python versions to the latest available patch release: ``` # Upgrade specific minor version uv python upgrade 3.12 --preview # Upgrade all installed minor versions uv python upgrade --preview ``` * Transparent upgrades also occur when installing newer patch versions: ``` uv python install 3.10.8 --preview # Automatically upgrades existing 3.10 environments uv python install 3.10.18 ``` * Support for transparently upgradeable Python `bin` installations via `--preview` flag ``` uv python install 3.13 --preview # Automatically upgrades the `bin` installation if there is a newer patch version available uv python upgrade 3.13 --preview ``` * Virtual environments can still be tied to a patch version if desired (ignoring patch upgrades): ``` uv venv -p 3.10.8 ``` ### Implementation Transparent upgrades are implemented using: * Minor version symlink directories (Unix) or junctions (Windows) * On Windows, trampolines simulate paths with junctions * Symlink directory naming follows Python build standalone format: e.g., `cpython-3.10-macos-aarch64-none` * Upgrades are scoped to the minor version key (as represented in the naming format: implementation-minor version+variant-os-arch-libc) * If the context does not provide a patch version request and the interpreter is from a managed CPython installation, the `Interpreter` used by `uv python run` will use the full symlink directory executable path when available, enabling transparently upgradeable environments created with the `venv` module (`uv run python -m venv`) New types: * `PythonMinorVersionLink`: in a sense, the core type for this PR, this is a representation of a minor version symlink directory (or junction on Windows) that points to the highest installed managed CPython patch version for a minor version key. * `PythonInstallationMinorVersionKey`: provides a view into a `PythonInstallationKey` that excludes the patch and prerelease. This is used for grouping installations by minor version key (e.g., to find the highest available patch installation for that minor version key) and for minor version directory naming. ### Compatibility * Supports virtual environments created with: * `uv venv` * `uv run python -m venv` (using managed Python that was installed or upgraded with `--preview`) * Virtual environments created within these environments * Existing virtual environments from before these changes continue to work but aren't transparently upgradeable without being recreated * Supports both standard Python (`python3.10`) and freethreaded Python (`python3.10t`) * Support for transparently upgrades is currently only available for managed CPython installations Closes #7287 Closes #7325 Closes #7892 Closes #9031 Closes #12977 --------- Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
parent
62365d4ec8
commit
e9d5780369
73 changed files with 3022 additions and 306 deletions
|
@ -4722,6 +4722,24 @@ pub enum PythonCommand {
|
|||
/// See `uv help python` to view supported request formats.
|
||||
Install(PythonInstallArgs),
|
||||
|
||||
/// Upgrade installed Python versions to the latest supported patch release (requires the
|
||||
/// `--preview` flag).
|
||||
///
|
||||
/// A target Python minor version to upgrade may be provided, e.g., `3.13`. Multiple versions
|
||||
/// may be provided to perform more than one upgrade.
|
||||
///
|
||||
/// If no target version is provided, then uv will upgrade all managed CPython versions.
|
||||
///
|
||||
/// During an upgrade, uv will not uninstall outdated patch versions.
|
||||
///
|
||||
/// When an upgrade is performed, virtual environments created by uv will automatically
|
||||
/// use the new version. However, if the virtual environment was created before the
|
||||
/// upgrade functionality was added, it will continue to use the old Python version; to enable
|
||||
/// upgrades, the environment must be recreated.
|
||||
///
|
||||
/// Upgrades are not yet supported for alternative implementations, like PyPy.
|
||||
Upgrade(PythonUpgradeArgs),
|
||||
|
||||
/// Search for a Python installation.
|
||||
///
|
||||
/// Displays the path to the Python executable.
|
||||
|
@ -4907,6 +4925,50 @@ pub struct PythonInstallArgs {
|
|||
pub default: bool,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
pub struct PythonUpgradeArgs {
|
||||
/// The directory Python installations are stored in.
|
||||
///
|
||||
/// If provided, `UV_PYTHON_INSTALL_DIR` will need to be set for subsequent operations for uv to
|
||||
/// discover the Python installation.
|
||||
///
|
||||
/// See `uv python dir` to view the current Python installation directory. Defaults to
|
||||
/// `~/.local/share/uv/python`.
|
||||
#[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR)]
|
||||
pub install_dir: Option<PathBuf>,
|
||||
|
||||
/// The Python minor version(s) to upgrade.
|
||||
///
|
||||
/// If no target version is provided, then uv will upgrade all managed CPython versions.
|
||||
#[arg(env = EnvVars::UV_PYTHON)]
|
||||
pub targets: Vec<String>,
|
||||
|
||||
/// Set the URL to use as the source for downloading Python installations.
|
||||
///
|
||||
/// The provided URL will replace
|
||||
/// `https://github.com/astral-sh/python-build-standalone/releases/download` in, e.g.,
|
||||
/// `https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz`.
|
||||
///
|
||||
/// Distributions can be read from a local directory by using the `file://` URL scheme.
|
||||
#[arg(long, env = EnvVars::UV_PYTHON_INSTALL_MIRROR)]
|
||||
pub mirror: Option<String>,
|
||||
|
||||
/// Set the URL to use as the source for downloading PyPy installations.
|
||||
///
|
||||
/// The provided URL will replace `https://downloads.python.org/pypy` in, e.g.,
|
||||
/// `https://downloads.python.org/pypy/pypy3.8-v7.3.7-osx64.tar.bz2`.
|
||||
///
|
||||
/// Distributions can be read from a local directory by using the `file://` URL scheme.
|
||||
#[arg(long, env = EnvVars::UV_PYPY_INSTALL_MIRROR)]
|
||||
pub pypy_mirror: Option<String>,
|
||||
|
||||
/// URL pointing to JSON of custom Python installations.
|
||||
///
|
||||
/// Note that currently, only local paths are supported.
|
||||
#[arg(long, env = EnvVars::UV_PYTHON_DOWNLOADS_JSON_URL)]
|
||||
pub python_downloads_json_url: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
pub struct PythonUninstallArgs {
|
||||
/// The directory where the Python was installed.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue