Make --reinstall, --upgrade, and --refresh shared arguments (#4319)

## Summary

Ensures that we respect these in all the relevant `uv` APIs.

Closes https://github.com/astral-sh/uv/issues/4316.
This commit is contained in:
Charlie Marsh 2024-06-13 18:43:18 -07:00 committed by GitHub
parent db84825908
commit 1d6d98f3a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 346 additions and 275 deletions

View file

@ -77,6 +77,10 @@ impl Combine for ResolverInstallerOptions {
exclude_newer: self.exclude_newer.combine(other.exclude_newer),
link_mode: self.link_mode.combine(other.link_mode),
compile_bytecode: self.compile_bytecode.combine(other.compile_bytecode),
upgrade: self.upgrade.combine(other.upgrade),
upgrade_package: self.upgrade_package.combine(other.upgrade_package),
reinstall: self.reinstall.combine(other.reinstall),
reinstall_package: self.reinstall_package.combine(other.reinstall_package),
}
}
}
@ -142,6 +146,10 @@ impl Combine for PipOptions {
link_mode: self.link_mode.combine(other.link_mode),
compile_bytecode: self.compile_bytecode.combine(other.compile_bytecode),
require_hashes: self.require_hashes.combine(other.require_hashes),
upgrade: self.upgrade.combine(other.upgrade),
upgrade_package: self.upgrade_package.combine(other.upgrade_package),
reinstall: self.reinstall.combine(other.reinstall),
reinstall_package: self.reinstall_package.combine(other.reinstall_package),
concurrent_downloads: self
.concurrent_downloads
.combine(other.concurrent_downloads),

View file

@ -75,6 +75,8 @@ pub struct InstallerOptions {
pub config_settings: Option<ConfigSettings>,
pub link_mode: Option<LinkMode>,
pub compile_bytecode: Option<bool>,
pub reinstall: Option<bool>,
pub reinstall_package: Option<Vec<PackageName>>,
}
/// Settings relevant to all resolver operations.
@ -94,6 +96,8 @@ pub struct ResolverOptions {
pub config_settings: Option<ConfigSettings>,
pub exclude_newer: Option<ExcludeNewer>,
pub link_mode: Option<LinkMode>,
pub upgrade: Option<bool>,
pub upgrade_package: Option<Vec<PackageName>>,
}
/// Shared settings, relevant to all operations that must resolve and install dependencies. The
@ -115,6 +119,10 @@ pub struct ResolverInstallerOptions {
pub exclude_newer: Option<ExcludeNewer>,
pub link_mode: Option<LinkMode>,
pub compile_bytecode: Option<bool>,
pub upgrade: Option<bool>,
pub upgrade_package: Option<Vec<PackageName>>,
pub reinstall: Option<bool>,
pub reinstall_package: Option<Vec<PackageName>>,
}
/// A `[tool.uv.pip]` section.
@ -164,6 +172,10 @@ pub struct PipOptions {
pub link_mode: Option<LinkMode>,
pub compile_bytecode: Option<bool>,
pub require_hashes: Option<bool>,
pub upgrade: Option<bool>,
pub upgrade_package: Option<Vec<PackageName>>,
pub reinstall: Option<bool>,
pub reinstall_package: Option<Vec<PackageName>>,
pub concurrent_downloads: Option<NonZeroUsize>,
pub concurrent_builds: Option<NonZeroUsize>,
pub concurrent_installs: Option<NonZeroUsize>,
@ -217,6 +229,10 @@ impl Options {
link_mode,
compile_bytecode,
require_hashes,
upgrade,
upgrade_package,
reinstall,
reinstall_package,
concurrent_builds,
concurrent_downloads,
concurrent_installs,
@ -235,6 +251,10 @@ impl Options {
exclude_newer: top_level_exclude_newer,
link_mode: top_level_link_mode,
compile_bytecode: top_level_compile_bytecode,
upgrade: top_level_upgrade,
upgrade_package: top_level_upgrade_package,
reinstall: top_level_reinstall,
reinstall_package: top_level_reinstall_package,
} = self.top_level;
PipOptions {
@ -279,6 +299,10 @@ impl Options {
link_mode: link_mode.or(top_level_link_mode),
compile_bytecode: compile_bytecode.or(top_level_compile_bytecode),
require_hashes,
upgrade: upgrade.or(top_level_upgrade),
upgrade_package: upgrade_package.or(top_level_upgrade_package),
reinstall: reinstall.or(top_level_reinstall),
reinstall_package: reinstall_package.or(top_level_reinstall_package),
concurrent_builds,
concurrent_downloads,
concurrent_installs,

View file

@ -172,6 +172,7 @@ pub(crate) enum SelfCommand {
}
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub(crate) struct CacheNamespace {
#[command(subcommand)]
pub(crate) command: CacheCommand,
@ -195,6 +196,7 @@ pub(crate) struct CleanArgs {
}
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub(crate) struct PipNamespace {
#[command(subcommand)]
pub(crate) command: PipCommand,
@ -345,6 +347,9 @@ pub(crate) struct PipCompileArgs {
#[command(flatten)]
pub(crate) resolver: ResolverArgs,
#[command(flatten)]
pub(crate) refresh: RefreshArgs,
/// Ignore package dependencies, instead only add those packages explicitly listed
/// on the command line to the resulting the requirements file.
#[arg(long)]
@ -392,22 +397,6 @@ pub(crate) struct PipCompileArgs {
#[arg(long, env = "UV_CUSTOM_COMPILE_COMMAND")]
pub(crate) custom_compile_command: Option<String>,
/// Refresh all cached data.
#[arg(long, conflicts_with("offline"), overrides_with("no_refresh"))]
pub(crate) refresh: bool,
#[arg(
long,
conflicts_with("offline"),
overrides_with("refresh"),
hide = true
)]
pub(crate) no_refresh: bool,
/// Refresh cached data for a specific package.
#[arg(long)]
pub(crate) refresh_package: Vec<PackageName>,
/// The Python interpreter against which to compile the requirements.
///
/// By default, `uv` uses the virtual environment in the current working directory or any parent
@ -439,18 +428,6 @@ pub(crate) struct PipCompileArgs {
#[arg(long, overrides_with("system"), hide = true)]
pub(crate) no_system: bool,
/// Allow package upgrades, ignoring pinned versions in the existing output file.
#[arg(long, short = 'U', overrides_with("no_upgrade"))]
pub(crate) upgrade: bool,
#[arg(long, overrides_with("upgrade"), hide = true)]
pub(crate) no_upgrade: bool,
/// Allow upgrades for a specific package, ignoring pinned versions in the existing output
/// file.
#[arg(long, short = 'P')]
pub(crate) upgrade_package: Vec<PackageName>,
/// Include distribution hashes in the output file.
#[arg(long, overrides_with("no_generate_hashes"))]
pub(crate) generate_hashes: bool,
@ -609,6 +586,9 @@ pub(crate) struct PipSyncArgs {
#[command(flatten)]
pub(crate) installer: InstallerArgs,
#[command(flatten)]
pub(crate) refresh: RefreshArgs,
/// 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 UTC dates in the same
@ -616,33 +596,6 @@ pub(crate) struct PipSyncArgs {
#[arg(long, env = "UV_EXCLUDE_NEWER")]
pub(crate) exclude_newer: Option<ExcludeNewer>,
/// Reinstall all packages, regardless of whether they're already installed.
#[arg(long, alias = "force-reinstall", overrides_with("no_reinstall"))]
pub(crate) reinstall: bool,
#[arg(long, overrides_with("reinstall"), hide = true)]
pub(crate) no_reinstall: bool,
/// Reinstall a specific package, regardless of whether it's already installed.
#[arg(long)]
pub(crate) reinstall_package: Vec<PackageName>,
/// Refresh all cached data.
#[arg(long, conflicts_with("offline"), overrides_with("no_refresh"))]
pub(crate) refresh: bool,
#[arg(
long,
conflicts_with("offline"),
overrides_with("refresh"),
hide = true
)]
pub(crate) no_refresh: bool,
/// Refresh cached data for a specific package.
#[arg(long)]
pub(crate) refresh_package: Vec<PackageName>,
/// Require a matching hash for each requirement.
///
/// Hash-checking mode is all or nothing. If enabled, _all_ requirements must be provided
@ -893,43 +846,8 @@ pub(crate) struct PipInstallArgs {
#[command(flatten)]
pub(crate) installer: ResolverInstallerArgs,
/// Allow package upgrades.
#[arg(long, short = 'U', overrides_with("no_upgrade"))]
pub(crate) upgrade: bool,
#[arg(long, overrides_with("upgrade"), hide = true)]
pub(crate) no_upgrade: bool,
/// Allow upgrade of a specific package.
#[arg(long, short = 'P')]
pub(crate) upgrade_package: Vec<PackageName>,
/// Reinstall all packages, regardless of whether they're already installed.
#[arg(long, alias = "force-reinstall", overrides_with("no_reinstall"))]
pub(crate) reinstall: bool,
#[arg(long, overrides_with("reinstall"), hide = true)]
pub(crate) no_reinstall: bool,
/// Reinstall a specific package, regardless of whether it's already installed.
#[arg(long)]
pub(crate) reinstall_package: Vec<PackageName>,
/// Refresh all cached data.
#[arg(long, conflicts_with("offline"), overrides_with("no_refresh"))]
pub(crate) refresh: bool,
#[arg(
long,
conflicts_with("offline"),
overrides_with("refresh"),
hide = true
)]
pub(crate) no_refresh: bool,
/// Refresh cached data for a specific package.
#[arg(long)]
pub(crate) refresh_package: Vec<PackageName>,
#[command(flatten)]
pub(crate) refresh: RefreshArgs,
/// Ignore package dependencies, instead only installing those packages explicitly listed
/// on the command line or in the requirements files.
@ -1570,36 +1488,12 @@ pub(crate) struct RunArgs {
#[arg(long)]
pub(crate) with: Vec<String>,
/// Refresh all cached data.
#[arg(long, conflicts_with("offline"), overrides_with("no_refresh"))]
pub(crate) refresh: bool,
#[arg(
long,
conflicts_with("offline"),
overrides_with("refresh"),
hide = true
)]
pub(crate) no_refresh: bool,
/// Refresh cached data for a specific package.
#[arg(long)]
pub(crate) refresh_package: Vec<PackageName>,
/// Allow package upgrades, ignoring pinned versions in the existing lockfile.
#[arg(long, short = 'U', overrides_with("no_upgrade"))]
pub(crate) upgrade: bool,
#[arg(long, overrides_with("upgrade"), hide = true)]
pub(crate) no_upgrade: bool,
/// Allow upgrades for a specific package, ignoring pinned versions in the existing lockfile.
#[arg(long, short = 'P')]
pub(crate) upgrade_package: Vec<PackageName>,
#[command(flatten)]
pub(crate) installer: ResolverInstallerArgs,
#[command(flatten)]
pub(crate) refresh: RefreshArgs,
/// The Python interpreter to use to build the run environment.
///
/// By default, `uv` uses the virtual environment in the current working directory or any parent
@ -1643,25 +1537,12 @@ pub(crate) struct SyncArgs {
#[arg(long, overrides_with("dev"))]
pub(crate) no_dev: bool,
/// Refresh all cached data.
#[arg(long, conflicts_with("offline"), overrides_with("no_refresh"))]
pub(crate) refresh: bool,
#[arg(
long,
conflicts_with("offline"),
overrides_with("refresh"),
hide = true
)]
pub(crate) no_refresh: bool,
/// Refresh cached data for a specific package.
#[arg(long)]
pub(crate) refresh_package: Vec<PackageName>,
#[command(flatten)]
pub(crate) installer: InstallerArgs,
#[command(flatten)]
pub(crate) refresh: RefreshArgs,
/// The Python interpreter to use to build the run environment.
///
/// By default, `uv` uses the virtual environment in the current working directory or any parent
@ -1680,36 +1561,12 @@ pub(crate) struct SyncArgs {
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub(crate) struct LockArgs {
/// Refresh all cached data.
#[arg(long, conflicts_with("offline"), overrides_with("no_refresh"))]
pub(crate) refresh: bool,
#[arg(
long,
conflicts_with("offline"),
overrides_with("refresh"),
hide = true
)]
pub(crate) no_refresh: bool,
/// Refresh cached data for a specific package.
#[arg(long)]
pub(crate) refresh_package: Vec<PackageName>,
/// Allow package upgrades, ignoring pinned versions in the existing lockfile.
#[arg(long, short = 'U', overrides_with("no_upgrade"))]
pub(crate) upgrade: bool,
#[arg(long, overrides_with("upgrade"), hide = true)]
pub(crate) no_upgrade: bool,
/// Allow upgrades for a specific package, ignoring pinned versions in the existing lockfile.
#[arg(long, short = 'P')]
pub(crate) upgrade_package: Vec<PackageName>,
#[command(flatten)]
pub(crate) resolver: ResolverArgs,
#[command(flatten)]
pub(crate) refresh: RefreshArgs,
/// The Python interpreter to use to build the run environment.
///
/// By default, `uv` uses the virtual environment in the current working directory or any parent
@ -1772,6 +1629,7 @@ pub(crate) struct RemoveArgs {
}
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub(crate) struct ToolNamespace {
#[command(subcommand)]
pub(crate) command: ToolCommand,
@ -1806,6 +1664,9 @@ pub(crate) struct ToolRunArgs {
#[command(flatten)]
pub(crate) installer: ResolverInstallerArgs,
#[command(flatten)]
pub(crate) refresh: RefreshArgs,
/// The Python interpreter to use to build the run environment.
///
/// By default, `uv` uses the virtual environment in the current working directory or any parent
@ -1822,6 +1683,7 @@ pub(crate) struct ToolRunArgs {
}
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub(crate) struct ToolchainNamespace {
#[command(subcommand)]
pub(crate) command: ToolchainCommand,
@ -1866,6 +1728,7 @@ pub(crate) struct ToolchainInstallArgs {
}
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub(crate) struct IndexArgs {
/// The URL of the Python package index (by default: <https://pypi.org/simple>).
///
@ -1903,12 +1766,44 @@ pub(crate) struct IndexArgs {
pub(crate) no_index: bool,
}
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub(crate) struct RefreshArgs {
/// Refresh all cached data.
#[arg(long, conflicts_with("offline"), overrides_with("no_refresh"))]
pub(crate) refresh: bool,
#[arg(
long,
conflicts_with("offline"),
overrides_with("refresh"),
hide = true
)]
pub(crate) no_refresh: bool,
/// Refresh cached data for a specific package.
#[arg(long)]
pub(crate) refresh_package: Vec<PackageName>,
}
/// Arguments that are used by commands that need to install (but not resolve) packages.
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub(crate) struct InstallerArgs {
#[command(flatten)]
pub(crate) index_args: IndexArgs,
/// Reinstall all packages, regardless of whether they're already installed.
#[arg(long, alias = "force-reinstall", overrides_with("no_reinstall"))]
pub(crate) reinstall: bool,
#[arg(long, overrides_with("reinstall"), hide = true)]
pub(crate) no_reinstall: bool,
/// Reinstall a specific package, regardless of whether it's already installed.
#[arg(long)]
pub(crate) 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
@ -1961,10 +1856,23 @@ pub(crate) struct InstallerArgs {
/// Arguments that are used by commands that need to resolve (but not install) packages.
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub(crate) struct ResolverArgs {
#[command(flatten)]
pub(crate) index_args: IndexArgs,
/// Allow package upgrades, ignoring pinned versions in any existing output file.
#[arg(long, short = 'U', overrides_with("no_upgrade"))]
pub(crate) upgrade: bool,
#[arg(long, overrides_with("upgrade"), hide = true)]
pub(crate) no_upgrade: bool,
/// Allow upgrades for a specific package, ignoring pinned versions in any existing output
/// file.
#[arg(long, short = 'P')]
pub(crate) upgrade_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
@ -2024,10 +1932,34 @@ pub(crate) struct ResolverArgs {
/// Arguments that are used by commands that need to resolve and install packages.
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub(crate) struct ResolverInstallerArgs {
#[command(flatten)]
pub(crate) index_args: IndexArgs,
/// Allow package upgrades, ignoring pinned versions in any existing output file.
#[arg(long, short = 'U', overrides_with("no_upgrade"))]
pub(crate) upgrade: bool,
#[arg(long, overrides_with("upgrade"), hide = true)]
pub(crate) no_upgrade: bool,
/// Allow upgrades for a specific package, ignoring pinned versions in any existing output
/// file.
#[arg(long, short = 'P')]
pub(crate) upgrade_package: Vec<PackageName>,
/// Reinstall all packages, regardless of whether they're already installed.
#[arg(long, alias = "force-reinstall", overrides_with("no_reinstall"))]
pub(crate) reinstall: bool,
#[arg(long, overrides_with("reinstall"), hide = true)]
pub(crate) no_reinstall: bool,
/// Reinstall a specific package, regardless of whether it's already installed.
#[arg(long)]
pub(crate) 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

View file

@ -37,7 +37,7 @@ use crate::printer::Printer;
pub(crate) async fn pip_sync(
requirements: &[RequirementsSource],
constraints: &[RequirementsSource],
reinstall: &Reinstall,
reinstall: Reinstall,
link_mode: LinkMode,
compile: bool,
require_hashes: bool,
@ -280,7 +280,7 @@ pub(crate) async fn pip_sync(
preferences,
site_packages.clone(),
&hasher,
reinstall,
&reinstall,
&upgrade,
interpreter,
Some(&tags),
@ -340,7 +340,7 @@ pub(crate) async fn pip_sync(
&resolution,
site_packages,
Modifications::Exact,
reinstall,
&reinstall,
&build_options,
link_mode,
compile,

View file

@ -5,7 +5,7 @@ use anyhow::Result;
use pep508_rs::Requirement;
use uv_cache::Cache;
use uv_client::Connectivity;
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode, Upgrade};
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode};
use uv_distribution::pyproject_mut::PyProjectTomlMut;
use uv_distribution::ProjectWorkspace;
use uv_warnings::warn_user;
@ -50,13 +50,12 @@ pub(crate) async fn add(
// Use the default settings.
let settings = ResolverSettings::default();
let upgrade = Upgrade::default();
// Lock and sync the environment.
let lock = project::lock::do_lock(
project.workspace(),
venv.interpreter(),
upgrade,
&settings.upgrade,
&settings.index_locations,
&settings.index_strategy,
&settings.keyring_provider,
@ -87,6 +86,7 @@ pub(crate) async fn add(
&lock,
extras,
dev,
&settings.reinstall,
&settings.index_locations,
&settings.index_strategy,
&settings.keyring_provider,

View file

@ -30,7 +30,6 @@ use crate::settings::ResolverSettings;
/// Resolve the project requirements into a lockfile.
#[allow(clippy::too_many_arguments)]
pub(crate) async fn lock(
upgrade: Upgrade,
python: Option<String>,
settings: ResolverSettings,
preview: PreviewMode,
@ -54,7 +53,7 @@ pub(crate) async fn lock(
match do_lock(
&workspace,
&interpreter,
upgrade,
&settings.upgrade,
&settings.index_locations,
&settings.index_strategy,
&settings.keyring_provider,
@ -90,7 +89,7 @@ pub(crate) async fn lock(
pub(super) async fn do_lock(
workspace: &Workspace,
interpreter: &Interpreter,
upgrade: Upgrade,
upgrade: &Upgrade,
index_locations: &IndexLocations,
index_strategy: &IndexStrategy,
keyring_provider: &KeyringProviderType,
@ -164,7 +163,6 @@ pub(super) async fn do_lock(
let build_isolation = BuildIsolation::default();
let build_options = BuildOptions::default();
let extras = ExtrasSpecification::default();
let reinstall = Reinstall::default();
let setup_py = SetupPyStrategy::default();
// Resolve the flat indexes from `--find-links`.
@ -175,7 +173,7 @@ pub(super) async fn do_lock(
};
// If an existing lockfile exists, build up a set of preferences.
let LockedRequirements { preferences, git } = read_lockfile(workspace, &upgrade).await?;
let LockedRequirements { preferences, git } = read_lockfile(workspace, upgrade).await?;
// Create the Git resolver.
let git = GitResolver::from_refs(git);
@ -211,8 +209,8 @@ pub(super) async fn do_lock(
preferences,
EmptyInstalledPackages,
&hasher,
&reinstall,
&upgrade,
&Reinstall::default(),
upgrade,
interpreter,
None,
None,

View file

@ -10,8 +10,7 @@ use pep440_rs::Version;
use uv_cache::Cache;
use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::{
BuildOptions, Concurrency, ExtrasSpecification, PreviewMode, Reinstall, SetupPyStrategy,
Upgrade,
BuildOptions, Concurrency, ExtrasSpecification, PreviewMode, SetupPyStrategy,
};
use uv_dispatch::BuildDispatch;
use uv_distribution::Workspace;
@ -279,6 +278,8 @@ pub(crate) async fn update_environment(
exclude_newer,
link_mode,
compile_bytecode,
upgrade,
reinstall,
} = settings;
let client_builder = BaseClientBuilder::new()
@ -353,9 +354,7 @@ pub(crate) async fn update_environment(
let extras = ExtrasSpecification::default();
let hasher = HashStrategy::default();
let preferences = Vec::default();
let reinstall = Reinstall::default();
let setup_py = SetupPyStrategy::default();
let upgrade = Upgrade::default();
// Resolve the flat indexes from `--find-links`.
let flat_index = {
@ -395,8 +394,8 @@ pub(crate) async fn update_environment(
preferences,
site_packages.clone(),
&hasher,
&reinstall,
&upgrade,
reinstall,
upgrade,
interpreter,
Some(tags),
Some(markers),
@ -448,7 +447,7 @@ pub(crate) async fn update_environment(
&resolution,
site_packages,
pip::operations::Modifications::Sufficient,
&reinstall,
reinstall,
&build_options,
*link_mode,
*compile_bytecode,

View file

@ -1,10 +1,10 @@
use anyhow::Result;
use pep508_rs::PackageName;
use uv_distribution::pyproject_mut::PyProjectTomlMut;
use pep508_rs::PackageName;
use uv_cache::Cache;
use uv_client::Connectivity;
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode, Upgrade};
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode};
use uv_distribution::pyproject_mut::PyProjectTomlMut;
use uv_distribution::ProjectWorkspace;
use uv_warnings::warn_user;
@ -52,13 +52,12 @@ pub(crate) async fn remove(
// Use the default settings.
let settings = ResolverSettings::default();
let upgrade = Upgrade::default();
// Lock and sync the environment.
let lock = project::lock::do_lock(
project.workspace(),
venv.interpreter(),
upgrade,
&settings.upgrade,
&settings.index_locations,
&settings.index_strategy,
&settings.keyring_provider,
@ -89,6 +88,7 @@ pub(crate) async fn remove(
&lock,
extras,
dev,
&settings.reinstall,
&settings.index_locations,
&settings.index_strategy,
&settings.keyring_provider,

View file

@ -8,7 +8,7 @@ use tracing::debug;
use uv_cache::Cache;
use uv_client::{BaseClientBuilder, Connectivity};
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode, Upgrade};
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode};
use uv_distribution::{ProjectWorkspace, Workspace};
use uv_normalize::PackageName;
use uv_requirements::RequirementsSource;
@ -28,7 +28,6 @@ pub(crate) async fn run(
mut args: Vec<OsString>,
requirements: Vec<RequirementsSource>,
python: Option<String>,
upgrade: Upgrade,
package: Option<PackageName>,
settings: ResolverInstallerSettings,
isolated: bool,
@ -67,7 +66,7 @@ pub(crate) async fn run(
let lock = project::lock::do_lock(
project.workspace(),
venv.interpreter(),
upgrade,
&settings.upgrade,
&settings.index_locations,
&settings.index_strategy,
&settings.keyring_provider,
@ -91,6 +90,7 @@ pub(crate) async fn run(
&lock,
extras,
dev,
&settings.reinstall,
&settings.index_locations,
&settings.index_strategy,
&settings.keyring_provider,

View file

@ -1,9 +1,9 @@
use std::path::Path;
use anyhow::Result;
use distribution_types::IndexLocations;
use install_wheel_rs::linker::LinkMode;
use uv_cache::Cache;
use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::{
@ -65,6 +65,7 @@ pub(crate) async fn sync(
&lock,
extras,
dev,
&settings.reinstall,
&settings.index_locations,
&settings.index_strategy,
&settings.keyring_provider,
@ -92,6 +93,7 @@ pub(super) async fn do_sync(
lock: &Lock,
extras: ExtrasSpecification,
dev: bool,
reinstall: &Reinstall,
index_locations: &IndexLocations,
index_strategy: &IndexStrategy,
keyring_provider: &KeyringProviderType,
@ -151,7 +153,6 @@ pub(super) async fn do_sync(
let build_options = BuildOptions::default();
let dry_run = false;
let hasher = HashStrategy::default();
let reinstall = Reinstall::default();
let setup_py = SetupPyStrategy::default();
// Resolve the flat indexes from `--find-links`.
@ -187,7 +188,7 @@ pub(super) async fn do_sync(
&resolution,
site_packages,
Modifications::Sufficient,
&reinstall,
reinstall,
&build_options,
*link_mode,
*compile_bytecode,

View file

@ -232,7 +232,7 @@ async fn run() -> Result<ExitStatus> {
args.settings.resolution,
args.settings.prerelease,
args.settings.dependency_mode,
args.upgrade,
args.settings.upgrade,
args.settings.generate_hashes,
args.settings.no_emit_package,
args.settings.no_strip_extras,
@ -297,7 +297,7 @@ async fn run() -> Result<ExitStatus> {
commands::pip_sync(
&requirements,
&constraints,
&args.reinstall,
args.settings.reinstall,
args.settings.link_mode,
args.settings.compile_bytecode,
args.settings.require_hashes,
@ -373,11 +373,11 @@ async fn run() -> Result<ExitStatus> {
args.settings.resolution,
args.settings.prerelease,
args.settings.dependency_mode,
args.upgrade,
args.settings.upgrade,
args.settings.index_locations,
args.settings.index_strategy,
args.settings.keyring_provider,
args.reinstall,
args.settings.reinstall,
args.settings.link_mode,
args.settings.compile_bytecode,
args.settings.require_hashes,
@ -581,20 +581,6 @@ async fn run() -> Result<ExitStatus> {
.with
.into_iter()
.map(RequirementsSource::from_package)
// TODO(zanieb): Consider editable package support. What benefit do these have in an ephemeral
// environment?
// .chain(
// args.with_editable
// .into_iter()
// .map(RequirementsSource::Editable),
// )
// TODO(zanieb): Consider requirements file support, this comes with additional complexity due to
// to the extensive configuration allowed in requirements files
// .chain(
// args.with_requirements
// .into_iter()
// .map(RequirementsSource::from_requirements_file),
// )
.collect::<Vec<_>>();
commands::run(
@ -604,7 +590,6 @@ async fn run() -> Result<ExitStatus> {
args.args,
requirements,
args.python,
args.upgrade,
args.package,
args.settings,
globals.isolated,
@ -646,7 +631,6 @@ async fn run() -> Result<ExitStatus> {
let cache = cache.init()?.with_refresh(args.refresh);
commands::lock(
args.upgrade,
args.python,
args.settings,
globals.preview,
@ -715,7 +699,7 @@ async fn run() -> Result<ExitStatus> {
let args = settings::ToolRunSettings::resolve(args, filesystem);
// Initialize the cache.
let cache = cache.init()?;
let cache = cache.init()?.with_refresh(args.refresh);
commands::run_tool(
args.target,

View file

@ -26,8 +26,8 @@ use uv_toolchain::{Prefix, PythonVersion, Target};
use crate::cli::{
AddArgs, ColorChoice, GlobalArgs, IndexArgs, InstallerArgs, LockArgs, Maybe, PipCheckArgs,
PipCompileArgs, PipFreezeArgs, PipInstallArgs, PipListArgs, PipShowArgs, PipSyncArgs,
PipUninstallArgs, RemoveArgs, ResolverArgs, ResolverInstallerArgs, RunArgs, SyncArgs,
ToolRunArgs, ToolchainInstallArgs, ToolchainListArgs, VenvArgs,
PipUninstallArgs, RefreshArgs, RemoveArgs, ResolverArgs, ResolverInstallerArgs, RunArgs,
SyncArgs, ToolRunArgs, ToolchainInstallArgs, ToolchainListArgs, VenvArgs,
};
use crate::commands::ListFormat;
@ -121,9 +121,8 @@ pub(crate) struct RunSettings {
pub(crate) args: Vec<OsString>,
pub(crate) with: Vec<String>,
pub(crate) python: Option<String>,
pub(crate) refresh: Refresh,
pub(crate) upgrade: Upgrade,
pub(crate) package: Option<PackageName>,
pub(crate) refresh: Refresh,
pub(crate) settings: ResolverInstallerSettings,
}
@ -140,20 +139,13 @@ impl RunSettings {
target,
args,
with,
refresh,
no_refresh,
refresh_package,
upgrade,
no_upgrade,
upgrade_package,
installer,
refresh,
python,
package,
} = args;
Self {
refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package),
upgrade: Upgrade::from_args(flag(upgrade, no_upgrade), upgrade_package),
extras: ExtrasSpecification::from_args(
flag(all_extras, no_all_extras).unwrap_or_default(),
extra.unwrap_or_default(),
@ -164,6 +156,7 @@ impl RunSettings {
with,
python,
package,
refresh: Refresh::from(refresh),
settings: ResolverInstallerSettings::combine(
ResolverInstallerOptions::from(installer),
filesystem,
@ -181,6 +174,7 @@ pub(crate) struct ToolRunSettings {
pub(crate) from: Option<String>,
pub(crate) with: Vec<String>,
pub(crate) python: Option<String>,
pub(crate) refresh: Refresh,
pub(crate) settings: ResolverInstallerSettings,
}
@ -194,6 +188,7 @@ impl ToolRunSettings {
from,
with,
installer,
refresh,
python,
} = args;
@ -203,6 +198,7 @@ impl ToolRunSettings {
from,
with,
python,
refresh: Refresh::from(refresh),
settings: ResolverInstallerSettings::combine(
ResolverInstallerOptions::from(installer),
filesystem,
@ -276,10 +272,10 @@ impl ToolchainInstallSettings {
#[allow(clippy::struct_excessive_bools, dead_code)]
#[derive(Debug, Clone)]
pub(crate) struct SyncSettings {
pub(crate) refresh: Refresh,
pub(crate) extras: ExtrasSpecification,
pub(crate) dev: bool,
pub(crate) python: Option<String>,
pub(crate) refresh: Refresh,
pub(crate) settings: InstallerSettings,
}
@ -293,21 +289,19 @@ impl SyncSettings {
no_all_extras,
dev,
no_dev,
refresh,
no_refresh,
refresh_package,
installer,
refresh,
python,
} = args;
Self {
refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package),
extras: ExtrasSpecification::from_args(
flag(all_extras, no_all_extras).unwrap_or_default(),
extra.unwrap_or_default(),
),
dev: flag(dev, no_dev).unwrap_or(true),
python,
refresh: Refresh::from(refresh),
settings: InstallerSettings::combine(InstallerOptions::from(installer), filesystem),
}
}
@ -317,9 +311,8 @@ impl SyncSettings {
#[allow(clippy::struct_excessive_bools, dead_code)]
#[derive(Debug, Clone)]
pub(crate) struct LockSettings {
pub(crate) refresh: Refresh,
pub(crate) upgrade: Upgrade,
pub(crate) python: Option<String>,
pub(crate) refresh: Refresh,
pub(crate) settings: ResolverSettings,
}
@ -328,20 +321,14 @@ impl LockSettings {
#[allow(clippy::needless_pass_by_value)]
pub(crate) fn resolve(args: LockArgs, filesystem: Option<FilesystemOptions>) -> Self {
let LockArgs {
refresh,
no_refresh,
refresh_package,
upgrade,
no_upgrade,
upgrade_package,
resolver,
refresh,
python,
} = args;
Self {
refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package),
upgrade: Upgrade::from_args(flag(upgrade, no_upgrade), upgrade_package),
python,
refresh: Refresh::from(refresh),
settings: ResolverSettings::combine(ResolverOptions::from(resolver), filesystem),
}
}
@ -402,9 +389,8 @@ pub(crate) struct PipCompileSettings {
pub(crate) src_file: Vec<PathBuf>,
pub(crate) constraint: Vec<PathBuf>,
pub(crate) r#override: Vec<PathBuf>,
pub(crate) refresh: Refresh,
pub(crate) upgrade: Upgrade,
pub(crate) overrides_from_workspace: Vec<Requirement>,
pub(crate) refresh: Refresh,
pub(crate) settings: PipSettings,
}
@ -418,6 +404,7 @@ impl PipCompileSettings {
extra,
all_extras,
no_all_extras,
refresh,
no_deps,
deps,
output_file,
@ -429,16 +416,10 @@ impl PipCompileSettings {
header,
annotation_style,
custom_compile_command,
refresh,
no_refresh,
refresh_package,
resolver,
python,
system,
no_system,
upgrade,
no_upgrade,
upgrade_package,
generate_hashes,
no_generate_hashes,
legacy_setup_py,
@ -484,9 +465,8 @@ impl PipCompileSettings {
.filter_map(Maybe::into_option)
.collect(),
r#override,
refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package),
upgrade: Upgrade::from_args(flag(upgrade, no_upgrade), upgrade_package),
overrides_from_workspace,
refresh: Refresh::from(refresh),
settings: PipSettings::combine(
PipOptions {
python,
@ -530,9 +510,8 @@ impl PipCompileSettings {
pub(crate) struct PipSyncSettings {
pub(crate) src_file: Vec<PathBuf>,
pub(crate) constraint: Vec<PathBuf>,
pub(crate) reinstall: Reinstall,
pub(crate) refresh: Refresh,
pub(crate) dry_run: bool,
pub(crate) refresh: Refresh,
pub(crate) settings: PipSettings,
}
@ -543,13 +522,8 @@ impl PipSyncSettings {
src_file,
constraint,
installer,
exclude_newer,
reinstall,
no_reinstall,
reinstall_package,
refresh,
no_refresh,
refresh_package,
exclude_newer,
require_hashes,
no_require_hashes,
python,
@ -581,9 +555,8 @@ impl PipSyncSettings {
.into_iter()
.filter_map(Maybe::into_option)
.collect(),
reinstall: Reinstall::from_args(flag(reinstall, no_reinstall), reinstall_package),
refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package),
dry_run,
refresh: Refresh::from(refresh),
settings: PipSettings::combine(
PipOptions {
python,
@ -621,11 +594,9 @@ pub(crate) struct PipInstallSettings {
pub(crate) editable: Vec<String>,
pub(crate) constraint: Vec<PathBuf>,
pub(crate) r#override: Vec<PathBuf>,
pub(crate) upgrade: Upgrade,
pub(crate) reinstall: Reinstall,
pub(crate) refresh: Refresh,
pub(crate) dry_run: bool,
pub(crate) overrides_from_workspace: Vec<Requirement>,
pub(crate) refresh: Refresh,
pub(crate) settings: PipSettings,
}
@ -641,15 +612,7 @@ impl PipInstallSettings {
extra,
all_extras,
no_all_extras,
upgrade,
no_upgrade,
upgrade_package,
reinstall,
no_reinstall,
reinstall_package,
refresh,
no_refresh,
refresh_package,
no_deps,
deps,
require_hashes,
@ -701,11 +664,9 @@ impl PipInstallSettings {
.filter_map(Maybe::into_option)
.collect(),
r#override,
upgrade: Upgrade::from_args(flag(upgrade, no_upgrade), upgrade_package),
reinstall: Reinstall::from_args(flag(reinstall, no_reinstall), reinstall_package),
refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package),
dry_run,
overrides_from_workspace,
refresh: Refresh::from(refresh),
settings: PipSettings::combine(
PipOptions {
python,
@ -991,6 +952,7 @@ pub(crate) struct InstallerSettings {
pub(crate) config_setting: ConfigSettings,
pub(crate) link_mode: LinkMode,
pub(crate) compile_bytecode: bool,
pub(crate) reinstall: Reinstall,
}
impl InstallerSettings {
@ -1009,6 +971,10 @@ impl InstallerSettings {
exclude_newer: _,
link_mode,
compile_bytecode,
upgrade: _,
upgrade_package: _,
reinstall,
reinstall_package,
} = filesystem
.map(FilesystemOptions::into_options)
.map(|options| options.top_level)
@ -1040,6 +1006,12 @@ impl InstallerSettings {
.compile_bytecode
.combine(compile_bytecode)
.unwrap_or_default(),
reinstall: Reinstall::from_args(
args.reinstall.or(reinstall),
args.reinstall_package
.or(reinstall_package)
.unwrap_or_default(),
),
}
}
}
@ -1059,6 +1031,7 @@ pub(crate) struct ResolverSettings {
pub(crate) config_setting: ConfigSettings,
pub(crate) exclude_newer: Option<ExcludeNewer>,
pub(crate) link_mode: LinkMode,
pub(crate) upgrade: Upgrade,
}
impl ResolverSettings {
@ -1077,6 +1050,10 @@ impl ResolverSettings {
exclude_newer,
link_mode,
compile_bytecode: _,
upgrade,
upgrade_package,
reinstall: _,
reinstall_package: _,
} = filesystem
.map(FilesystemOptions::into_options)
.map(|options| options.top_level)
@ -1107,6 +1084,10 @@ impl ResolverSettings {
.unwrap_or_default(),
exclude_newer: args.exclude_newer.combine(exclude_newer),
link_mode: args.link_mode.combine(link_mode).unwrap_or_default(),
upgrade: Upgrade::from_args(
args.upgrade.or(upgrade),
args.upgrade_package.or(upgrade_package).unwrap_or_default(),
),
}
}
}
@ -1128,6 +1109,8 @@ pub(crate) struct ResolverInstallerSettings {
pub(crate) exclude_newer: Option<ExcludeNewer>,
pub(crate) link_mode: LinkMode,
pub(crate) compile_bytecode: bool,
pub(crate) upgrade: Upgrade,
pub(crate) reinstall: Reinstall,
}
impl ResolverInstallerSettings {
@ -1149,6 +1132,10 @@ impl ResolverInstallerSettings {
exclude_newer,
link_mode,
compile_bytecode,
upgrade,
upgrade_package,
reinstall,
reinstall_package,
} = filesystem
.map(FilesystemOptions::into_options)
.map(|options| options.top_level)
@ -1183,6 +1170,16 @@ impl ResolverInstallerSettings {
.compile_bytecode
.combine(compile_bytecode)
.unwrap_or_default(),
upgrade: Upgrade::from_args(
args.upgrade.or(upgrade),
args.upgrade_package.or(upgrade_package).unwrap_or_default(),
),
reinstall: Reinstall::from_args(
args.reinstall.or(reinstall),
args.reinstall_package
.or(reinstall_package)
.unwrap_or_default(),
),
}
}
}
@ -1230,6 +1227,8 @@ pub(crate) struct PipSettings {
pub(crate) link_mode: LinkMode,
pub(crate) compile_bytecode: bool,
pub(crate) require_hashes: bool,
pub(crate) upgrade: Upgrade,
pub(crate) reinstall: Reinstall,
pub(crate) concurrency: Concurrency,
}
@ -1278,6 +1277,10 @@ impl PipSettings {
link_mode,
compile_bytecode,
require_hashes,
upgrade,
upgrade_package,
reinstall,
reinstall_package,
concurrent_builds,
concurrent_downloads,
concurrent_installs,
@ -1393,6 +1396,16 @@ impl PipSettings {
.combine(compile_bytecode)
.unwrap_or_default(),
strict: args.strict.combine(strict).unwrap_or_default(),
upgrade: Upgrade::from_args(
args.upgrade.or(upgrade),
args.upgrade_package.or(upgrade_package).unwrap_or_default(),
),
reinstall: Reinstall::from_args(
args.reinstall.or(reinstall),
args.reinstall_package
.or(reinstall_package)
.unwrap_or_default(),
),
concurrency: Concurrency {
downloads: args
.concurrent_downloads
@ -1462,10 +1475,25 @@ fn flag(yes: bool, no: bool) -> Option<bool> {
}
}
impl From<RefreshArgs> for Refresh {
fn from(value: RefreshArgs) -> Self {
let RefreshArgs {
refresh,
no_refresh,
refresh_package,
} = value;
Self::from_args(flag(refresh, no_refresh), refresh_package)
}
}
impl From<ResolverArgs> for PipOptions {
fn from(args: ResolverArgs) -> Self {
let ResolverArgs {
index_args,
upgrade,
no_upgrade,
upgrade_package,
index_strategy,
keyring_provider,
resolution,
@ -1486,6 +1514,8 @@ impl From<ResolverArgs> for PipOptions {
}),
no_index: Some(index_args.no_index),
find_links: index_args.find_links,
upgrade: flag(upgrade, no_upgrade),
upgrade_package: Some(upgrade_package),
index_strategy,
keyring_provider,
resolution,
@ -1507,6 +1537,9 @@ impl From<InstallerArgs> for PipOptions {
fn from(args: InstallerArgs) -> Self {
let InstallerArgs {
index_args,
reinstall,
no_reinstall,
reinstall_package,
index_strategy,
keyring_provider,
config_setting,
@ -1525,6 +1558,8 @@ impl From<InstallerArgs> for PipOptions {
}),
no_index: Some(index_args.no_index),
find_links: index_args.find_links,
reinstall: flag(reinstall, no_reinstall),
reinstall_package: Some(reinstall_package),
index_strategy,
keyring_provider,
config_settings: config_setting
@ -1540,6 +1575,12 @@ impl From<ResolverInstallerArgs> for PipOptions {
fn from(args: ResolverInstallerArgs) -> Self {
let ResolverInstallerArgs {
index_args,
upgrade,
no_upgrade,
upgrade_package,
reinstall,
no_reinstall,
reinstall_package,
index_strategy,
keyring_provider,
resolution,
@ -1562,6 +1603,10 @@ impl From<ResolverInstallerArgs> for PipOptions {
}),
no_index: Some(index_args.no_index),
find_links: index_args.find_links,
upgrade: flag(upgrade, no_upgrade),
upgrade_package: Some(upgrade_package),
reinstall: flag(reinstall, no_reinstall),
reinstall_package: Some(reinstall_package),
index_strategy,
keyring_provider,
resolution,
@ -1584,6 +1629,9 @@ impl From<InstallerArgs> for InstallerOptions {
fn from(args: InstallerArgs) -> Self {
let InstallerArgs {
index_args,
reinstall,
no_reinstall,
reinstall_package,
index_strategy,
keyring_provider,
config_setting,
@ -1602,6 +1650,8 @@ impl From<InstallerArgs> for InstallerOptions {
}),
no_index: Some(index_args.no_index),
find_links: index_args.find_links,
reinstall: flag(reinstall, no_reinstall),
reinstall_package: Some(reinstall_package),
index_strategy,
keyring_provider,
config_settings: config_setting
@ -1616,6 +1666,9 @@ impl From<ResolverArgs> for ResolverOptions {
fn from(args: ResolverArgs) -> Self {
let ResolverArgs {
index_args,
upgrade,
no_upgrade,
upgrade_package,
index_strategy,
keyring_provider,
resolution,
@ -1636,6 +1689,8 @@ impl From<ResolverArgs> for ResolverOptions {
}),
no_index: Some(index_args.no_index),
find_links: index_args.find_links,
upgrade: flag(upgrade, no_upgrade),
upgrade_package: Some(upgrade_package),
index_strategy,
keyring_provider,
resolution,
@ -1656,6 +1711,12 @@ impl From<ResolverInstallerArgs> for ResolverInstallerOptions {
fn from(args: ResolverInstallerArgs) -> Self {
let ResolverInstallerArgs {
index_args,
upgrade,
no_upgrade,
upgrade_package,
reinstall,
no_reinstall,
reinstall_package,
index_strategy,
keyring_provider,
resolution,
@ -1678,6 +1739,10 @@ impl From<ResolverInstallerArgs> for ResolverInstallerOptions {
}),
no_index: Some(index_args.no_index),
find_links: index_args.find_links,
upgrade: flag(upgrade, no_upgrade),
upgrade_package: Some(upgrade_package),
reinstall: flag(reinstall, no_reinstall),
reinstall_package: Some(reinstall_package),
index_strategy,
keyring_provider,
resolution,