Skip to content
Open
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
39 changes: 39 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,19 @@ pub struct PipCompileArgs {
#[arg(long, alias = "exclude", env = EnvVars::UV_EXCLUDE, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub excludes: Vec<Maybe<PathBuf>>,

/// Exclude the given packages from resolution.
///
/// When a package is excluded, it will be omitted from the dependency list entirely and its own
/// dependencies will be ignored during the resolution phase.
///
/// May be provided multiple times or multiple values can be provided separated by commas.
#[arg(
long = "exclude-packages",
alias = "exclude-package",
value_delimiter = ','
)]
pub exclude_packages: Vec<PackageName>,

/// Constrain build dependencies using the given requirements files when building source
/// distributions.
///
Expand Down Expand Up @@ -2053,6 +2066,19 @@ pub struct PipInstallArgs {
#[arg(long, alias = "exclude", env = EnvVars::UV_EXCLUDE, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub excludes: Vec<Maybe<PathBuf>>,

/// Exclude the given packages from resolution.
///
/// When a package is excluded, it will be omitted from the dependency list entirely and its own
/// dependencies will be ignored during the resolution phase.
///
/// May be provided multiple times or multiple values can be provided separated by commas.
#[arg(
long = "exclude-packages",
alias = "exclude-package",
value_delimiter = ','
)]
pub exclude_packages: Vec<PackageName>,

/// Constrain build dependencies using the given requirements files when building source
/// distributions.
///
Expand Down Expand Up @@ -5193,6 +5219,19 @@ pub struct ToolInstallArgs {
#[arg(long, alias = "exclude", env = EnvVars::UV_EXCLUDE, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub excludes: Vec<Maybe<PathBuf>>,

/// Exclude the given packages from resolution.
///
/// When a package is excluded, it will be omitted from the dependency list entirely and its own
/// dependencies will be ignored during the resolution phase.
///
/// May be provided multiple times or multiple values can be provided separated by commas.
#[arg(
long = "exclude-packages",
alias = "exclude-package",
value_delimiter = ','
)]
pub exclude_packages: Vec<PackageName>,

