Skip to content

Commit

Permalink
Add compatibility arguments for pip list (#3055)
Browse files Browse the repository at this point in the history
Hello! This is my first PR so do not hesitate to let me know if anything
should be done differently 馃檶馃徑

## Summary

This PR starts adding useful error messages and warnings when people
pass redundant or unsupported arguments to `pip list`.

For now, I've just covered `pip list --outdated`, which is currently
unsupported.

Closes #2948
  • Loading branch information
amv213 committed Apr 16, 2024
1 parent 52472ce commit 193704f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
3 changes: 3 additions & 0 deletions crates/uv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,9 @@ pub(crate) struct PipListArgs {
/// should be used with caution.
#[clap(long, env = "UV_SYSTEM_PYTHON", group = "discovery")]
pub(crate) system: bool,

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

#[derive(Args)]
Expand Down
25 changes: 25 additions & 0 deletions crates/uv/src/compat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,31 @@ impl CompatArgs for PipCompileCompatArgs {
}
}

/// Arguments for `pip list` compatibility.
///
/// These represent a subset of the `pip list` interface that uv supports by default.
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub(crate) struct PipListCompatArgs {
#[clap(long, hide = true)]
outdated: bool,
}

impl CompatArgs for crate::compat::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.outdated {
return Err(anyhow!("pip list's `--outdated` is unsupported."));
}

Ok(())
}
}

/// Arguments for `pip-sync` compatibility.
///
/// These represent a subset of the `pip-sync` interface that uv supports by default.
Expand Down
26 changes: 15 additions & 11 deletions crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,17 +454,21 @@ async fn run() -> Result<ExitStatus> {
),
Commands::Pip(PipNamespace {
command: PipCommand::List(args),
}) => commands::pip_list(
args.editable,
args.exclude_editable,
&args.exclude,
&args.format,
args.strict,
args.python.as_deref(),
args.system,
&cache,
printer,
),
}) => {
args.compat_args.validate()?;

commands::pip_list(
args.editable,
args.exclude_editable,
&args.exclude,
&args.format,
args.strict,
args.python.as_deref(),
args.system,
&cache,
printer,
)
}
Commands::Pip(PipNamespace {
command: PipCommand::Show(args),
}) => commands::pip_show(
Expand Down

0 comments on commit 193704f

Please sign in to comment.