mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-01 14:31:12 +00:00
Preserve given for tool.uv.sources
paths (#3412)
We now correctly emit relative paths in `uv pip compile` with `tool.uv.sources` path inputs. `tool.uv.sources` is mainly intended to be used with the uv lock file over requirements.txt, but it's good to have basic `uv pip` support working. Fixes #3366
This commit is contained in:
parent
18516b4e41
commit
24f38d7c22
2 changed files with 84 additions and 1 deletions
|
@ -530,7 +530,7 @@ fn path_source(
|
||||||
project_dir: &Path,
|
project_dir: &Path,
|
||||||
editable: Option<bool>,
|
editable: Option<bool>,
|
||||||
) -> Result<RequirementSource, LoweringError> {
|
) -> Result<RequirementSource, LoweringError> {
|
||||||
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 = PathBuf::from(&path);
|
||||||
let path_buf = path_buf
|
let path_buf = path_buf
|
||||||
.absolutize_from(project_dir)
|
.absolutize_from(project_dir)
|
||||||
|
|
|
@ -8652,3 +8652,86 @@ fn git_source_missing_tag() -> Result<()> {
|
||||||
|
|
||||||
Ok(())
|
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(())
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue