Skip to content

Commit 66b6d7a

Browse files
charliermarshzanieb
authored andcommitted
Respect subdirectories when locating Git workspaces (#5944)
We were discovering the workspace from the Git repository root, so attempting to build any subdirectories would fail. Closes #5942. ``` cargo run pip install \ git+https://github.com/flyteorg/flytekit.git@master#subdirectory=plugins/flytekit-flyteinteractive ```
1 parent 4f56a27 commit 66b6d7a

File tree

2 files changed

+94
-2
lines changed

2 files changed

+94
-2
lines changed

crates/uv-distribution/src/source/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,11 +1249,17 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
12491249
.await
12501250
.map_err(Error::CacheWrite)?;
12511251

1252+
let path = if let Some(subdirectory) = resource.subdirectory {
1253+
Cow::Owned(fetch.path().join(subdirectory))
1254+
} else {
1255+
Cow::Borrowed(fetch.path())
1256+
};
1257+
12521258
return Ok(ArchiveMetadata::from(
12531259
Metadata::from_workspace(
12541260
metadata,
1255-
fetch.path(),
1256-
fetch.path(),
1261+
&path,
1262+
&path,
12571263
self.build_context.sources(),
12581264
self.preview_mode,
12591265
)

crates/uv/tests/lock.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,92 @@ fn lock_sdist_git() -> Result<()> {
500500
Ok(())
501501
}
502502

503+
/// Lock a Git requirement using PEP 508.
504+
#[test]
505+
#[cfg(feature = "git")]
506+
fn lock_sdist_git_subdirectory() -> Result<()> {
507+
let context = TestContext::new("3.12");
508+
509+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
510+
pyproject_toml.write_str(
511+
r#"
512+
[project]
513+
name = "project"
514+
version = "0.1.0"
515+
requires-python = ">=3.12"
516+
dependencies = ["example-pkg-a @ git+https://github.com/pypa/sample-namespace-packages.git@df7530eeb8fa0cb7dbb8ecb28363e8e36bfa2f45#subdirectory=pkg_resources/pkg_a"]
517+
"#,
518+
)?;
519+
520+
deterministic! { context =>
521+
uv_snapshot!(context.filters(), context.lock(), @r###"
522+
success: true
523+
exit_code: 0
524+
----- stdout -----
525+
526+
----- stderr -----
527+
warning: `uv lock` is experimental and may change without warning
528+
Resolved 2 packages in [TIME]
529+
"###);
530+
531+
let lock = fs_err::read_to_string(context.temp_dir.join("uv.lock")).unwrap();
532+
533+
insta::with_settings!({
534+
filters => context.filters(),
535+
}, {
536+
assert_snapshot!(
537+
lock, @r###"
538+
version = 1
539+
requires-python = ">=3.12"
540+
541+
[options]
542+
exclude-newer = "2024-03-25 00:00:00 UTC"
543+
544+
[[package]]
545+
name = "example-pkg-a"
546+
version = "1"
547+
source = { git = "https://github.com/pypa/sample-namespace-packages.git?subdirectory=pkg_resources%2Fpkg_a&rev=df7530eeb8fa0cb7dbb8ecb28363e8e36bfa2f45#df7530eeb8fa0cb7dbb8ecb28363e8e36bfa2f45" }
548+
549+
[[package]]
550+
name = "project"
551+
version = "0.1.0"
552+
source = { editable = "." }
553+
dependencies = [
554+
{ name = "example-pkg-a" },
555+
]
556+
"###
557+
);
558+
});
559+
}
560+
561+
// Re-run with `--locked`.
562+
uv_snapshot!(context.filters(), context.lock().arg("--locked"), @r###"
563+
success: true
564+
exit_code: 0
565+
----- stdout -----
566+
567+
----- stderr -----
568+
warning: `uv lock` is experimental and may change without warning
569+
Resolved 2 packages in [TIME]
570+
"###);
571+
572+
// Install from the lockfile.
573+
uv_snapshot!(context.filters(), context.sync().arg("--frozen"), @r###"
574+
success: true
575+
exit_code: 0
576+
----- stdout -----
577+
578+
----- stderr -----
579+
warning: `uv sync` is experimental and may change without warning
580+
Prepared 2 packages in [TIME]
581+
Installed 2 packages in [TIME]
582+
+ example-pkg-a==1 (from git+https://github.com/pypa/sample-namespace-packages.git@df7530eeb8fa0cb7dbb8ecb28363e8e36bfa2f45#subdirectory=pkg_resources/pkg_a)
583+
+ project==0.1.0 (from file://[TEMP_DIR]/)
584+
"###);
585+
586+
Ok(())
587+
}
588+
503589
/// Lock a Git requirement using PEP 508.
504590
#[test]
505591
#[cfg(feature = "git")]

0 commit comments

Comments
 (0)