Skip to content

Commit

Permalink
Add --disable-pip-version-check to compatibility arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jun 30, 2024
1 parent ac87fd4 commit 25a7903
Show file tree
Hide file tree
Showing 2 changed files with 55 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

0 comments on commit 25a7903

Please sign in to comment.