Add --disable-pip-version-check to compatibility arguments (#4672)

## Summary

Closes https://github.com/astral-sh/uv/issues/4590.
This commit is contained in:
Charlie Marsh 2024-06-30 19:43:23 -04:00 committed by GitHub
parent d5501274d8
commit 8ea47ab45f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 59 additions and 3 deletions

View file

@ -176,19 +176,26 @@ impl CompatArgs for PipCompileCompatArgs {
#[derive(Args)] #[derive(Args)]
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
pub struct PipListCompatArgs { pub struct PipListCompatArgs {
#[clap(long, hide = true)]
disable_pip_version_check: bool,
#[clap(long, hide = true)] #[clap(long, hide = true)]
outdated: bool, outdated: bool,
} }
impl CompatArgs for crate::compat::PipListCompatArgs { impl CompatArgs for PipListCompatArgs {
/// Validate the arguments passed for `pip list` compatibility. /// 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 /// 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., /// behavior. If an argument is passed that does _not_ match uv's behavior (e.g.,
/// `--outdated`), this method will return an error. /// `--outdated`), this method will return an error.
fn validate(&self) -> Result<()> { fn validate(&self) -> Result<()> {
if self.disable_pip_version_check {
warn_user!("pip's `--disable-pip-version-check` has no effect.");
}
if self.outdated { if self.outdated {
return Err(anyhow!("pip list's `--outdated` is unsupported.")); return Err(anyhow!("pip's `--outdated` is unsupported."));
} }
Ok(()) Ok(())
@ -359,6 +366,9 @@ impl CompatArgs for VenvCompatArgs {
#[derive(Args)] #[derive(Args)]
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
pub struct PipInstallCompatArgs { pub struct PipInstallCompatArgs {
#[clap(long, hide = true)]
disable_pip_version_check: bool,
#[clap(long, hide = false)] #[clap(long, hide = false)]
user: bool, user: bool,
} }
@ -370,11 +380,41 @@ impl CompatArgs for PipInstallCompatArgs {
/// behavior. If an argument is passed that does _not_ match uv's behavior, this method will /// behavior. If an argument is passed that does _not_ match uv's behavior, this method will
/// return an error. /// return an error.
fn validate(&self) -> Result<()> { fn validate(&self) -> Result<()> {
if self.disable_pip_version_check {
warn_user!("pip's `--disable-pip-version-check` has no effect.");
}
if self.user { if self.user {
return Err(anyhow!( 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(()) Ok(())
} }
} }

View file

@ -1205,6 +1205,9 @@ pub struct PipUninstallArgs {
/// Uninstall packages from the specified `--prefix` directory. /// Uninstall packages from the specified `--prefix` directory.
#[arg(long, conflicts_with = "target")] #[arg(long, conflicts_with = "target")]
pub prefix: Option<PathBuf>, pub prefix: Option<PathBuf>,
#[command(flatten)]
pub compat_args: compat::PipGlobalCompatArgs,
} }
#[derive(Args)] #[derive(Args)]
@ -1255,6 +1258,9 @@ pub struct PipFreezeArgs {
#[arg(long, overrides_with("system"), hide = true)] #[arg(long, overrides_with("system"), hide = true)]
pub no_system: bool, pub no_system: bool,
#[command(flatten)]
pub compat_args: compat::PipGlobalCompatArgs,
} }
#[derive(Args)] #[derive(Args)]
@ -1407,6 +1413,9 @@ pub struct PipShowArgs {
#[arg(long, overrides_with("system"), hide = true)] #[arg(long, overrides_with("system"), hide = true)]
pub no_system: bool, pub no_system: bool,
#[command(flatten)]
pub compat_args: compat::PipGlobalCompatArgs,
} }
#[derive(Args)] #[derive(Args)]
@ -1468,6 +1477,9 @@ pub struct PipTreeArgs {
#[arg(long, overrides_with("system"))] #[arg(long, overrides_with("system"))]
pub no_system: bool, pub no_system: bool,
#[command(flatten)]
pub compat_args: compat::PipGlobalCompatArgs,
} }
#[derive(Args)] #[derive(Args)]

View file

@ -921,6 +921,7 @@ impl PipUninstallSettings {
no_break_system_packages, no_break_system_packages,
target, target,
prefix, prefix,
compat_args: _,
} = args; } = args;
Self { Self {
@ -960,6 +961,7 @@ impl PipFreezeSettings {
python, python,
system, system,
no_system, no_system,
compat_args: _,
} = args; } = args;
Self { Self {
@ -1040,6 +1042,7 @@ impl PipShowSettings {
python, python,
system, system,
no_system, no_system,
compat_args: _,
} = args; } = args;
Self { Self {
@ -1080,6 +1083,7 @@ impl PipTreeSettings {
python, python,
system, system,
no_system, no_system,
compat_args: _,
} = args; } = args;
Self { Self {