Skip to content

Commit

Permalink
Accept either singular or plural for CLI constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Nov 20, 2024
1 parent 110c38e commit ea9a801
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 89 deletions.
46 changes: 23 additions & 23 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,8 @@ pub struct PipCompileArgs {
/// trigger the installation of that package.
///
/// This is equivalent to pip's `--constraint` option.
#[arg(long, short, env = EnvVars::UV_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub constraint: Vec<Maybe<PathBuf>>,
#[arg(long, short, alias = "constraint", env = EnvVars::UV_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub constraints: Vec<Maybe<PathBuf>>,

/// Override versions using the given requirements files.
///
Expand All @@ -954,17 +954,17 @@ pub struct PipCompileArgs {
/// While constraints are _additive_, in that they're combined with the requirements of the
/// constituent packages, overrides are _absolute_, in that they completely replace the
/// requirements of the constituent packages.
#[arg(long, env = EnvVars::UV_OVERRIDE, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub r#override: Vec<Maybe<PathBuf>>,
#[arg(long, alias = "override", env = EnvVars::UV_OVERRIDE, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub overrides: Vec<Maybe<PathBuf>>,

/// Constrain build dependencies using the given requirements files when building source
/// distributions.
///
/// Constraints files are `requirements.txt`-like files that only control the _version_ of a
/// requirement that's installed. However, including a package in a constraints file will _not_
/// trigger the installation of that package.
#[arg(long, short, env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub build_constraint: Vec<Maybe<PathBuf>>,
#[arg(long, short, alias = "build-constraint", env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub build_constraints: Vec<Maybe<PathBuf>>,

/// Include optional dependencies from the specified extra name; may be provided more than once.
///
Expand Down Expand Up @@ -1243,17 +1243,17 @@ pub struct PipSyncArgs {
/// trigger the installation of that package.
///
/// This is equivalent to pip's `--constraint` option.
#[arg(long, short, env = EnvVars::UV_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub constraint: Vec<Maybe<PathBuf>>,
#[arg(long, short, alias = "constraint", env = EnvVars::UV_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub constraints: Vec<Maybe<PathBuf>>,

/// Constrain build dependencies using the given requirements files when building source
/// distributions.
///
/// Constraints files are `requirements.txt`-like files that only control the _version_ of a
/// requirement that's installed. However, including a package in a constraints file will _not_
/// trigger the installation of that package.
#[arg(long, short, env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub build_constraint: Vec<Maybe<PathBuf>>,
#[arg(long, short, alias = "build-constraint", env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub build_constraints: Vec<Maybe<PathBuf>>,

#[command(flatten)]
pub installer: InstallerArgs,
Expand Down Expand Up @@ -1480,8 +1480,8 @@ pub struct PipInstallArgs {
/// extract the requirements for the relevant project.
///
/// If `-` is provided, then requirements will be read from stdin.
#[arg(long, short, group = "sources", value_parser = parse_file_path)]
pub requirement: Vec<PathBuf>,
#[arg(long, short, alias = "requirement", group = "sources", value_parser = parse_file_path)]
pub requirements: Vec<PathBuf>,

/// Install the editable package based on the provided local file path.
#[arg(long, short, group = "sources")]
Expand All @@ -1494,8 +1494,8 @@ pub struct PipInstallArgs {
/// trigger the installation of that package.
///
/// This is equivalent to pip's `--constraint` option.
#[arg(long, short, env = EnvVars::UV_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub constraint: Vec<Maybe<PathBuf>>,
#[arg(long, short, alias = "constraint", env = EnvVars::UV_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub constraints: Vec<Maybe<PathBuf>>,

/// Override versions using the given requirements files.
///
Expand All @@ -1506,17 +1506,17 @@ pub struct PipInstallArgs {
/// While constraints are _additive_, in that they're combined with the requirements of the
/// constituent packages, overrides are _absolute_, in that they completely replace the
/// requirements of the constituent packages.
#[arg(long, env = EnvVars::UV_OVERRIDE, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub r#override: Vec<Maybe<PathBuf>>,
#[arg(long, alias = "override", env = EnvVars::UV_OVERRIDE, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub overrides: Vec<Maybe<PathBuf>>,

/// Constrain build dependencies using the given requirements files when building source
/// distributions.
///
/// Constraints files are `requirements.txt`-like files that only control the _version_ of a
/// requirement that's installed. However, including a package in a constraints file will _not_
/// trigger the installation of that package.
#[arg(long, short, env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub build_constraint: Vec<Maybe<PathBuf>>,
#[arg(long, short, alias = "build-constraint", env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub build_constraints: Vec<Maybe<PathBuf>>,

/// Include optional dependencies from the specified extra name; may be provided more than once.
///
Expand Down Expand Up @@ -1764,8 +1764,8 @@ pub struct PipUninstallArgs {
pub package: Vec<String>,

/// Uninstall all packages listed in the given requirements files.
#[arg(long, short, group = "sources", value_parser = parse_file_path)]
pub requirement: Vec<PathBuf>,
#[arg(long, short, alias = "requirement", group = "sources", value_parser = parse_file_path)]
pub requirements: Vec<PathBuf>,

/// The Python interpreter from which packages should be uninstalled.
///
Expand Down Expand Up @@ -2180,8 +2180,8 @@ pub struct BuildArgs {
/// Constraints files are `requirements.txt`-like files that only control the _version_ of a
/// build dependency that's installed. However, including a package in a constraints file will
/// _not_ trigger the inclusion of that package on its own.
#[arg(long, short, env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub build_constraint: Vec<Maybe<PathBuf>>,
#[arg(long, short, alias = "build-constraint", env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub build_constraints: Vec<Maybe<PathBuf>>,

/// Require a matching hash for each requirement.
///
Expand Down Expand Up @@ -3047,7 +3047,7 @@ pub struct AddArgs {
pub packages: Vec<String>,

/// Add all packages listed in the given `requirements.txt` files.
#[arg(long, short, group = "sources", value_parser = parse_file_path)]
#[arg(long, short, alias = "requirement", group = "sources", value_parser = parse_file_path)]
pub requirements: Vec<PathBuf>,

/// Add the requirements to the development dependency group.
Expand Down
24 changes: 12 additions & 12 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,17 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
.map(RequirementsSource::from_requirements_file)
.collect::<Vec<_>>();
let constraints = args
.constraint
.constraints
.into_iter()
.map(RequirementsSource::from_constraints_txt)
.collect::<Vec<_>>();
let overrides = args
.r#override
.overrides
.into_iter()
.map(RequirementsSource::from_overrides_txt)
.collect::<Vec<_>>();
let build_constraints = args
.build_constraint
.build_constraints
.into_iter()
.map(RequirementsSource::from_constraints_txt)
.collect::<Vec<_>>();
Expand Down Expand Up @@ -402,12 +402,12 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
.map(RequirementsSource::from_requirements_file)
.collect::<Vec<_>>();
let constraints = args
.constraint
.constraints
.into_iter()
.map(RequirementsSource::from_constraints_txt)
.collect::<Vec<_>>();
let build_constraints = args
.build_constraint
.build_constraints
.into_iter()
.map(RequirementsSource::from_constraints_txt)
.collect::<Vec<_>>();
Expand Down Expand Up @@ -469,25 +469,25 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
.package
.into_iter()
.map(RequirementsSource::from_package)
.chain(args.editable.into_iter().map(RequirementsSource::Editable))
.chain(args.editables.into_iter().map(RequirementsSource::Editable))
.chain(
args.requirement
args.requirements
.into_iter()
.map(RequirementsSource::from_requirements_file),
)
.collect::<Vec<_>>();
let constraints = args
.constraint
.constraints
.into_iter()
.map(RequirementsSource::from_constraints_txt)
.collect::<Vec<_>>();
let overrides = args
.r#override
.overrides
.into_iter()
.map(RequirementsSource::from_overrides_txt)
.collect::<Vec<_>>();
let build_constraints = args
.build_constraint
.build_constraints
.into_iter()
.map(RequirementsSource::from_overrides_txt)
.collect::<Vec<_>>();
Expand Down Expand Up @@ -552,7 +552,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
.into_iter()
.map(RequirementsSource::from_package)
.chain(
args.requirement
args.requirements
.into_iter()
.map(RequirementsSource::from_requirements_txt),
)
Expand Down Expand Up @@ -717,7 +717,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {

// Resolve the build constraints.
let build_constraints = args
.build_constraint
.build_constraints
.into_iter()
.map(RequirementsSource::from_constraints_txt)
.collect::<Vec<_>>();
Expand Down
Loading

0 comments on commit ea9a801

Please sign in to comment.