diff --git a/crates/uv-requirements/src/pyproject.rs b/crates/uv-requirements/src/pyproject.rs index da247eb5c..00527008e 100644 --- a/crates/uv-requirements/src/pyproject.rs +++ b/crates/uv-requirements/src/pyproject.rs @@ -530,7 +530,7 @@ fn path_source( project_dir: &Path, editable: Option, ) -> Result { - let url = VerbatimUrl::parse_path(&path, project_dir); + let url = VerbatimUrl::parse_path(&path, project_dir).with_given(path.clone()); let path_buf = PathBuf::from(&path); let path_buf = path_buf .absolutize_from(project_dir) diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index b12841a9b..5628a3210 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -8652,3 +8652,86 @@ fn git_source_missing_tag() -> Result<()> { Ok(()) } + +#[test] +fn tool_uv_sources() -> Result<()> { + let context = TestContext::new("3.12"); + // Use a subdir to test path normalization. + let require_path = "some_dir/pyproject.toml"; + let pyproject_toml = context.temp_dir.child(require_path); + pyproject_toml.write_str(indoc! {r#" + [project] + name = "foo" + version = "0.0.0" + dependencies = [ + "tqdm>4,<=5", + "packaging @ git+https://github.com/pypa/packaging@32deafe8668a2130a3366b98154914d188f3718e", + "poetry_editable", + "urllib3 @ https://files.pythonhosted.org/packages/a2/73/a68704750a7679d0b6d3ad7aa8d4da8e14e151ae82e6fee774e6e0d05ec8/urllib3-2.2.1-py3-none-any.whl", + # Windows consistency + "colorama>0.4,<5", + ] + + [project.optional-dependencies] + utils = [ + "boltons==24.0.0" + ] + dont_install_me = [ + "broken @ https://example.org/does/not/exist" + ] + + [tool.uv.sources] + tqdm = { url = "https://files.pythonhosted.org/packages/a5/d6/502a859bac4ad5e274255576cd3e15ca273cdb91731bc39fb840dd422ee9/tqdm-4.66.0-py3-none-any.whl" } + boltons = { git = "https://github.com/mahmoud/boltons", rev = "57fbaa9b673ed85b32458b31baeeae230520e4a0" } + poetry_editable = { path = "../poetry_editable", editable = true } + "#})?; + + let project_root = fs_err::canonicalize(std::env::current_dir()?.join("../.."))?; + fs_err::create_dir_all(context.temp_dir.join("poetry_editable/poetry_editable"))?; + fs_err::copy( + project_root.join("scripts/packages/poetry_editable/pyproject.toml"), + context.temp_dir.join("poetry_editable/pyproject.toml"), + )?; + fs_err::copy( + project_root.join("scripts/packages/poetry_editable/poetry_editable/__init__.py"), + context + .temp_dir + .join("poetry_editable/poetry_editable/__init__.py"), + )?; + + let mut filters = context.filters(); + // Remove windows-only tqdm -> colorama dependency + filters.push((" # via tqdm\n", "")); + + // Install the editable packages. + uv_snapshot!(filters, windows_filters=false, context.compile() + .arg("--preview") + .arg(require_path) + .arg("--extra") + .arg("utils"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z --preview some_dir/pyproject.toml --extra utils + -e ../poetry_editable + anyio==4.3.0 + # via poetry-editable + boltons @ git+https://github.com/mahmoud/boltons@57fbaa9b673ed85b32458b31baeeae230520e4a0 + colorama==0.4.6 + idna==3.6 + # via anyio + packaging @ git+https://github.com/pypa/packaging@32deafe8668a2130a3366b98154914d188f3718e + sniffio==1.3.1 + # via anyio + tqdm @ https://files.pythonhosted.org/packages/a5/d6/502a859bac4ad5e274255576cd3e15ca273cdb91731bc39fb840dd422ee9/tqdm-4.66.0-py3-none-any.whl + urllib3 @ https://files.pythonhosted.org/packages/a2/73/a68704750a7679d0b6d3ad7aa8d4da8e14e151ae82e6fee774e6e0d05ec8/urllib3-2.2.1-py3-none-any.whl + + ----- stderr ----- + Built 1 editable in [TIME] + Resolved 9 packages in [TIME] + "### + ); + + Ok(()) +}