Skip to content

Commit

Permalink
Respect resolver settings in uv remove (#4930)
Browse files Browse the repository at this point in the history
## Summary

Closes #4925
  • Loading branch information
charliermarsh committed Jul 9, 2024
1 parent 5f20bdb commit 92290d8
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 15 deletions.
9 changes: 9 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,15 @@ pub struct RemoveArgs {
#[arg(long, conflicts_with("dev"))]
pub optional: Option<ExtraName>,

#[command(flatten)]
pub installer: ResolverInstallerArgs,

#[command(flatten)]
pub build: BuildArgs,

#[command(flatten)]
pub refresh: RefreshArgs,

/// Remove the dependency from a specific package in the workspace.
#[arg(long, conflicts_with = "isolated")]
pub package: Option<PackageName>,
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/pip/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::commands::ExitStatus;
use crate::printer::Printer;

/// Resolve a set of requirements into a set of pinned versions.
#[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)]
#[allow(clippy::fn_params_excessive_bools)]
pub(crate) async fn pip_compile(
requirements: &[RequirementsSource],
constraints: &[RequirementsSource],
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/pip/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::commands::{elapsed, ExitStatus, SharedState};
use crate::printer::Printer;

/// Install packages into the current environment.
#[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)]
#[allow(clippy::fn_params_excessive_bools)]
pub(crate) async fn pip_install(
requirements: &[RequirementsSource],
constraints: &[RequirementsSource],
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/pip/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::commands::ExitStatus;
use crate::printer::Printer;

/// Enumerate the installed packages in the current environment.
#[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)]
#[allow(clippy::fn_params_excessive_bools)]
pub(crate) fn pip_list(
editable: bool,
exclude_editable: bool,
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/pip/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::commands::{ExitStatus, SharedState};
use crate::printer::Printer;

/// Install a set of locked requirements into the current Python environment.
#[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)]
#[allow(clippy::fn_params_excessive_bools)]
pub(crate) async fn pip_sync(
requirements: &[RequirementsSource],
constraints: &[RequirementsSource],
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/project/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::printer::Printer;
use crate::settings::ResolverInstallerSettings;

/// Add one or more packages to the project requirements.
#[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)]
#[allow(clippy::fn_params_excessive_bools)]
pub(crate) async fn add(
requirements: Vec<RequirementsSource>,
editable: Option<bool>,
Expand Down
11 changes: 4 additions & 7 deletions crates/uv/src/commands/project/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ use uv_warnings::{warn_user, warn_user_once};
use crate::commands::pip::operations::Modifications;
use crate::commands::{project, ExitStatus, SharedState};
use crate::printer::Printer;
use crate::settings::{InstallerSettings, ResolverSettings};
use crate::settings::ResolverInstallerSettings;

/// Remove one or more packages from the project requirements.
pub(crate) async fn remove(
requirements: Vec<PackageName>,
dependency_type: DependencyType,
package: Option<PackageName>,
python: Option<String>,
settings: ResolverInstallerSettings,
python_preference: PythonPreference,
python_fetch: PythonFetch,
preview: PreviewMode,
Expand Down Expand Up @@ -94,17 +95,14 @@ pub(crate) async fn remove(
)
.await?;

// Use the default settings.
let settings = ResolverSettings::default();

// Initialize any shared state.
let state = SharedState::default();

// Lock and sync the environment.
let lock = project::lock::do_lock(
project.workspace(),
venv.interpreter(),
settings.as_ref(),
settings.as_ref().into(),
&state,
preview,
connectivity,
Expand All @@ -117,7 +115,6 @@ pub(crate) async fn remove(

// Perform a full sync, because we don't know what exactly is affected by the removal.
// TODO(ibraheem): Should we accept CLI overrides for this? Should we even sync here?
let settings = InstallerSettings::default();
let extras = ExtrasSpecification::All;
let dev = true;

Expand All @@ -128,7 +125,7 @@ pub(crate) async fn remove(
extras,
dev,
Modifications::Exact,
settings.as_ref(),
settings.as_ref().into(),
&state,
preview,
connectivity,
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ enum VenvError {
}

/// Create a virtual environment.
#[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)]
#[allow(clippy::fn_params_excessive_bools)]
async fn venv_impl(
path: &Path,
python_request: Option<&str>,
Expand Down
3 changes: 2 additions & 1 deletion crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,13 +959,14 @@ async fn run_project(
show_settings!(args);

// Initialize the cache.
let cache = cache.init()?;
let cache = cache.init()?.with_refresh(args.refresh);

commands::remove(
args.requirements,
args.dependency_type,
args.package,
args.python,
args.settings,
globals.python_preference,
globals.python_fetch,
globals.preview,
Expand Down
12 changes: 11 additions & 1 deletion crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,16 +565,21 @@ pub(crate) struct RemoveSettings {
pub(crate) dependency_type: DependencyType,
pub(crate) package: Option<PackageName>,
pub(crate) python: Option<String>,
pub(crate) refresh: Refresh,
pub(crate) settings: ResolverInstallerSettings,
}

impl RemoveSettings {
/// Resolve the [`RemoveSettings`] from the CLI and filesystem configuration.
#[allow(clippy::needless_pass_by_value)]
pub(crate) fn resolve(args: RemoveArgs, _filesystem: Option<FilesystemOptions>) -> Self {
pub(crate) fn resolve(args: RemoveArgs, filesystem: Option<FilesystemOptions>) -> Self {
let RemoveArgs {
dev,
optional,
requirements,
installer,
build,
refresh,
package,
python,
} = args;
Expand All @@ -592,6 +597,11 @@ impl RemoveSettings {
dependency_type,
package,
python,
refresh: Refresh::from(refresh),
settings: ResolverInstallerSettings::combine(
resolver_installer_options(installer, build),
filesystem,
),
}
}
}
Expand Down

0 comments on commit 92290d8

Please sign in to comment.