Skip to content

Commit

Permalink
Allow users to specify URLs in project.dependencies and tool.uv.sources
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Dec 8, 2024
1 parent 00a4adf commit 5ba26bf
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 31 deletions.
37 changes: 13 additions & 24 deletions crates/uv-distribution/src/metadata/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ impl LoweredRequirement {
marker,
..
} => {
if matches!(requirement.version_or_url, Some(VersionOrUrl::Url(_))) {
return Err(LoweringError::ConflictingUrls);
}
let source = git_source(
&git,
subdirectory.map(PathBuf::from),
Expand All @@ -203,9 +200,6 @@ impl LoweredRequirement {
marker,
..
} => {
if matches!(requirement.version_or_url, Some(VersionOrUrl::Url(_))) {
return Err(LoweringError::ConflictingUrls);
}
let source = url_source(url, subdirectory.map(PathBuf::from))?;
(source, marker)
}
Expand All @@ -215,9 +209,6 @@ impl LoweredRequirement {
marker,
..
} => {
if matches!(requirement.version_or_url, Some(VersionOrUrl::Url(_))) {
return Err(LoweringError::ConflictingUrls);
}
let source = path_source(
PathBuf::from(path),
git_member,
Expand Down Expand Up @@ -276,9 +267,6 @@ impl LoweredRequirement {
if !is_workspace {
return Err(LoweringError::WorkspaceFalse);
}
if matches!(requirement.version_or_url, Some(VersionOrUrl::Url(_))) {
return Err(LoweringError::ConflictingUrls);
}
let member = workspace
.packages()
.get(&requirement.name)
Expand Down Expand Up @@ -433,9 +421,6 @@ impl LoweredRequirement {
marker,
..
} => {
if matches!(requirement.version_or_url, Some(VersionOrUrl::Url(_))) {
return Err(LoweringError::ConflictingUrls);
}
let source = git_source(
&git,
subdirectory.map(PathBuf::from),
Expand All @@ -451,9 +436,6 @@ impl LoweredRequirement {
marker,
..
} => {
if matches!(requirement.version_or_url, Some(VersionOrUrl::Url(_))) {
return Err(LoweringError::ConflictingUrls);
}
let source = url_source(url, subdirectory.map(PathBuf::from))?;
(source, marker)
}
Expand All @@ -463,9 +445,6 @@ impl LoweredRequirement {
marker,
..
} => {
if matches!(requirement.version_or_url, Some(VersionOrUrl::Url(_))) {
return Err(LoweringError::ConflictingUrls);
}
let source = path_source(
PathBuf::from(path),
None,
Expand Down Expand Up @@ -550,8 +529,6 @@ pub enum LoweringError {
InvalidUrl(#[from] url::ParseError),
#[error(transparent)]
InvalidVerbatimUrl(#[from] uv_pep508::VerbatimUrlError),
#[error("Can't combine URLs from both `project.dependencies` and `tool.uv.sources`")]
ConflictingUrls,
#[error("Fragments are not allowed in URLs: `{0}`")]
ForbiddenFragment(Url),
#[error("`workspace = false` is not yet supported")]
Expand Down Expand Up @@ -678,7 +655,19 @@ fn registry_source(
index: Some(index),
conflict,
}),
Some(VersionOrUrl::Url(_)) => Err(LoweringError::ConflictingUrls),
Some(VersionOrUrl::Url(_)) => {
if matches!(bounds, LowerBound::Warn) {
warn_user_once!(
"Missing version constraint (e.g., a lower bound) for `{}`",
requirement.name
);
}
Ok(RequirementSource::Registry {
specifier: VersionSpecifiers::empty(),
index: Some(index),
conflict,
})
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-distribution/src/metadata/requires_dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ mod test {

assert_snapshot!(format_err(input).await, @r###"
error: Failed to parse entry: `tqdm`
Caused by: Can't combine URLs from both `project.dependencies` and `tool.uv.sources`
Caused by: `tqdm` references a workspace in `tool.uv.sources` (e.g., `tqdm = { workspace = true }`), but is not a workspace member
"###);
}

Expand Down
84 changes: 78 additions & 6 deletions crates/uv/tests/it/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9738,7 +9738,7 @@ fn lock_transitive_extra() -> Result<()> {
}

/// If a source is provided via `tool.uv.sources` _and_ a URL is provided in `project.dependencies`,
/// we raise an error.
/// we accept the source in `tool.uv.sources`, unless `--no-sources` is provided.
#[test]
fn lock_mismatched_sources() -> Result<()> {
let context = TestContext::new("3.12");
Expand All @@ -9760,16 +9760,88 @@ fn lock_mismatched_sources() -> Result<()> {
)?;

uv_snapshot!(context.filters(), context.lock(), @r###"
success: false
exit_code: 1
success: true
exit_code: 0
----- stdout -----

----- stderr -----
× Failed to build `project @ file://[TEMP_DIR]/`
├─▶ Failed to parse entry: `uv-public-pypackage`
╰─▶ Can't combine URLs from both `project.dependencies` and `tool.uv.sources`
Resolved 2 packages in [TIME]
"###);

let lock = context.read("uv.lock");

insta::with_settings!({
filters => context.filters(),
}, {
assert_snapshot!(
lock, @r###"
version = 1
requires-python = ">=3.12"

[options]
exclude-newer = "2024-03-25T00:00:00Z"

[[package]]
name = "project"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "uv-public-pypackage" },
]

[package.metadata]
requires-dist = [{ name = "uv-public-pypackage", git = "https://github.com/astral-test/uv-public-pypackage?tag=0.0.1" }]

[[package]]
name = "uv-public-pypackage"
version = "0.1.0"
source = { git = "https://github.com/astral-test/uv-public-pypackage?tag=0.0.1#0dacfd662c64cb4ceb16e6cf65a157a8b715b979" }
"###
);
});

// If we run with `--no-sources`, we should use the URL provided in `project.dependencies`.
uv_snapshot!(context.filters(), context.lock().arg("--no-sources"), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 2 packages in [TIME]
"###);

let lock = context.read("uv.lock");

insta::with_settings!({
filters => context.filters(),
}, {
assert_snapshot!(
lock, @r###"
version = 1
requires-python = ">=3.12"

[options]
exclude-newer = "2024-03-25T00:00:00Z"

[[package]]
name = "project"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "uv-public-pypackage" },
]

[package.metadata]
requires-dist = [{ name = "uv-public-pypackage", git = "https://github.com/astral-test/uv-public-pypackage?rev=0.0.2" }]

[[package]]
name = "uv-public-pypackage"
version = "0.1.0"
source = { git = "https://github.com/astral-test/uv-public-pypackage?rev=0.0.2#b270df1a2fb5d012294e9aaf05e7e0bab1e6a389" }
"###
);
});

Ok(())
}

Expand Down

0 comments on commit 5ba26bf

Please sign in to comment.