/// Constrain build dependencies using the given requirements files when building source
/// distributions.
///
Expand Down
24 changes: 21 additions & 3 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,17 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
.into_iter()
.map(RequirementsSource::from_overrides_txt)
.collect::<Result<Vec<_>, _>>()?;
let excludes = args
let mut excludes = args
.excludes
.into_iter()
.map(RequirementsSource::from_requirements_txt)
.collect::<Result<Vec<_>, _>>()?;
excludes.extend(
args.exclude_packages
.into_iter()
.map(|package| RequirementsSource::from_package_argument(package.as_ref()))
.collect::<Result<Vec<_>, _>>()?,
);
let build_constraints = args
.build_constraints
.into_iter()
Expand Down Expand Up @@ -765,11 +771,17 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
.into_iter()
.map(RequirementsSource::from_overrides_txt)
.collect::<Result<Vec<_>, _>>()?;
let excludes = args
let mut excludes = args
.excludes
.into_iter()
.map(RequirementsSource::from_requirements_txt)
.collect::<Result<Vec<_>, _>>()?;
excludes.extend(
args.exclude_packages
.into_iter()
.map(|package| RequirementsSource::from_package_argument(package.as_ref()))
.collect::<Result<Vec<_>, _>>()?,
);
let build_constraints = args
.build_constraints
.into_iter()
Expand Down Expand Up @@ -1399,11 +1411,17 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
.into_iter()
.map(RequirementsSource::from_overrides_txt)
.collect::<Result<Vec<_>, _>>()?;
let excludes = args
let mut excludes = args
.excludes
.into_iter()
.map(RequirementsSource::from_requirements_txt)
.collect::<Result<Vec<_>, _>>()?;
excludes.extend(
args.exclude_packages
.into_iter()
.map(|package| RequirementsSource::from_package_argument(package.as_ref()))
.collect::<Result<Vec<_>, _>>()?,
);
let build_constraints = args
.build_constraints
.into_iter()
Expand Down
9 changes: 9 additions & 0 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ pub(crate) struct ToolInstallSettings {
pub(crate) constraints: Vec<PathBuf>,
pub(crate) overrides: Vec<PathBuf>,
pub(crate) excludes: Vec<PathBuf>,
pub(crate) exclude_packages: Vec<PackageName>,
pub(crate) build_constraints: Vec<PathBuf>,
pub(crate) python: Option<String>,
pub(crate) python_platform: Option<TargetTriple>,
Expand Down Expand Up @@ -714,6 +715,7 @@ impl ToolInstallSettings {
constraints,
overrides,
excludes,
exclude_packages,
build_constraints,
installer,
force,
Expand Down Expand Up @@ -770,6 +772,7 @@ impl ToolInstallSettings {
.into_iter()
.filter_map(Maybe::into_option)
.collect(),
exclude_packages,
build_constraints: build_constraints
.into_iter()
.filter_map(Maybe::into_option)
Expand Down Expand Up @@ -2190,6 +2193,7 @@ pub(crate) struct PipCompileSettings {
pub(crate) constraints: Vec<PathBuf>,
pub(crate) overrides: Vec<PathBuf>,
pub(crate) excludes: Vec<PathBuf>,
pub(crate) exclude_packages: Vec<PackageName>,
pub(crate) build_constraints: Vec<PathBuf>,
pub(crate) constraints_from_workspace: Vec<Requirement>,
pub(crate) overrides_from_workspace: Vec<Requirement>,
Expand All @@ -2212,6 +2216,7 @@ impl PipCompileSettings {
constraints,
overrides,
excludes,
exclude_packages,
extra,
all_extras,
no_all_extras,
Expand Down Expand Up @@ -2337,6 +2342,7 @@ impl PipCompileSettings {
.into_iter()
.filter_map(Maybe::into_option)
.collect(),
exclude_packages,
constraints_from_workspace,
overrides_from_workspace,
excludes_from_workspace,
Expand Down Expand Up @@ -2505,6 +2511,7 @@ pub(crate) struct PipInstallSettings {
pub(crate) constraints: Vec<PathBuf>,
pub(crate) overrides: Vec<PathBuf>,
pub(crate) excludes: Vec<PathBuf>,
pub(crate) exclude_packages: Vec<PackageName>,
pub(crate) build_constraints: Vec<PathBuf>,
pub(crate) dry_run: DryRun,
pub(crate) constraints_from_workspace: Vec<Requirement>,
Expand All @@ -2530,6 +2537,7 @@ impl PipInstallSettings {
constraints,
overrides,
excludes,
exclude_packages,
build_constraints,
extra,
all_extras,
Expand Down Expand Up @@ -2632,6 +2640,7 @@ impl PipInstallSettings {
.into_iter()
.filter_map(Maybe::into_option)
.collect(),
exclude_packages,
build_constraints: build_constraints
.into_iter()
.filter_map(Maybe::into_option)
Expand Down
30 changes: 30 additions & 0 deletions crates/uv/tests/it/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,36 @@ fn empty_requirements_txt() -> Result<()> {
Ok(())
}

#[test]
fn install_with_exclude_packages() {
let context = TestContext::new("3.12");

uv_snapshot!(context.pip_install()
.arg("flask")
.arg("--exclude-packages")
.arg("werkzeug,itsdangerous")
.arg("--strict"), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 5 packages in [TIME]
Prepared 5 packages in [TIME]
Installed 5 packages in [TIME]
+ blinker==1.7.0
+ click==8.1.7
+ flask==3.0.2
+ jinja2==3.1.3
+ markupsafe==2.1.5
warning: The package `flask` requires `werkzeug>=3.0.0`, but it's not installed
warning: The package `flask` requires `itsdangerous>=2.1.2`, but it's not installed
"###);

context.assert_not_installed("werkzeug");
context.assert_not_installed("itsdangerous");
}

#[test]
fn missing_pyproject_toml() {
let context = TestContext::new("3.12");
Expand Down
Loading
Loading