Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove --upgrade, --no-upgrade, and --upgrade-package from uv tool upgrade #9318

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 181 additions & 1 deletion crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3847,8 +3847,188 @@ pub struct ToolUpgradeArgs {
)]
pub python: Option<Maybe<String>>,

// 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<Requirement<VerbatimParsedUrl>>,

#[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<PackageName>,

/// 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<IndexStrategy>,

/// 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<KeyringProviderType>,

/// 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<ResolutionMode>,

/// 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<PrereleaseMode>,

#[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<Vec<ConfigSettingEntry>>,

/// 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<PackageName>,

#[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<ExcludeNewer>,

/// 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<uv_install_wheel::linker::LinkMode>,

/// 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,
Expand Down
55 changes: 48 additions & 7 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -3741,10 +3741,6 @@ uv tool upgrade [OPTIONS] <NAME>...

<li><code>lowest-direct</code>: Resolve the lowest compatible version of any direct dependencies, and the highest compatible version of any transitive dependencies</li>
</ul>
</dd><dt><code>--upgrade</code>, <code>-U</code></dt><dd><p>Allow package upgrades, ignoring pinned versions in any existing output file. Implies <code>--refresh</code></p>

</dd><dt><code>--upgrade-package</code>, <code>-P</code> <i>upgrade-package</i></dt><dd><p>Allow upgrades for a specific package, ignoring pinned versions in any existing output file. Implies <code>--refresh-package</code></p>

</dd><dt><code>--verbose</code>, <code>-v</code></dt><dd><p>Use verbose output.</p>

<p>You can configure fine-grained logging using the <code>RUST_LOG</code> environment variable. (&lt;https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives&gt;)</p>
Expand Down
Loading