Skip to content

Commit

Permalink
unrestrict api
Browse files Browse the repository at this point in the history
  • Loading branch information
Gankra committed Feb 27, 2025
1 parent dbeb858 commit 29b5098
Show file tree
Hide file tree
Showing 3 changed files with 317 additions and 22 deletions.
4 changes: 2 additions & 2 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ pub struct PipCompileArgs {
/// If no path is provided, ./pyproject.toml is used.
///
/// May be provided multiple times.
#[arg(long, group = "sources", conflicts_with_all = ["requirements", "package", "editable"])]
#[arg(long, group = "sources")]
pub group: Vec<PipGroupName>,

/// Write the compiled requirements to the given `requirements.txt` file.
Expand Down Expand Up @@ -1599,7 +1599,7 @@ pub struct PipInstallArgs {
/// If no path is provided, ./pyproject.toml is used.
///
/// May be provided multiple times.
#[arg(long, group = "sources", conflicts_with_all = ["requirements", "package", "editable"])]
#[arg(long, group = "sources")]
pub group: Vec<PipGroupName>,

/// Require a matching hash for each requirement.
Expand Down
265 changes: 265 additions & 0 deletions crates/uv/tests/it/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15231,6 +15231,271 @@ fn respect_index_preference() -> Result<()> {
Ok(())
}

#[test]
fn dependency_group() -> Result<()> {
fn new_context() -> Result<TestContext> {
let context = TestContext::new("3.12");

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["typing-extensions"]
[dependency-groups]
foo = ["sortedcontainers"]
bar = ["iniconfig"]
dev = ["sniffio"]
"#,
)?;

Ok(context)
}

let mut context;

context = new_context()?;
uv_snapshot!(context.filters(), context.pip_compile()
.arg("--group").arg("bar"), @r"
success: true
exit_code: 0
----- stdout -----
----- 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("--group").arg("bar"), @r"
success: true
exit_code: 0
----- stdout -----
----- 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()?;
uv_snapshot!(context.filters(), context.pip_compile()
.arg("--group").arg("pyproject.toml:bar"), @r"
success: true
exit_code: 0
----- stdout -----
----- 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("--group").arg("pyproject.toml:bar"), @r"
success: true
exit_code: 0
----- stdout -----
----- 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()?;
uv_snapshot!(context.filters(), context.pip_compile()
.arg("--group").arg("foo"), @r"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ sortedcontainers==2.4.0
");

context = new_context()?;
uv_snapshot!(context.filters(), context.pip_compile()
.arg("--group").arg("foo")
.arg("--group").arg("bar"), @r"
success: true
exit_code: 0
----- stdout -----
----- 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("--group").arg("foo")
.arg("--group").arg("bar"), @r"
success: true
exit_code: 0
----- stdout -----
----- 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(())
}

#[test]
fn many_pyproject_group() -> Result<()> {
fn new_context() -> Result<TestContext> {
let context = TestContext::new("3.12");

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["typing-extensions"]
[dependency-groups]
foo = ["sortedcontainers"]
"#,
)?;

let subdir = context.temp_dir.child("subdir");
subdir.create_dir_all()?;
let pyproject_toml2 = subdir.child("pyproject.toml");
pyproject_toml2.write_str(
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
[dependency-groups]
foo = ["iniconfig"]
bar = ["sniffio"]
"#,
)?;

Ok(context)
}

let mut context;

context = new_context()?;
uv_snapshot!(context.filters(), context.pip_compile()
.arg("--group").arg("pyproject.toml:foo"), @r"
success: true
exit_code: 0
----- stdout -----
----- 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 -----
----- 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("--group").arg("pyproject.toml:foo")
.arg("--group").arg("subdir/pyproject.toml:foo"), @r"
success: true
exit_code: 0
----- stdout -----
----- 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("--group").arg("foo")
.arg("--group").arg("subdir/pyproject.toml:foo"), @r"
success: true
exit_code: 0
----- stdout -----
----- 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("--group").arg("foo")
.arg("--group").arg("subdir/pyproject.toml:bar"), @r"
success: true
exit_code: 0
----- stdout -----
----- 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()?;

uv_snapshot!(context.filters(), context.pip_compile()
.arg("--group").arg("bar")
.arg("--group").arg("subdir/pyproject.toml:bar"), @r"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: The dependency-group 'bar' is not defined in pyproject.toml
");

Ok(())
}

/// See: <https://github.com/astral-sh/uv/issues/10957>
#[test]
fn compile_preserve_requires_python_split() -> Result<()> {
Expand Down
70 changes: 50 additions & 20 deletions crates/uv/tests/it/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9015,6 +9015,22 @@ fn dependency_group() -> Result<()> {
+ iniconfig==2.0.0
");

context = new_context()?;
uv_snapshot!(context.filters(), context.pip_install()
.arg("-r").arg("pyproject.toml")
.arg("--group").arg("bar"), @r"
success: true
exit_code: 0
----- stdout -----
----- 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()?;
uv_snapshot!(context.filters(), context.pip_install()
.arg("--group").arg("pyproject.toml:bar"), @r"
Expand All @@ -9029,6 +9045,22 @@ fn dependency_group() -> Result<()> {
+ iniconfig==2.0.0
");

context = new_context()?;
uv_snapshot!(context.filters(), context.pip_install()
.arg("-r").arg("pyproject.toml")
.arg("--group").arg("pyproject.toml:bar"), @r"
success: true
exit_code: 0
----- stdout -----
----- 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()?;
uv_snapshot!(context.filters(), context.pip_install()
.arg("--group").arg("foo"), @r"
Expand Down Expand Up @@ -9059,6 +9091,24 @@ fn dependency_group() -> Result<()> {
+ sortedcontainers==2.4.0
");

context = new_context()?;
uv_snapshot!(context.filters(), context.pip_install()
.arg("-r").arg("pyproject.toml")
.arg("--group").arg("foo")
.arg("--group").arg("bar"), @r"
success: true
exit_code: 0
----- stdout -----
----- 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 @@ -9192,26 +9242,6 @@ fn many_pyproject_group() -> Result<()> {
Ok(())
}

#[test]
fn group_needs_manifest() {
let context = TestContext::new("3.12");

uv_snapshot!(context.filters(), context.pip_install()
.arg("sniffio")
.arg("--group").arg("foo"), @r"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: the argument '[PACKAGE]...' cannot be used with '--group <GROUP>'
Usage: uv pip install --cache-dir [CACHE_DIR] --exclude-newer <EXCLUDE_NEWER> <PACKAGE|--requirements <REQUIREMENTS>|--editable <EDITABLE>|--group <GROUP>>
For more information, try '--help'.
");
}

/// Regression test that we don't discover workspaces with `--no-sources`.
///
/// We have a workspace dependency shadowing a PyPI package and using this package's version to
Expand Down

0 comments on commit 29b5098

Please sign in to comment.