mirror of https://github.com/astral-sh/uv
Respect preferences for explicit index dependencies from `requirements.txt` (#10690)
## Summary Closes: https://github.com/astral-sh/uv/issues/10383.
This commit is contained in:
parent
75a1a47859
commit
45455b33c0
|
|
@ -188,10 +188,9 @@ impl CandidateSelector {
|
||||||
.filter(|(marker, _index, _version)| !env.included_by_marker(marker.pep508()));
|
.filter(|(marker, _index, _version)| !env.included_by_marker(marker.pep508()));
|
||||||
let preferences = preferences_match.chain(preferences_mismatch).filter_map(
|
let preferences = preferences_match.chain(preferences_mismatch).filter_map(
|
||||||
|(marker, source, version)| {
|
|(marker, source, version)| {
|
||||||
// If the package is mapped to an explicit index, only consider preferences that
|
// Ignore preferences that are associated with conflicting indexes.
|
||||||
// match the index.
|
|
||||||
index
|
index
|
||||||
.map_or(true, |index| source == Some(index))
|
.is_none_or(|index| source.is_none_or(|source| source == index))
|
||||||
.then_some((marker, version))
|
.then_some((marker, version))
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -14345,3 +14345,51 @@ fn max_python_requirement() -> Result<()> {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// See: <https://github.com/astral-sh/uv/issues/10383>
|
||||||
|
#[test]
|
||||||
|
fn respect_index_preference() -> Result<()> {
|
||||||
|
let context = TestContext::new("3.12");
|
||||||
|
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||||
|
pyproject_toml.write_str(indoc::indoc! {r#"
|
||||||
|
[project]
|
||||||
|
name = "project"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = ["iniconfig>=1", "typing-extensions>=4"]
|
||||||
|
|
||||||
|
[[tool.uv.index]]
|
||||||
|
name = "pypi"
|
||||||
|
url = "https://pypi.org/simple"
|
||||||
|
explicit = true
|
||||||
|
|
||||||
|
[tool.uv.sources]
|
||||||
|
iniconfig = { index = "pypi" }
|
||||||
|
"#})?;
|
||||||
|
|
||||||
|
let requirements_txt = context.temp_dir.child("requirements.txt");
|
||||||
|
requirements_txt.write_str(indoc::indoc! {r"
|
||||||
|
iniconfig==1.1.1
|
||||||
|
typing-extensions==4.6.0
|
||||||
|
"})?;
|
||||||
|
|
||||||
|
uv_snapshot!(context
|
||||||
|
.pip_compile()
|
||||||
|
.arg("pyproject.toml")
|
||||||
|
.arg("-o")
|
||||||
|
.arg("requirements.txt"), @r###"
|
||||||
|
success: true
|
||||||
|
exit_code: 0
|
||||||
|
----- stdout -----
|
||||||
|
# This file was autogenerated by uv via the following command:
|
||||||
|
# uv pip compile --cache-dir [CACHE_DIR] pyproject.toml -o requirements.txt
|
||||||
|
iniconfig==1.1.1
|
||||||
|
# via project (pyproject.toml)
|
||||||
|
typing-extensions==4.6.0
|
||||||
|
# via project (pyproject.toml)
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
Resolved 2 packages in [TIME]
|
||||||
|
"###);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue