Skip to content

Commit

Permalink
Add negation flags to the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Apr 17, 2024
1 parent 17b6acb commit d1273f2
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 80 deletions.
109 changes: 79 additions & 30 deletions crates/uv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@ pub(crate) struct Cli {
pub(crate) cache_args: CacheArgs,

/// The path to a `pyproject.toml` or `uv.toml` file to use for configuration.
#[arg(long, short, env = "UV_CONFIG_FILE")]
#[clap(long, short, env = "UV_CONFIG_FILE")]
pub(crate) config_file: Option<PathBuf>,
}

#[derive(Parser, Debug, Clone)]
pub(crate) struct GlobalArgs {
/// Do not print any output.
#[arg(global = true, long, short, conflicts_with = "verbose")]
#[clap(global = true, long, short, conflicts_with = "verbose")]
pub(crate) quiet: bool,

/// Use verbose output.
///
/// You can configure fine-grained logging using the `RUST_LOG` environment variable.
/// (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)
#[arg(global = true, action = clap::ArgAction::Count, long, short, conflicts_with = "quiet")]
#[clap(global = true, action = clap::ArgAction::Count, long, short, conflicts_with = "quiet")]
pub(crate) verbose: u8,

/// Disable colors; provided for compatibility with `pip`.
#[arg(global = true, long, hide = true, conflicts_with = "color")]
#[clap(global = true, long, hide = true, conflicts_with = "color")]
pub(crate) no_color: bool,

/// Control colors in output.
#[arg(
#[clap(
global = true,
long,
value_enum,
Expand All @@ -72,7 +72,7 @@ pub(crate) struct GlobalArgs {
/// However, in some cases, you may want to use the platform's native certificate store,
/// especially if you're relying on a corporate trust root (e.g., for a mandatory proxy) that's
/// included in your system's certificate store.
#[arg(global = true, long, env = "UV_NATIVE_TLS")]
#[clap(global = true, long, env = "UV_NATIVE_TLS")]
pub(crate) native_tls: bool,
}

Expand Down Expand Up @@ -117,7 +117,7 @@ pub(crate) enum Commands {
Clean(CleanArgs),
/// Display uv's version
Version {
#[arg(long, value_enum, default_value = "text")]
#[clap(long, value_enum, default_value = "text")]
output_format: VersionFormat,
},
/// Generate shell completion
Expand Down Expand Up @@ -256,11 +256,17 @@ pub(crate) struct PipCompileArgs {
#[clap(long, conflicts_with = "extra")]
pub(crate) all_extras: bool,

#[clap(long, overrides_with("all_extras"), hide = true)]
pub(crate) no_all_extras: bool,

/// Ignore package dependencies, instead only add those packages explicitly listed
/// on the command line to the resulting the requirements file.
#[clap(long)]
pub(crate) no_deps: bool,

#[clap(long, overrides_with("no_deps"), hide = true)]
pub(crate) deps: bool,

#[clap(long, value_enum, default_value = "highest", env = "UV_RESOLUTION")]
pub(crate) resolution: Option<ResolutionMode>,

Expand All @@ -284,17 +290,26 @@ pub(crate) struct PipCompileArgs {
/// By default, `uv` strips extras, as any packages pulled in by the extras are already included
/// as dependencies in the output file directly. Further, output files generated with
/// `--no-strip-extras` cannot be used as constraints files in `install` and `sync` invocations.
#[clap(long)]
#[clap(long, overrides_with("strip_extras"))]
pub(crate) no_strip_extras: bool,

#[clap(long, overrides_with("no_strip_extras"), hide = true)]
pub(crate) strip_extras: bool,

/// Exclude comment annotations indicating the source of each package.
#[clap(long)]
#[clap(long, overrides_with("annotate"))]
pub(crate) no_annotate: bool,

#[clap(long, overrides_with("no_annotate"), hide = true)]
pub(crate) annotate: bool,

/// Exclude the comment header at the top of the generated output file.
#[clap(long)]
#[clap(long, overrides_with("header"))]
pub(crate) no_header: bool,

#[clap(long, overrides_with("no_header"), hide = true)]
pub(crate) header: bool,

/// Choose the style of the annotation comments, which indicate the source of each package.
#[clap(long, default_value = "split", value_enum)]
pub(crate) annotation_style: Option<AnnotationStyle>,
Expand All @@ -304,14 +319,18 @@ pub(crate) struct PipCompileArgs {
pub(crate) custom_compile_command: Option<String>,

/// Run offline, i.e., without accessing the network.
#[arg(
#[clap(
global = true,
long,
conflicts_with = "refresh",
conflicts_with = "refresh_package"
conflicts_with = "refresh_package",
overrides_with("no_offline")
)]
pub(crate) offline: bool,

#[clap(long, overrides_with("offline"), hide = true)]
pub(crate) no_offline: bool,

/// Refresh all cached data.
#[clap(long)]
pub(crate) refresh: bool,
Expand Down Expand Up @@ -402,30 +421,42 @@ pub(crate) struct PipCompileArgs {
pub(crate) upgrade_package: Option<Vec<PackageName>>,

/// Include distribution hashes in the output file.
#[clap(long)]
#[clap(long, overrides_with("no_generate_hashes"))]
pub(crate) generate_hashes: bool,

#[clap(long, overrides_with("generate_hashes"), hide = true)]
pub(crate) no_generate_hashes: bool,

/// Use legacy `setuptools` behavior when building source distributions without a
/// `pyproject.toml`.
#[clap(long)]
#[clap(long, overrides_with("no_legacy_setup_py"))]
pub(crate) legacy_setup_py: bool,

#[clap(long, overrides_with("legacy_setup_py"), hide = true)]
pub(crate) no_legacy_setup_py: bool,

/// Disable isolation when building source distributions.
///
/// Assumes that build dependencies specified by PEP 518 are already installed.
#[clap(long)]
#[clap(long, overrides_with("build_isolation"))]
pub(crate) no_build_isolation: bool,

#[clap(long, overrides_with("no_build_isolation"), hide = true)]
pub(crate) build_isolation: bool,

/// Don't build source distributions.
///
/// When enabled, resolving will not run arbitrary code. The cached wheels of already-built
/// source distributions will be reused, but operations that require building distributions will
/// exit with an error.
///
/// Alias for `--only-binary :all:`.
#[clap(long, conflicts_with = "only_binary")]
#[clap(long, conflicts_with = "only_binary", overrides_with = "build")]
pub(crate) no_build: bool,

#[clap(long, overrides_with("no_build"), hide = true)]
pub(crate) build: bool,

/// Only use pre-built wheels; don't build source distributions.
///
/// When enabled, resolving will not run code from the given packages. The cached wheels of already-built
Expand All @@ -446,14 +477,14 @@ pub(crate) struct PipCompileArgs {
///
/// If a patch version is omitted, the most recent known patch version for that minor version
/// is assumed. For example, `3.7` is mapped to `3.7.17`.
#[arg(long, short)]
#[clap(long, short)]
pub(crate) python_version: Option<PythonVersion>,

/// Limit candidate packages to those that were uploaded prior to the given date.
///
/// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and UTC dates in the same
/// format (e.g., `2006-12-02`).
#[arg(long)]
#[clap(long)]
pub(crate) exclude_newer: Option<ExcludeNewer>,

/// Specify a package to omit from the output resolution. Its dependencies will still be
Expand All @@ -462,27 +493,39 @@ pub(crate) struct PipCompileArgs {
pub(crate) no_emit_package: Option<Vec<PackageName>>,

/// Include `--index-url` and `--extra-index-url` entries in the generated output file.
#[clap(long)]
#[clap(long, overrides_with("no_emit_index_url"))]
pub(crate) emit_index_url: bool,

#[clap(long, overrides_with("emit_index_url"), hide = true)]
pub(crate) no_emit_index_url: bool,

/// Include `--find-links` entries in the generated output file.
#[clap(long)]
#[clap(long, overrides_with("no_emit_find_links"))]
pub(crate) emit_find_links: bool,

#[clap(long, overrides_with("emit_find_links"), hide = true)]
pub(crate) no_emit_find_links: bool,

/// Whether to emit a marker string indicating when it is known that the
/// resulting set of pinned dependencies is valid.
///
/// The pinned dependencies may be valid even when the marker expression is
/// false, but when the expression is true, the requirements are known to
/// be correct.
#[clap(long, hide = true)]
#[clap(long, overrides_with("no_emit_marker_expression"), hide = true)]
pub(crate) emit_marker_expression: bool,

#[clap(long, overrides_with("emit_marker_expression"), hide = true)]
pub(crate) no_emit_marker_expression: bool,

/// Include comment annotations indicating the index used to resolve each package (e.g.,
/// `# from https://pypi.org/simple`).
#[clap(long)]
#[clap(long, overrides_with("no_emit_index_annotation"))]
pub(crate) emit_index_annotation: bool,

#[clap(long, overrides_with("emit_index_annotation"), hide = true)]
pub(crate) no_emit_index_annotation: bool,

#[command(flatten)]
pub(crate) compat_args: compat::PipCompileCompatArgs,
}
Expand All @@ -503,7 +546,7 @@ pub(crate) struct PipSyncArgs {
pub(crate) reinstall_package: Vec<PackageName>,

/// Run offline, i.e., without accessing the network.
#[arg(
#[clap(
global = true,
long,
conflicts_with = "refresh",
Expand Down Expand Up @@ -752,9 +795,12 @@ pub(crate) struct PipInstallArgs {
pub(crate) extra: Option<Vec<ExtraName>>,

/// Include all optional dependencies.
#[clap(long, conflicts_with = "extra")]
#[clap(long, conflicts_with = "extra", overrides_with = "no_all_extras")]
pub(crate) all_extras: bool,

#[clap(long, overrides_with("all_extras"), hide = true)]
pub(crate) no_all_extras: bool,

/// Allow package upgrades.
#[clap(long, short = 'U')]
pub(crate) upgrade: bool,
Expand All @@ -772,7 +818,7 @@ pub(crate) struct PipInstallArgs {
pub(crate) reinstall_package: Option<Vec<PackageName>>,

/// Run offline, i.e., without accessing the network.
#[arg(
#[clap(
global = true,
long,
conflicts_with = "refresh",
Expand All @@ -790,9 +836,12 @@ pub(crate) struct PipInstallArgs {

/// Ignore package dependencies, instead only installing those packages explicitly listed
/// on the command line or in the requirements files.
#[clap(long)]
#[clap(long, overrides_with("deps"))]
pub(crate) no_deps: bool,

#[clap(long, overrides_with("no_deps"), hide = true)]
pub(crate) deps: bool,

/// The method to use when installing packages from the global cache.
///
/// Defaults to `clone` (also known as Copy-on-Write) on macOS, and `hardlink` on Linux and
Expand Down Expand Up @@ -997,7 +1046,7 @@ pub(crate) struct PipInstallArgs {
///
/// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and UTC dates in the same
/// format (e.g., `2006-12-02`).
#[arg(long)]
#[clap(long)]
pub(crate) exclude_newer: Option<ExcludeNewer>,

/// Perform a dry run, i.e., don't actually install anything but resolve the dependencies and
Expand Down Expand Up @@ -1066,7 +1115,7 @@ pub(crate) struct PipUninstallArgs {
pub(crate) break_system_packages: bool,

/// Run offline, i.e., without accessing the network.
#[arg(global = true, long)]
#[clap(global = true, long)]
pub(crate) offline: bool,
}

Expand Down Expand Up @@ -1352,14 +1401,14 @@ pub(crate) struct VenvArgs {
pub(crate) keyring_provider: Option<KeyringProviderType>,

/// Run offline, i.e., without accessing the network.
#[arg(global = true, long)]
#[clap(global = true, long)]
pub(crate) offline: bool,

/// Limit candidate packages to those that were uploaded prior to the given date.
///
/// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and UTC dates in the same
/// format (e.g., `2006-12-02`).
#[arg(long)]
#[clap(long)]
pub(crate) exclude_newer: Option<ExcludeNewer>,

#[command(flatten)]
Expand Down
36 changes: 0 additions & 36 deletions crates/uv/src/compat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ pub(crate) struct PipCompileCompatArgs {
#[clap(long, hide = true)]
no_reuse_hashes: bool,

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

#[clap(long, hide = true)]
resolver: Option<Resolver>,

Expand Down Expand Up @@ -57,21 +54,12 @@ pub(crate) struct PipCompileCompatArgs {
#[clap(long, hide = true)]
no_config: bool,

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

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

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

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

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

#[clap(long, hide = true)]
pip_args: Option<String>,
}
Expand Down Expand Up @@ -105,12 +93,6 @@ impl CompatArgs for PipCompileCompatArgs {
);
}

if self.build_isolation {
warn_user!(
"pip-compile's `--build-isolation` has no effect (uv always uses build isolation)."
);
}

if let Some(resolver) = self.resolver {
match resolver {
Resolver::Backtracking => {
Expand Down Expand Up @@ -168,18 +150,6 @@ impl CompatArgs for PipCompileCompatArgs {
);
}

if self.no_emit_index_url {
warn_user!(
"pip-compile's `--no-emit-index-url` has no effect (uv excludes index URLs by default)."
);
}

if self.no_emit_find_links {
warn_user!(
"pip-compile's `--no-emit-find-links` has no effect (uv excludes `--find-links` URLs by default)."
);
}

if self.emit_options {
return Err(anyhow!(
"pip-compile's `--emit-options` is unsupported (uv never emits options)."
Expand All @@ -190,12 +160,6 @@ impl CompatArgs for PipCompileCompatArgs {
warn_user!("pip-compile's `--no-emit-options` has no effect (uv never emits options).");
}

if self.strip_extras {
warn_user!(
"pip-compile's `--strip-extras` has no effect (uv strips extras by default)."
);
}

if self.pip_args.is_some() {
return Err(anyhow!(
"pip-compile's `--pip-args` is unsupported (try passing arguments to uv directly)."
Expand Down
Loading

0 comments on commit d1273f2

Please sign in to comment.