Skip to content

Commit

Permalink
relax pip-compile cli strictness
Browse files Browse the repository at this point in the history
  • Loading branch information
Gankra committed Feb 27, 2025
1 parent 29b5098 commit 6e578d9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 56 deletions.
3 changes: 2 additions & 1 deletion crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ fn parse_maybe_string(input: &str) -> Result<Maybe<String>, String> {

#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
#[command(group = clap::ArgGroup::new("sources").required(true).multiple(true))]
pub struct PipCompileArgs {
/// Include all packages listed in the given `requirements.in` files.
///
Expand All @@ -959,7 +960,7 @@ pub struct PipCompileArgs {
///
/// The order of the requirements files and the requirements in them is used to determine
/// priority during resolution.
#[arg(required(true), value_parser = parse_file_path)]
#[arg(group = "sources", value_parser = parse_file_path)]
pub src_file: Vec<PathBuf>,

/// Constrain versions using the given requirements files.
Expand Down
109 changes: 56 additions & 53 deletions crates/uv/tests/it/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1591,18 +1591,18 @@ fn compile_python_conflicts() -> Result<()> {
.arg("--python")
.arg("3.12")
.arg("-p")
.arg("3.12"), @r###"
.arg("3.12"), @r"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: the argument '--python <PYTHON>' cannot be used multiple times
Usage: uv pip compile [OPTIONS] <SRC_FILE>...
Usage: uv pip compile [OPTIONS] <SRC_FILE|--group <GROUP>>
For more information, try '--help'.
"###
"
);

// `UV_PYTHON` should be usable with `-p`
Expand Down Expand Up @@ -3263,18 +3263,18 @@ optional-dependencies.bar = [
.arg("--all-extras")
.arg("--extra")
.arg("foo"),
@r###"
@r"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: the argument '--all-extras' cannot be used with '--extra <EXTRA>'
Usage: uv pip compile --cache-dir [CACHE_DIR] --all-extras --exclude-newer <EXCLUDE_NEWER> <SRC_FILE>...
Usage: uv pip compile --cache-dir [CACHE_DIR] --all-extras --exclude-newer <EXCLUDE_NEWER> <SRC_FILE|--group <GROUP>>
For more information, try '--help'.
"###
"
);

Ok(())
Expand Down Expand Up @@ -15262,28 +15262,29 @@ fn dependency_group() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --group bar
iniconfig==2.0.0
----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ iniconfig==2.0.0
");

context = new_context()?;
uv_snapshot!(context.filters(), context.pip_compile()
.arg("-r").arg("pyproject.toml")
.arg("pyproject.toml")
.arg("--group").arg("bar"), @r"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] pyproject.toml --group bar
iniconfig==2.0.0
typing-extensions==4.10.0
# via project (pyproject.toml)
----- stderr -----
Resolved 2 packages in [TIME]
Prepared 2 packages in [TIME]
Installed 2 packages in [TIME]
+ iniconfig==2.0.0
+ typing-extensions==4.10.0
");

context = new_context()?;
Expand All @@ -15292,28 +15293,29 @@ fn dependency_group() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --group pyproject.toml:bar
iniconfig==2.0.0
----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ iniconfig==2.0.0
");

context = new_context()?;
uv_snapshot!(context.filters(), context.pip_compile()
.arg("-r").arg("pyproject.toml")
.arg("pyproject.toml")
.arg("--group").arg("pyproject.toml:bar"), @r"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] pyproject.toml --group pyproject.toml:bar
iniconfig==2.0.0
typing-extensions==4.10.0
# via project (pyproject.toml)
----- stderr -----
Resolved 2 packages in [TIME]
Prepared 2 packages in [TIME]
Installed 2 packages in [TIME]
+ iniconfig==2.0.0
+ typing-extensions==4.10.0
");

context = new_context()?;
Expand All @@ -15322,12 +15324,12 @@ fn dependency_group() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --group foo
sortedcontainers==2.4.0
----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ sortedcontainers==2.4.0
");

context = new_context()?;
Expand All @@ -15337,31 +15339,32 @@ fn dependency_group() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --group foo --group bar
iniconfig==2.0.0
sortedcontainers==2.4.0
----- stderr -----
Resolved 2 packages in [TIME]
Prepared 2 packages in [TIME]
Installed 2 packages in [TIME]
+ iniconfig==2.0.0
+ sortedcontainers==2.4.0
");

context = new_context()?;
uv_snapshot!(context.filters(), context.pip_compile()
.arg("-r").arg("pyproject.toml")
.arg("pyproject.toml")
.arg("--group").arg("foo")
.arg("--group").arg("bar"), @r"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] pyproject.toml --group foo --group bar
iniconfig==2.0.0
sortedcontainers==2.4.0
typing-extensions==4.10.0
# via project (pyproject.toml)
----- stderr -----
Resolved 3 packages in [TIME]
Prepared 3 packages in [TIME]
Installed 3 packages in [TIME]
+ iniconfig==2.0.0
+ sortedcontainers==2.4.0
+ typing-extensions==4.10.0
");

Ok(())
Expand Down Expand Up @@ -15411,25 +15414,25 @@ fn many_pyproject_group() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --group pyproject.toml:foo
sortedcontainers==2.4.0
----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ sortedcontainers==2.4.0
");

uv_snapshot!(context.filters(), context.pip_compile()
.arg("--group").arg("subdir/pyproject.toml:foo"), @r"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --group subdir/pyproject.toml:foo
iniconfig==2.0.0
----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ iniconfig==2.0.0
");

context = new_context()?;
Expand All @@ -15439,13 +15442,13 @@ fn many_pyproject_group() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --group pyproject.toml:foo --group subdir/pyproject.toml:foo
iniconfig==2.0.0
sortedcontainers==2.4.0
----- stderr -----
Resolved 2 packages in [TIME]
Prepared 2 packages in [TIME]
Installed 2 packages in [TIME]
+ iniconfig==2.0.0
+ sortedcontainers==2.4.0
");

context = new_context()?;
Expand All @@ -15455,13 +15458,13 @@ fn many_pyproject_group() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --group foo --group subdir/pyproject.toml:foo
iniconfig==2.0.0
sortedcontainers==2.4.0
----- stderr -----
Resolved 2 packages in [TIME]
Prepared 2 packages in [TIME]
Installed 2 packages in [TIME]
+ iniconfig==2.0.0
+ sortedcontainers==2.4.0
");

context = new_context()?;
Expand All @@ -15471,13 +15474,13 @@ fn many_pyproject_group() -> Result<()> {
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --group foo --group subdir/pyproject.toml:bar
sniffio==1.3.1
sortedcontainers==2.4.0
----- stderr -----
Resolved 2 packages in [TIME]
Prepared 2 packages in [TIME]
Installed 2 packages in [TIME]
+ sniffio==1.3.1
+ sortedcontainers==2.4.0
");

context = new_context()?;
Expand Down
12 changes: 10 additions & 2 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -5533,7 +5533,7 @@ Compile a `requirements.in` file to a `requirements.txt` file
<h3 class="cli-reference">Usage</h3>

```
uv pip compile [OPTIONS] <SRC_FILE>...
uv pip compile [OPTIONS] <SRC_FILE|--group <GROUP>>
```

<h3 class="cli-reference">Arguments</h3>
Expand Down Expand Up @@ -5678,6 +5678,12 @@ uv pip compile [OPTIONS] <SRC_FILE>...
</ul>
</dd><dt><code>--generate-hashes</code></dt><dd><p>Include distribution hashes in the output file</p>

</dd><dt><code>--group</code> <i>group</i></dt><dd><p>Install the specified dependency group in the specified pyproject.toml</p>

<p>If no path is provided, ./pyproject.toml is used.</p>

<p>May be provided multiple times.</p>

</dd><dt><code>--help</code>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>

</dd><dt><code>--index</code> <i>index</i></dt><dd><p>The URLs to use when resolving dependencies, in addition to the default index.</p>
Expand Down Expand Up @@ -6552,7 +6558,9 @@ uv pip install [OPTIONS] <PACKAGE|--requirements <REQUIREMENTS>|--editable <EDIT

<li><code>requires-python</code>: Optimize for selecting latest supported version of each package, for each supported Python version</li>
</ul>
</dd><dt><code>--group</code> <i>group</i></dt><dd><p>Ignore the package and it&#8217;s dependencies, only install from the specified dependency group.</p>
</dd><dt><code>--group</code> <i>group</i></dt><dd><p>Install the specified dependency group in the specified pyproject.toml</p>

<p>If no path is provided, ./pyproject.toml is used.</p>

<p>May be provided multiple times.</p>

Expand Down

0 comments on commit 6e578d9

Please sign in to comment.