Allow URL requirements in editable installs (#1614)

## 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 https://github.com/astral-sh/uv/issues/1603.
This commit is contained in:
Charlie Marsh 2024-02-17 15:20:23 -05:00 committed by GitHub
parent 8675f66e74
commit 5c4cecaa85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 75 additions and 7 deletions

View file

@ -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

View file

@ -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<()> {

View file

@ -0,0 +1,2 @@
def func():
pass

View file

@ -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 = "hey@astral.sh" },
]
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

View file

@ -2,7 +2,7 @@
name = "poetry-editable"
version = "0.1.0"
description = ""
authors = ["konstin <konstin@mailbox.org>"]
authors = ["Astral Software Inc. <hey@astral.sh>"]
[tool.poetry.dependencies]
python = "^3.10"