Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow direct URLs in optional dependencies in editables #2206

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 48 additions & 0 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4756,3 +4756,51 @@ 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 pyproject_toml = context.temp_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("-e .[dev]")?;

uv_snapshot!(context.compile()
.arg("requirements.in"), @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 2023-11-18T12:00:00Z requirements.in
-e .
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(())
}