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 18, 2024
1 parent 0aaa6ba commit 24091dd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
22 changes: 11 additions & 11 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ 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)]
#[arg(long, short, alias = "constraints", env = EnvVars::UV_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub constraint: Vec<Maybe<PathBuf>>,

/// Override versions using the given requirements files.
Expand All @@ -963,7 +963,7 @@ pub struct PipCompileArgs {
/// 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)]
#[arg(long, short, alias = "build-constraints", env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub build_constraint: Vec<Maybe<PathBuf>>,

/// Include optional dependencies from the specified extra name; may be provided more than once.
Expand Down Expand Up @@ -1243,7 +1243,7 @@ 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)]
#[arg(long, short, alias = "constraints", env = EnvVars::UV_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub constraint: Vec<Maybe<PathBuf>>,

/// Constrain build dependencies using the given requirements files when building source
Expand All @@ -1252,7 +1252,7 @@ pub struct PipSyncArgs {
/// 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)]
#[arg(long, short, alias = "build-constraints", env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub build_constraint: Vec<Maybe<PathBuf>>,

#[command(flatten)]
Expand Down Expand Up @@ -1480,7 +1480,7 @@ 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)]
#[arg(long, short, alias = "requirements", group = "sources", value_parser = parse_file_path)]
pub requirement: Vec<PathBuf>,

/// Install the editable package based on the provided local file path.
Expand All @@ -1494,7 +1494,7 @@ 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)]
#[arg(long, short, alias = "constraints", env = EnvVars::UV_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub constraint: Vec<Maybe<PathBuf>>,

/// Override versions using the given requirements files.
Expand All @@ -1515,7 +1515,7 @@ pub struct PipInstallArgs {
/// 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)]
#[arg(long, short, alias = "build-constraints", env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub build_constraint: Vec<Maybe<PathBuf>>,

/// Include optional dependencies from the specified extra name; may be provided more than once.
Expand Down Expand Up @@ -1764,7 +1764,7 @@ 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)]
#[arg(long, short, alias = "requirements", group = "sources", value_parser = parse_file_path)]
pub requirement: Vec<PathBuf>,

/// The Python interpreter from which packages should be uninstalled.
Expand Down Expand Up @@ -2180,7 +2180,7 @@ 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)]
#[arg(long, short, alias = "build-constraints", env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
pub build_constraint: Vec<Maybe<PathBuf>>,

/// Require a matching hash for each requirement.
Expand Down Expand Up @@ -3047,8 +3047,8 @@ 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)]
pub requirements: Vec<PathBuf>,
#[arg(long, short, alias = "requirements", group = "sources", value_parser = parse_file_path)]
pub requirement: Vec<PathBuf>,

