Skip to content

Commit

Permalink
Allow direct URLs in optional dependencies in editables
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 5, 2024
1 parent 0bc0478 commit 5f00c7b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/uv-resolver/src/resolver/urls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ impl Urls {
}

// Add any editable requirements. If there are any conflicts, return an error.
for (requirement, metadata) in &manifest.editables {
if let Some(previous) = urls.insert(metadata.name.clone(), requirement.url.clone()) {
for (editable, metadata) in &manifest.editables {
if let Some(previous) = urls.insert(metadata.name.clone(), editable.url.clone()) {
if cache_key::CanonicalUrl::new(previous.raw())
!= cache_key::CanonicalUrl::new(requirement.raw())
!= cache_key::CanonicalUrl::new(editable.raw())
{
return Err(ResolveError::ConflictingUrlsDirect(
metadata.name.clone(),
previous.verbatim().to_string(),
requirement.verbatim().to_string(),
editable.verbatim().to_string(),
));
}
}

for requirement in &metadata.requires_dist {
if !requirement.evaluate_markers(markers, &[]) {
if !requirement.evaluate_markers(markers, &editable.extras) {
continue;
}

Expand Down
51 changes: 51 additions & 0 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4756,3 +4756,54 @@ requires-python = "<=3.8"

Ok(())
}

#[test]
fn editable_optional_url() -> Result<()> {
let context = TestContext::new("3.12");

// Create an editable package with an optional URL dependency.
let editable_dir = TempDir::new()?;
let pyproject_toml = editable_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"[project]
name = "example"
version = "0.0.0"
dependencies = []
requires-python = '>=3.8'
[project.optional-dependencies]
dev = [
"anyio @ https://files.pythonhosted.org/packages/bf/cd/d6d9bb1dadf73e7af02d18225cbd2c93f8552e13130484f1c8dcfece292b/anyio-4.2.0-py3-none-any.whl"
]
"#,
)?;

// Write to a requirements file.
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str(&format!("-e {}[dev]", editable_dir.path().display()))?;

uv_snapshot!(context.compile()
.arg("requirements.in"), @r###"
success: true
exit_code: 0
----- stdout -----
Highest
Highest
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2023-11-18T12:00:00Z requirements.in
-e /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpsMMTWf
anyio @ https://files.pythonhosted.org/packages/bf/cd/d6d9bb1dadf73e7af02d18225cbd2c93f8552e13130484f1c8dcfece292b/anyio-4.2.0-py3-none-any.whl
# via example
idna==3.4
# via anyio
sniffio==1.3.0
# via anyio
----- stderr -----
Built 1 editable in [TIME]
Resolved 4 packages in [TIME]
"###
);

Ok(())
}

0 comments on commit 5f00c7b

Please sign in to comment.