Skip to content

Commit

Permalink
Add --disable-pip-version-check to compatibility arguments (#4672)
Browse files Browse the repository at this point in the history
## Summary

Closes #4590.
  • Loading branch information
charliermarsh authored Jun 30, 2024
1 parent d550127 commit 8ea47ab
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
46 changes: 43 additions & 3 deletions crates/uv-cli/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,26 @@ impl CompatArgs for PipCompileCompatArgs {
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub struct PipListCompatArgs {
#[clap(long, hide = true)]
disable_pip_version_check: bool,

#[clap(long, hide = true)]
outdated: bool,
}

impl CompatArgs for crate::compat::PipListCompatArgs {
impl CompatArgs for PipListCompatArgs {
/// Validate the arguments passed for `pip list` compatibility.
///
/// This method will warn when an argument is passed that has no effect but matches uv's
/// behavior. If an argument is passed that does _not_ match uv's behavior (e.g.,
/// `--outdated`), this method will return an error.
fn validate(&self) -> Result<()> {
if self.disable_pip_version_check {
warn_user!("pip's `--disable-pip-version-check` has no effect.");
}

if self.outdated {
return Err(anyhow!("pip list's `--outdated` is unsupported."));
return Err(anyhow!("pip's `--outdated` is unsupported."));
}

Ok(())
Expand Down Expand Up @@ -359,6 +366,9 @@ impl CompatArgs for VenvCompatArgs {
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub struct PipInstallCompatArgs {
#[clap(long, hide = true)]
disable_pip_version_check: bool,

#[clap(long, hide = false)]
user: bool,
}
Expand All @@ -370,11 +380,41 @@ impl CompatArgs for PipInstallCompatArgs {
/// behavior. If an argument is passed that does _not_ match uv's behavior, this method will
/// return an error.
fn validate(&self) -> Result<()> {
if self.disable_pip_version_check {
warn_user!("pip's `--disable-pip-version-check` has no effect.");
}

if self.user {
return Err(anyhow!(
"pip install's `--user` is unsupported (use a virtual environment instead)."
"pip's `--user` is unsupported (use a virtual environment instead)."
));
}

Ok(())
}
}

/// Arguments for generic `pip` command compatibility.
///
/// These represent a subset of the `pip` interface that exists on all commands.
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub struct PipGlobalCompatArgs {
#[clap(long, hide = true)]
disable_pip_version_check: bool,
}

impl CompatArgs for PipGlobalCompatArgs {
/// Validate the arguments passed for `pip` compatibility.
///
/// This method will warn when an argument is passed that has no effect but matches uv's
/// behavior. If an argument is passed that does _not_ match uv's behavior, this method will
/// return an error.
fn validate(&self) -> Result<()> {
if self.disable_pip_version_check {
warn_user!("pip's `--disable-pip-version-check` has no effect.");
}

Ok(())
}
}
12 changes: 12 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,9 @@ pub struct PipUninstallArgs {
/// Uninstall packages from the specified `--prefix` directory.
#[arg(long, conflicts_with = "target")]
pub prefix: Option<PathBuf>,

#[command(flatten)]
pub compat_args: compat::PipGlobalCompatArgs,
}

#[derive(Args)]
Expand Down Expand Up @@ -1255,6 +1258,9 @@ pub struct PipFreezeArgs {

#[arg(long, overrides_with("system"), hide = true)]
pub no_system: bool,

#[command(flatten)]
pub compat_args: compat::PipGlobalCompatArgs,
}

#[derive(Args)]
Expand Down Expand Up @@ -1407,6 +1413,9 @@ pub struct PipShowArgs {

#[arg(long, overrides_with("system"), hide = true)]
pub no_system: bool,

#[command(flatten)]
pub compat_args: compat::PipGlobalCompatArgs,
}

#[derive(Args)]
Expand Down Expand Up @@ -1468,6 +1477,9 @@ pub struct PipTreeArgs {

#[arg(long, overrides_with("system"))]
pub no_system: bool,

#[command(flatten)]
pub compat_args: compat::PipGlobalCompatArgs,
}

#[derive(Args)]
Expand Down
4 changes: 4 additions & 0 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ impl PipUninstallSettings {
no_break_system_packages,
target,
prefix,
compat_args: _,
} = args;

Self {
Expand Down Expand Up @@ -960,6 +961,7 @@ impl PipFreezeSettings {
python,
system,
no_system,
compat_args: _,
} = args;

Self {
Expand Down Expand Up @@ -1040,6 +1042,7 @@ impl PipShowSettings {
python,
system,
no_system,
compat_args: _,
} = args;

Self {
Expand Down Expand Up @@ -1080,6 +1083,7 @@ impl PipTreeSettings {
python,
system,
no_system,
compat_args: _,
} = args;

Self {
Expand Down

0 comments on commit 8ea47ab

Please sign in to comment.