/// Add the requirements to the development dependency group.
///
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ async fn run_project(
.into_iter()
.map(RequirementsSource::Package)
.chain(
args.requirements
args.requirement
.into_iter()
.map(RequirementsSource::from_requirements_file),
)
Expand Down
6 changes: 3 additions & 3 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ pub(crate) struct AddSettings {
pub(crate) frozen: bool,
pub(crate) no_sync: bool,
pub(crate) packages: Vec<String>,
pub(crate) requirements: Vec<PathBuf>,
pub(crate) requirement: Vec<PathBuf>,
pub(crate) dependency_type: DependencyType,
pub(crate) editable: Option<bool>,
pub(crate) extras: Vec<ExtraName>,
Expand All @@ -980,7 +980,7 @@ impl AddSettings {
pub(crate) fn resolve(args: AddArgs, filesystem: Option<FilesystemOptions>) -> Self {
let AddArgs {
packages,
requirements,
requirement,
dev,
optional,
group,
Expand Down Expand Up @@ -1067,7 +1067,7 @@ impl AddSettings {
frozen,
no_sync,
packages,
requirements,
requirement,
dependency_type,
raw_sources,
rev,
Expand Down
12 changes: 6 additions & 6 deletions crates/uv/tests/it/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ fn add_raw_error() -> Result<()> {
----- stderr -----
error: the argument '--tag <TAG>' cannot be used with '--raw-sources'
Usage: uv add --cache-dir [CACHE_DIR] --tag <TAG> --exclude-newer <EXCLUDE_NEWER> <PACKAGES|--requirements <REQUIREMENTS>>
Usage: uv add --cache-dir [CACHE_DIR] --tag <TAG> --exclude-newer <EXCLUDE_NEWER> <PACKAGES|--requirement <REQUIREMENT>>
For more information, try '--help'.
"###);
Expand Down Expand Up @@ -3806,7 +3806,7 @@ fn add_reject_multiple_git_ref_flags() {
----- stderr -----
error: the argument '--tag <TAG>' cannot be used with '--branch <BRANCH>'
Usage: uv add --cache-dir [CACHE_DIR] --tag <TAG> --exclude-newer <EXCLUDE_NEWER> <PACKAGES|--requirements <REQUIREMENTS>>
Usage: uv add --cache-dir [CACHE_DIR] --tag <TAG> --exclude-newer <EXCLUDE_NEWER> <PACKAGES|--requirement <REQUIREMENT>>
For more information, try '--help'.
"###
Expand All @@ -3827,7 +3827,7 @@ fn add_reject_multiple_git_ref_flags() {
----- stderr -----
error: the argument '--tag <TAG>' cannot be used with '--rev <REV>'
Usage: uv add --cache-dir [CACHE_DIR] --tag <TAG> --exclude-newer <EXCLUDE_NEWER> <PACKAGES|--requirements <REQUIREMENTS>>
Usage: uv add --cache-dir [CACHE_DIR] --tag <TAG> --exclude-newer <EXCLUDE_NEWER> <PACKAGES|--requirement <REQUIREMENT>>
For more information, try '--help'.
"###
Expand All @@ -3848,7 +3848,7 @@ fn add_reject_multiple_git_ref_flags() {
----- stderr -----
error: the argument '--tag <TAG>' cannot be used multiple times
Usage: uv add [OPTIONS] <PACKAGES|--requirements <REQUIREMENTS>>
Usage: uv add [OPTIONS] <PACKAGES|--requirement <REQUIREMENT>>
For more information, try '--help'.
"###
Expand Down Expand Up @@ -4627,9 +4627,9 @@ fn add_requirements_file() -> Result<()> {
----- stderr -----
error: the following required arguments were not provided:
<PACKAGES|--requirements <REQUIREMENTS>>
<PACKAGES|--requirement <REQUIREMENT>>
Usage: uv add --cache-dir [CACHE_DIR] --exclude-newer <EXCLUDE_NEWER> <PACKAGES|--requirements <REQUIREMENTS>>
Usage: uv add --cache-dir [CACHE_DIR] --exclude-newer <EXCLUDE_NEWER> <PACKAGES|--requirement <REQUIREMENT>>
For more information, try '--help'.
"###);
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ uv will search for a project in the current directory or any parent directory. I
<h3 class="cli-reference">Usage</h3>

```
uv add [OPTIONS] <PACKAGES|--requirements <REQUIREMENTS>>
uv add [OPTIONS] <PACKAGES|--requirement <REQUIREMENT>>
```

<h3 class="cli-reference">Arguments</h3>
Expand Down Expand Up @@ -1001,7 +1001,7 @@ uv add [OPTIONS] <PACKAGES|--requirements <REQUIREMENTS>>

</dd><dt><code>--reinstall-package</code> <i>reinstall-package</i></dt><dd><p>Reinstall a specific package, regardless of whether it&#8217;s already installed. Implies <code>--refresh-package</code></p>

</dd><dt><code>--requirements</code>, <code>-r</code> <i>requirements</i></dt><dd><p>Add all packages listed in the given <code>requirements.txt</code> files</p>
</dd><dt><code>--requirement</code>, <code>-r</code> <i>requirement</i></dt><dd><p>Add all packages listed in the given <code>requirements.txt</code> files</p>

</dd><dt><code>--resolution</code> <i>resolution</i></dt><dd><p>The strategy to use when selecting between the different compatible versions for a given package requirement.</p>

Expand Down

0 comments on commit 24091dd

Please sign in to comment.