Skip to content

Commit

Permalink
add --keep-untracked option to uv sync, default in uv add/run
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed Jun 17, 2024
1 parent bdc399e commit dc78d8b
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions crates/uv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,11 @@ pub(crate) struct SyncArgs {
#[arg(long, overrides_with("dev"))]
pub(crate) no_dev: bool,

/// Keeps installations no tracked as dependencies.
/// Without this flag any extraneous installations will be removed.
#[arg(long)]
pub(crate) keep_untracked: bool,

#[command(flatten)]
pub(crate) installer: InstallerArgs,

Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::printer::Printer;
mod cache_clean;
mod cache_dir;
mod cache_prune;
mod pip;
pub(crate) mod pip;
mod project;
pub(crate) mod reporters;
mod tool;
Expand Down
2 changes: 2 additions & 0 deletions crates/uv/src/commands/project/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode, SetupPyStr
use uv_distribution::{DistributionDatabase, ProjectWorkspace};
use uv_warnings::warn_user;

use crate::commands::pip::operations::Modifications;
use crate::commands::pip::resolution_environment;
use crate::commands::reporters::ResolverReporter;
use crate::commands::{project, ExitStatus};
Expand Down Expand Up @@ -172,6 +173,7 @@ pub(crate) async fn add(
&lock,
extras,
dev,
Modifications::Sufficient,
&settings.reinstall,
&settings.index_locations,
&settings.index_strategy,
Expand Down
2 changes: 2 additions & 0 deletions crates/uv/src/commands/project/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use uv_distribution::pyproject_mut::PyProjectTomlMut;
use uv_distribution::ProjectWorkspace;
use uv_warnings::warn_user;

use crate::commands::pip::operations::Modifications;
use crate::commands::{project, ExitStatus};
use crate::printer::Printer;
use crate::settings::{InstallerSettings, ResolverSettings};
Expand Down Expand Up @@ -121,6 +122,7 @@ pub(crate) async fn remove(
&lock,
extras,
dev,
Modifications::Exact,
&settings.reinstall,
&settings.index_locations,
&settings.index_strategy,
Expand Down
2 changes: 2 additions & 0 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use uv_requirements::RequirementsSource;
use uv_toolchain::{PythonEnvironment, SystemPython, Toolchain, ToolchainRequest};
use uv_warnings::warn_user;

use crate::commands::pip::operations::Modifications;
use crate::commands::{project, ExitStatus};
use crate::printer::Printer;
use crate::settings::ResolverInstallerSettings;
Expand Down Expand Up @@ -91,6 +92,7 @@ pub(crate) async fn run(
&lock,
extras,
dev,
Modifications::Sufficient,
&settings.reinstall,
&settings.index_locations,
&settings.index_strategy,
Expand Down
5 changes: 4 additions & 1 deletion crates/uv/src/commands/project/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::settings::InstallerSettings;
pub(crate) async fn sync(
extras: ExtrasSpecification,
dev: bool,
modifications: Modifications,
python: Option<String>,
settings: InstallerSettings,
preview: PreviewMode,
Expand Down Expand Up @@ -65,6 +66,7 @@ pub(crate) async fn sync(
&lock,
extras,
dev,
modifications,
&settings.reinstall,
&settings.index_locations,
&settings.index_strategy,
Expand Down Expand Up @@ -94,6 +96,7 @@ pub(super) async fn do_sync(
lock: &Lock,
extras: ExtrasSpecification,
dev: bool,
modifications: Modifications,
reinstall: &Reinstall,
index_locations: &IndexLocations,
index_strategy: &IndexStrategy,
Expand Down Expand Up @@ -188,7 +191,7 @@ pub(super) async fn do_sync(
pip::operations::install(
&resolution,
site_packages,
Modifications::Exact,
modifications,
reinstall,
build_options,
*link_mode,
Expand Down
1 change: 1 addition & 0 deletions crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ async fn run() -> Result<ExitStatus> {
commands::sync(
args.extras,
args.dev,
args.modifications,
args.python,
args.settings,
globals.preview,
Expand Down
10 changes: 10 additions & 0 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::cli::{
RunArgs, SyncArgs, ToolRunArgs, ToolchainFindArgs, ToolchainInstallArgs, ToolchainListArgs,
VenvArgs,
};
use crate::commands::pip::operations::Modifications;
use crate::commands::ListFormat;

/// The resolved global settings to use for any invocation of the CLI.
Expand Down Expand Up @@ -297,6 +298,7 @@ impl ToolchainFindSettings {
pub(crate) struct SyncSettings {
pub(crate) extras: ExtrasSpecification,
pub(crate) dev: bool,
pub(crate) modifications: Modifications,
pub(crate) python: Option<String>,
pub(crate) refresh: Refresh,
pub(crate) settings: InstallerSettings,
Expand All @@ -312,18 +314,26 @@ impl SyncSettings {
no_all_extras,
dev,
no_dev,
keep_untracked,
installer,
build,
refresh,
python,
} = args;

let modifications = if keep_untracked {
Modifications::Sufficient
} else {
Modifications::Exact
};

Self {
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),
modifications,
python,
refresh: Refresh::from(refresh),
settings: InstallerSettings::combine(installer_options(installer, build), filesystem),
Expand Down

0 comments on commit dc78d8b

Please sign in to comment.