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

Avoid showing disjoint marker error with true #9169

Merged
merged 1 commit into from
Nov 18, 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
22 changes: 12 additions & 10 deletions crates/uv-workspace/src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,23 +799,23 @@ impl TryFrom<SourcesWire> for Sources {
.zip(sources.iter().skip(1).map(Source::marker))
{
if !lhs.is_disjoint(&rhs) {
let Some(left) = lhs.contents().map(|contents| contents.to_string()) else {
return Err(SourceError::MissingMarkers);
};

let Some(right) = rhs.contents().map(|contents| contents.to_string())
else {
return Err(SourceError::MissingMarkers);
};

let mut hint = lhs.negate();
hint.and(rhs.clone());

let lhs = lhs
.contents()
.map(|contents| contents.to_string())
.unwrap_or_else(|| "true".to_string());
let rhs = rhs
.contents()
.map(|contents| contents.to_string())
.unwrap_or_else(|| "true".to_string());
let hint = hint
.contents()
.map(|contents| contents.to_string())
.unwrap_or_else(|| "true".to_string());

return Err(SourceError::OverlappingMarkers(lhs, rhs, hint));
return Err(SourceError::OverlappingMarkers(left, right, hint));
}
}

Expand Down Expand Up @@ -1231,6 +1231,8 @@ pub enum SourceError {
NonUtf8Path(PathBuf),
#[error("Source markers must be disjoint, but the following markers overlap: `{0}` and `{1}`.\n\n{hint}{colon} replace `{1}` with `{2}`.", hint = "hint".bold().cyan(), colon = ":".bold())]
OverlappingMarkers(String, String, String),
#[error("When multiple sources are provided, each source must include a platform markers (e.g., `marker = \"sys_platform == 'linux'\"`)")]
MissingMarkers,
#[error("Must provide at least one source")]
EmptySources,
}
Expand Down
38 changes: 38 additions & 0 deletions crates/uv/tests/it/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18036,6 +18036,44 @@ fn lock_multiple_sources_conflict() -> Result<()> {
Ok(())
}

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

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["iniconfig"]

[tool.uv.sources]
iniconfig = [
{ url = "https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl" },
{ url = "https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz" },
]
"#,
)?;

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

----- stderr -----
error: Failed to parse: `pyproject.toml`
Caused by: TOML parse error at line 9, column 21
|
9 | iniconfig = [
| ^
When multiple sources are provided, each source must include a platform markers (e.g., `marker = "sys_platform == 'linux'"`)
"###);

Ok(())
}

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