Skip to content

Commit

Permalink
Allow URL requirements in editable installs (#1614)
Browse files Browse the repository at this point in the history
## Summary

If an editable package declares a direct URL requirement, we currently
error since it's not considered an "allowed" requirement. We need to add
those URLs to the allow-list.

Closes #1603.
  • Loading branch information
charliermarsh authored Feb 17, 2024
1 parent 8675f66 commit 5c4ceca
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 7 deletions.
17 changes: 11 additions & 6 deletions crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,17 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
None
}
})
.chain(
manifest
.editables
.iter()
.map(|(editable, _)| editable.raw()),
)
.chain(manifest.editables.iter().flat_map(|(editable, metadata)| {
std::iter::once(editable.raw()).chain(metadata.requires_dist.iter().filter_map(
|req| {
if let Some(pep508_rs::VersionOrUrl::Url(url)) = &req.version_or_url {
Some(url.raw())
} else {
None
}
},
))
}))
.collect();

// Determine the allowed yanked package versions
Expand Down
39 changes: 39 additions & 0 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,45 @@ fn compile_editable() -> Result<()> {
Ok(())
}

/// Compile an editable package with a direct URL requirement.
#[test]
fn compile_editable_url_requirement() -> Result<()> {
let context = TestContext::new("3.12");
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("-e ../../scripts/editable-installs/hatchling_editable")?;

let filter_path = regex::escape(&requirements_in.normalized_display().to_string());
let filters: Vec<_> = [(filter_path.as_str(), "requirements.in")]
.into_iter()
.chain(INSTA_FILTERS.to_vec())
.collect();

uv_snapshot!(filters, Command::new(get_bin())
.arg("pip")
.arg("compile")
.arg(requirements_in.path())
.arg("--cache-dir")
.arg(context.cache_dir.path())
.arg("--exclude-newer")
.arg(EXCLUDE_NEWER)
.env("VIRTUAL_ENV", context.venv.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv v[VERSION] via the following command:
# uv pip compile requirements.in --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z
-e ../../scripts/editable-installs/hatchling_editable
iniconfig @ https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl
# via hatchling-editable
----- stderr -----
Built 1 editable in [TIME]
Resolved 2 packages in [TIME]
"###);

Ok(())
}

#[test]
#[ignore]
fn cache_errors_are_non_fatal() -> Result<()> {
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def func():
pass
22 changes: 22 additions & 0 deletions scripts/editable-installs/hatchling_editable/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "hatchling-editable"
description = 'A simple editable package with a URL dependency.'
readme = "README.md"
requires-python = ">=3.7"
license = "MIT"
keywords = []
authors = [
{ name = "Astral Software Inc.", email = "[email protected]" },
]
classifiers = []
dependencies = [
"iniconfig @ https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl"
]
version = "0.1.0"

[tool.hatch.metadata]
allow-direct-references = true
2 changes: 1 addition & 1 deletion scripts/editable-installs/poetry_editable/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "poetry-editable"
version = "0.1.0"
description = ""
authors = ["konstin <[email protected]>"]
authors = ["Astral Software Inc. <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.10"
Expand Down

0 comments on commit 5c4ceca

Please sign in to comment.