Skip to content

Commit d362e03

Browse files
Add more tests for non-[project] groups (astral-sh#8575)
1 parent 36b729e commit d362e03

File tree

2 files changed

+238
-4
lines changed

2 files changed

+238
-4
lines changed

crates/uv/tests/it/lock.rs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12348,6 +12348,145 @@ fn lock_non_project_conditional() -> Result<()> {
1234812348
Ok(())
1234912349
}
1235012350

12351+
/// Lock a (legacy) non-project workspace root with `dependency-group`.
12352+
#[test]
12353+
fn lock_non_project_group() -> Result<()> {
12354+
let context = TestContext::new("3.10");
12355+
12356+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
12357+
pyproject_toml.write_str(
12358+
r#"
12359+
[tool.uv.workspace]
12360+
members = []
12361+
12362+
[tool.uv]
12363+
dev-dependencies = ["anyio"]
12364+
12365+
[dependency-groups]
12366+
lint = ["iniconfig"]
12367+
dev = ["typing-extensions"]
12368+
"#,
12369+
)?;
12370+
12371+
uv_snapshot!(context.filters(), context.lock(), @r###"
12372+
success: true
12373+
exit_code: 0
12374+
----- stdout -----
12375+
12376+
----- stderr -----
12377+
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.10`.
12378+
Resolved 6 packages in [TIME]
12379+
"###);
12380+
12381+
let lock = context.read("uv.lock");
12382+
12383+
insta::with_settings!({
12384+
filters => context.filters(),
12385+
}, {
12386+
assert_snapshot!(
12387+
lock, @r###"
12388+
version = 1
12389+
requires-python = ">=3.10"
12390+
12391+
[options]
12392+
exclude-newer = "2024-03-25T00:00:00Z"
12393+
12394+
[manifest]
12395+
requirements = [
12396+
{ name = "anyio" },
12397+
{ name = "iniconfig" },
12398+
{ name = "typing-extensions" },
12399+
]
12400+
12401+
[[package]]
12402+
name = "anyio"
12403+
version = "4.3.0"
12404+
source = { registry = "https://pypi.org/simple" }
12405+
dependencies = [
12406+
{ name = "exceptiongroup", marker = "python_full_version < '3.11'" },
12407+
{ name = "idna" },
12408+
{ name = "sniffio" },
12409+
{ name = "typing-extensions", marker = "python_full_version < '3.11'" },
12410+
]
12411+
sdist = { url = "https://files.pythonhosted.org/packages/db/4d/3970183622f0330d3c23d9b8a5f52e365e50381fd484d08e3285104333d3/anyio-4.3.0.tar.gz", hash = "sha256:f75253795a87df48568485fd18cdd2a3fa5c4f7c5be8e5e36637733fce06fed6", size = 159642 }
12412+
wheels = [
12413+
{ url = "https://files.pythonhosted.org/packages/14/fd/2f20c40b45e4fb4324834aea24bd4afdf1143390242c0b33774da0e2e34f/anyio-4.3.0-py3-none-any.whl", hash = "sha256:048e05d0f6caeed70d731f3db756d35dcc1f35747c8c403364a8332c630441b8", size = 85584 },
12414+
]
12415+
12416+
[[package]]
12417+
name = "exceptiongroup"
12418+
version = "1.2.0"
12419+
source = { registry = "https://pypi.org/simple" }
12420+
sdist = { url = "https://files.pythonhosted.org/packages/8e/1c/beef724eaf5b01bb44b6338c8c3494eff7cab376fab4904cfbbc3585dc79/exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68", size = 26264 }
12421+
wheels = [
12422+
{ url = "https://files.pythonhosted.org/packages/b8/9a/5028fd52db10e600f1c4674441b968cf2ea4959085bfb5b99fb1250e5f68/exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14", size = 16210 },
12423+
]
12424+
12425+
[[package]]
12426+
name = "idna"
12427+
version = "3.6"
12428+
source = { registry = "https://pypi.org/simple" }
12429+
sdist = { url = "https://files.pythonhosted.org/packages/bf/3f/ea4b9117521a1e9c50344b909be7886dd00a519552724809bb1f486986c2/idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca", size = 175426 }
12430+
wheels = [
12431+
{ url = "https://files.pythonhosted.org/packages/c2/e7/a82b05cf63a603df6e68d59ae6a68bf5064484a0718ea5033660af4b54a9/idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f", size = 61567 },
12432+
]
12433+
12434+
[[package]]
12435+
name = "iniconfig"
12436+
version = "2.0.0"
12437+
source = { registry = "https://pypi.org/simple" }
12438+
sdist = { url = "https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3", size = 4646 }
12439+
wheels = [
12440+
{ url = "https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374", size = 5892 },
12441+
]
12442+
12443+
[[package]]
12444+
name = "sniffio"
12445+
version = "1.3.1"
12446+
source = { registry = "https://pypi.org/simple" }
12447+
sdist = { url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc", size = 20372 }
12448+
wheels = [
12449+
{ url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2", size = 10235 },
12450+
]
12451+
12452+
[[package]]
12453+
name = "typing-extensions"
12454+
version = "4.10.0"
12455+
source = { registry = "https://pypi.org/simple" }
12456+
sdist = { url = "https://files.pythonhosted.org/packages/16/3a/0d26ce356c7465a19c9ea8814b960f8a36c3b0d07c323176620b7b483e44/typing_extensions-4.10.0.tar.gz", hash = "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb", size = 77558 }
12457+
wheels = [
12458+
{ url = "https://files.pythonhosted.org/packages/f9/de/dc04a3ea60b22624b51c703a84bbe0184abcd1d0b9bc8074b5d6b7ab90bb/typing_extensions-4.10.0-py3-none-any.whl", hash = "sha256:69b1a937c3a517342112fb4c6df7e72fc39a38e7891a5730ed4985b5214b5475", size = 33926 },
12459+
]
12460+
"###
12461+
);
12462+
});
12463+
12464+
// Re-run with `--locked`.
12465+
uv_snapshot!(context.filters(), context.lock().arg("--locked"), @r###"
12466+
success: true
12467+
exit_code: 0
12468+
----- stdout -----
12469+
12470+
----- stderr -----
12471+
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.10`.
12472+
Resolved 6 packages in [TIME]
12473+
"###);
12474+
12475+
// Re-run with `--offline`. We shouldn't need a network connection to validate an
12476+
// already-correct lockfile with immutable metadata.
12477+
uv_snapshot!(context.filters(), context.lock().arg("--locked").arg("--offline").arg("--no-cache"), @r###"
12478+
success: true
12479+
exit_code: 0
12480+
----- stdout -----
12481+
12482+
----- stderr -----
12483+
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.10`.
12484+
Resolved 6 packages in [TIME]
12485+
"###);
12486+
12487+
Ok(())
12488+
}
12489+
1235112490
/// `coverage` defines a `toml` extra, but it doesn't enable any dependencies after Python 3.11.
1235212491
#[test]
1235312492
fn lock_dropped_dev_extra() -> Result<()> {

crates/uv/tests/it/sync.rs

Lines changed: 99 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ fn mixed_requires_python() -> Result<()> {
383383
Ok(())
384384
}
385385

386-
/// Sync development dependencies in a virtual workspace root.
386+
/// Sync development dependencies in a (legacy) non-project workspace root.
387387
#[test]
388-
fn virtual_workspace_dev_dependencies() -> Result<()> {
388+
fn sync_legacy_non_project_dev_dependencies() -> Result<()> {
389389
let context = TestContext::new("3.12");
390390

391391
let pyproject_toml = context.temp_dir.child("pyproject.toml");
@@ -467,6 +467,101 @@ fn virtual_workspace_dev_dependencies() -> Result<()> {
467467
Ok(())
468468
}
469469

470+
/// Sync development dependencies in a (legacy) non-project workspace root.
471+
#[test]
472+
fn sync_legacy_non_project_group() -> Result<()> {
473+
let context = TestContext::new("3.12");
474+
475+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
476+
pyproject_toml.write_str(
477+
r#"
478+
[dependency-groups]
479+
foo = ["anyio"]
480+
bar = ["typing-extensions"]
481+
482+
[tool.uv.workspace]
483+
members = ["child"]
484+
"#,
485+
)?;
486+
487+
let src = context.temp_dir.child("src").child("albatross");
488+
src.create_dir_all()?;
489+
490+
let init = src.child("__init__.py");
491+
init.touch()?;
492+
493+
let child = context.temp_dir.child("child");
494+
fs_err::create_dir_all(&child)?;
495+
496+
let pyproject_toml = child.child("pyproject.toml");
497+
pyproject_toml.write_str(
498+
r#"
499+
[project]
500+
name = "child"
501+
version = "0.1.0"
502+
requires-python = ">=3.12"
503+
dependencies = ["iniconfig>1"]
504+
505+
[build-system]
506+
requires = ["setuptools>=42"]
507+
build-backend = "setuptools.build_meta"
508+
"#,
509+
)?;
510+
511+
let src = child.child("src").child("albatross");
512+
src.create_dir_all()?;
513+
514+
let init = src.child("__init__.py");
515+
init.touch()?;
516+
517+
uv_snapshot!(context.filters(), context.sync(), @r###"
518+
success: true
519+
exit_code: 0
520+
----- stdout -----
521+
522+
----- stderr -----
523+
Resolved 6 packages in [TIME]
524+
Prepared 2 packages in [TIME]
525+
Installed 2 packages in [TIME]
526+
+ child==0.1.0 (from file://[TEMP_DIR]/child)
527+
+ iniconfig==2.0.0
528+
"###);
529+
530+
uv_snapshot!(context.filters(), context.sync().arg("--group").arg("foo"), @r###"
531+
success: true
532+
exit_code: 0
533+
----- stdout -----
534+
535+
----- stderr -----
536+
Resolved 6 packages in [TIME]
537+
Prepared 3 packages in [TIME]
538+
Installed 3 packages in [TIME]
539+
+ anyio==4.3.0
540+
+ idna==3.6
541+
+ sniffio==1.3.1
542+
"###);
543+
544+
uv_snapshot!(context.filters(), context.sync().arg("--only-group").arg("bar"), @r###"
545+
success: true
546+
exit_code: 0
547+
----- stdout -----
548+
549+
----- stderr -----
550+
Resolved 6 packages in [TIME]
551+
Prepared 1 package in [TIME]
552+
Uninstalled 5 packages in [TIME]
553+
Installed 1 package in [TIME]
554+
- anyio==4.3.0
555+
- child==0.1.0 (from file://[TEMP_DIR]/child)
556+
- idna==3.6
557+
- iniconfig==2.0.0
558+
- sniffio==1.3.1
559+
+ typing-extensions==4.10.0
560+
"###);
561+
562+
Ok(())
563+
}
564+
470565
/// Use a `pip install` step to pre-install build dependencies for `--no-build-isolation`.
471566
#[test]
472567
fn sync_build_isolation() -> Result<()> {
@@ -2459,9 +2554,9 @@ fn sync_workspace_custom_environment_path() -> Result<()> {
24592554
Ok(())
24602555
}
24612556

2462-
// Test for warnings when `VIRTUAL_ENV` is set but will not be respected.
2557+
/// Test for warnings when `VIRTUAL_ENV` is set but will not be respected.
24632558
#[test]
2464-
fn sync_virtual_env_warning() -> Result<()> {
2559+
fn sync_legacy_non_project_warning() -> Result<()> {
24652560
let context = TestContext::new("3.12");
24662561

24672562
let pyproject_toml = context.temp_dir.child("pyproject.toml");

0 commit comments

Comments
 (0)