From 40844048afa12a50a429dbc8066fc4e33be00c13 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 21 Nov 2024 09:35:57 -0500 Subject: [PATCH] Remove `--upgrade`, `--no-upgrade`, and `--upgrade-package` from `uv tool upgrade` (#9318) ## Summary `--upgrade` isn't useful, since it's the default. So it's now hidden, but continues to warn if you enable it. `--no-upgrade` isn't useful, since it panics. So it's now removed entirely. This isn't breaking, since it already didn't work. `--upgrade-package` actually _is_ useful, because it turns out it allows things like: `uv tool upgrade babel --upgrade-package "babel<0.2.14"` to constrain the upgrade. I left this in place but hid it... I think we should provide a better workflow for this, like `uv tool upgrade "babel<0.2.14"`? It's strange to specify the package twice, and that `uv tool upgrade` has an `--upgrade-package` flag. Closes https://github.com/astral-sh/uv/issues/9317. --- crates/uv-cli/src/lib.rs | 182 +++++++++++++++++++++++++++++++++++++- crates/uv/src/settings.rs | 55 ++++++++++-- docs/reference/cli.md | 4 - 3 files changed, 229 insertions(+), 12 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index ee038ebd6393..50c5ba28a206 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -3847,8 +3847,188 @@ pub struct ToolUpgradeArgs { )] pub python: Option>, + // The following is equivalent to flattening `ResolverInstallerArgs`, with the `--upgrade`, + // and `--upgrade-package` options hidden, and the `--no-upgrade` option removed. + /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies + /// `--refresh`. + #[arg(hide = true, long, short = 'U', help_heading = "Resolver options")] + pub upgrade: bool, + + /// Allow upgrades for a specific package, ignoring pinned versions in any existing output + /// file. Implies `--refresh-package`. + #[arg(hide = true, long, short = 'P', help_heading = "Resolver options")] + pub upgrade_package: Vec>, + #[command(flatten)] - pub installer: ResolverInstallerArgs, + pub index_args: IndexArgs, + + /// Reinstall all packages, regardless of whether they're already installed. Implies + /// `--refresh`. + #[arg( + long, + alias = "force-reinstall", + overrides_with("no_reinstall"), + help_heading = "Installer options" + )] + pub reinstall: bool, + + #[arg( + long, + overrides_with("reinstall"), + hide = true, + help_heading = "Installer options" + )] + pub no_reinstall: bool, + + /// Reinstall a specific package, regardless of whether it's already installed. Implies + /// `--refresh-package`. + #[arg(long, help_heading = "Installer options")] + pub reinstall_package: Vec, + + /// The strategy to use when resolving against multiple index URLs. + /// + /// By default, uv will stop at the first index on which a given package is available, and + /// limit resolutions to those present on that first index (`first-match`). This prevents + /// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the + /// same name to an alternate index. + #[arg( + long, + value_enum, + env = EnvVars::UV_INDEX_STRATEGY, + help_heading = "Index options" + )] + pub index_strategy: Option, + + /// Attempt to use `keyring` for authentication for index URLs. + /// + /// At present, only `--keyring-provider subprocess` is supported, which configures uv to + /// use the `keyring` CLI to handle authentication. + /// + /// Defaults to `disabled`. + #[arg( + long, + value_enum, + env = EnvVars::UV_KEYRING_PROVIDER, + help_heading = "Index options" + )] + pub keyring_provider: Option, + + /// The strategy to use when selecting between the different compatible versions for a given + /// package requirement. + /// + /// By default, uv will use the latest compatible version of each package (`highest`). + #[arg( + long, + value_enum, + env = EnvVars::UV_RESOLUTION, + help_heading = "Resolver options" + )] + pub resolution: Option, + + /// The strategy to use when considering pre-release versions. + /// + /// By default, uv will accept pre-releases for packages that _only_ publish pre-releases, + /// along with first-party requirements that contain an explicit pre-release marker in the + /// declared specifiers (`if-necessary-or-explicit`). + #[arg( + long, + value_enum, + env = EnvVars::UV_PRERELEASE, + help_heading = "Resolver options" + )] + pub prerelease: Option, + + #[arg(long, hide = true)] + pub pre: bool, + + /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs. + #[arg( + long, + short = 'C', + alias = "config-settings", + help_heading = "Build options" + )] + pub config_setting: Option>, + + /// Disable isolation when building source distributions. + /// + /// Assumes that build dependencies specified by PEP 518 are already installed. + #[arg( + long, + overrides_with("build_isolation"), + help_heading = "Build options", + env = EnvVars::UV_NO_BUILD_ISOLATION, + value_parser = clap::builder::BoolishValueParser::new(), + )] + pub no_build_isolation: bool, + + /// Disable isolation when building source distributions for a specific package. + /// + /// Assumes that the packages' build dependencies specified by PEP 518 are already installed. + #[arg(long, help_heading = "Build options")] + pub no_build_isolation_package: Vec, + + #[arg( + long, + overrides_with("no_build_isolation"), + hide = true, + help_heading = "Build options" + )] + pub build_isolation: bool, + + /// Limit candidate packages to those that were uploaded prior to the given date. + /// + /// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and local dates in the same + /// format (e.g., `2006-12-02`) in your system's configured time zone. + #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")] + pub exclude_newer: Option, + + /// The method to use when installing packages from the global cache. + /// + /// Defaults to `clone` (also known as Copy-on-Write) on macOS, and `hardlink` on Linux and + /// Windows. + #[arg( + long, + value_enum, + env = EnvVars::UV_LINK_MODE, + help_heading = "Installer options" + )] + pub link_mode: Option, + + /// Compile Python files to bytecode after installation. + /// + /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`); + /// instead, compilation is performed lazily the first time a module is imported. For use-cases + /// in which start time is critical, such as CLI applications and Docker containers, this option + /// can be enabled to trade longer installation times for faster start times. + /// + /// When enabled, uv will process the entire site-packages directory (including packages that + /// are not being modified by the current operation) for consistency. Like pip, it will also + /// ignore errors. + #[arg( + long, + alias = "compile", + overrides_with("no_compile_bytecode"), + help_heading = "Installer options", + env = EnvVars::UV_COMPILE_BYTECODE, + value_parser = clap::builder::BoolishValueParser::new(), + )] + pub compile_bytecode: bool, + + #[arg( + long, + alias = "no-compile", + overrides_with("compile_bytecode"), + hide = true, + help_heading = "Installer options" + )] + pub no_compile_bytecode: bool, + + /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the + /// standards-compliant, publishable package metadata, as opposed to using any local or Git + /// sources. + #[arg(long, help_heading = "Resolver options")] + pub no_sources: bool, #[command(flatten)] pub build: BuildOptionsArgs, diff --git a/crates/uv/src/settings.rs b/crates/uv/src/settings.rs index 3a74aba0e69e..3d29f532158c 100644 --- a/crates/uv/src/settings.rs +++ b/crates/uv/src/settings.rs @@ -9,7 +9,8 @@ use uv_cache::{CacheArgs, Refresh}; use uv_cli::comma::CommaSeparatedRequirements; use uv_cli::{ options::{flag, resolver_installer_options, resolver_options}, - AuthorFrom, BuildArgs, ExportArgs, PublishArgs, PythonDirArgs, ToolUpgradeArgs, + AuthorFrom, BuildArgs, ExportArgs, PublishArgs, PythonDirArgs, ResolverInstallerArgs, + ToolUpgradeArgs, }; use uv_cli::{ AddArgs, ColorChoice, ExternalCommand, GlobalArgs, InitArgs, ListFormat, LockArgs, Maybe, @@ -544,19 +545,59 @@ impl ToolUpgradeSettings { let ToolUpgradeArgs { name, python, + upgrade, + upgrade_package, + index_args, all, - mut installer, + reinstall, + no_reinstall, + reinstall_package, + index_strategy, + keyring_provider, + resolution, + prerelease, + pre, + config_setting, + no_build_isolation, + no_build_isolation_package, + build_isolation, + exclude_newer, + link_mode, + compile_bytecode, + no_compile_bytecode, + no_sources, build, } = args; - if installer.upgrade { - // If `--upgrade` was passed explicitly, warn. + if upgrade { warn_user_once!("`--upgrade` is enabled by default on `uv tool upgrade`"); - } else if installer.upgrade_package.is_empty() { - // If neither `--upgrade` nor `--upgrade-package` were passed in, assume `--upgrade`. - installer.upgrade = true; } + // Enable `--upgrade` by default. + let installer = ResolverInstallerArgs { + index_args, + upgrade: upgrade_package.is_empty(), + no_upgrade: false, + upgrade_package, + reinstall, + no_reinstall, + reinstall_package, + index_strategy, + keyring_provider, + resolution, + prerelease, + pre, + config_setting, + no_build_isolation, + no_build_isolation_package, + build_isolation, + exclude_newer, + link_mode, + compile_bytecode, + no_compile_bytecode, + no_sources, + }; + let args = resolver_installer_options(installer, build); let filesystem = filesystem.map(FilesystemOptions::into_options); let install_mirrors = filesystem diff --git a/docs/reference/cli.md b/docs/reference/cli.md index b56a8b08059e..87c779ae0a87 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -3741,10 +3741,6 @@ uv tool upgrade [OPTIONS] ...
  • lowest-direct: Resolve the lowest compatible version of any direct dependencies, and the highest compatible version of any transitive dependencies
  • -
    --upgrade, -U

    Allow package upgrades, ignoring pinned versions in any existing output file. Implies --refresh

    - -
    --upgrade-package, -P upgrade-package

    Allow upgrades for a specific package, ignoring pinned versions in any existing output file. Implies --refresh-package

    -
    --verbose, -v

    Use verbose output.

    You can configure fine-grained logging using the RUST_LOG environment variable. (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)