mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
parent
8123e1a8f6
commit
b8ff32f6be
3 changed files with 82 additions and 11 deletions
|
@ -228,6 +228,56 @@ fn compile_constraints_inline() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resolve a package from a `requirements.in` file, with a `constraints.txt` file that
|
||||||
|
/// uses markers.
|
||||||
|
#[test]
|
||||||
|
fn compile_constraints_markers() -> Result<()> {
|
||||||
|
let temp_dir = assert_fs::TempDir::new()?;
|
||||||
|
let cache_dir = assert_fs::TempDir::new()?;
|
||||||
|
let venv = temp_dir.child(".venv");
|
||||||
|
|
||||||
|
Command::new(get_cargo_bin(BIN_NAME))
|
||||||
|
.arg("venv")
|
||||||
|
.arg(venv.as_os_str())
|
||||||
|
.arg("--cache-dir")
|
||||||
|
.arg(cache_dir.path())
|
||||||
|
.current_dir(&temp_dir)
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
venv.assert(predicates::path::is_dir());
|
||||||
|
|
||||||
|
let requirements_in = temp_dir.child("requirements.in");
|
||||||
|
requirements_in.touch()?;
|
||||||
|
requirements_in.write_str("anyio")?;
|
||||||
|
|
||||||
|
// Constrain a transitive dependency based on the Python version
|
||||||
|
let constraints_txt = temp_dir.child("constraints.txt");
|
||||||
|
constraints_txt.touch()?;
|
||||||
|
// If constraints are ignored, these will conflict
|
||||||
|
constraints_txt.write_str("sniffio==1.2.0;python_version<='3.7'")?;
|
||||||
|
constraints_txt.write_str("sniffio==1.3.0;python_version>'3.7'")?;
|
||||||
|
|
||||||
|
insta::with_settings!({
|
||||||
|
filters => vec![
|
||||||
|
(r"(\d|\.)+(ms|s)", "[TIME]"),
|
||||||
|
(r"# .* pip-compile", "# [BIN_PATH] pip-compile"),
|
||||||
|
(r"--cache-dir .*", "--cache-dir [CACHE_DIR]"),
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||||
|
.arg("pip-compile")
|
||||||
|
.arg("requirements.in")
|
||||||
|
.arg("--constraint")
|
||||||
|
.arg("constraints.txt")
|
||||||
|
.arg("--cache-dir")
|
||||||
|
.arg(cache_dir.path())
|
||||||
|
.env("VIRTUAL_ENV", venv.as_os_str())
|
||||||
|
.current_dir(&temp_dir));
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Resolve a package from an optional dependency group in a `pyproject.toml` file.
|
/// Resolve a package from an optional dependency group in a `pyproject.toml` file.
|
||||||
#[test]
|
#[test]
|
||||||
fn compile_pyproject_toml_extra() -> Result<()> {
|
fn compile_pyproject_toml_extra() -> Result<()> {
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
---
|
||||||
|
source: crates/puffin-cli/tests/pip_compile.rs
|
||||||
|
info:
|
||||||
|
program: puffin
|
||||||
|
args:
|
||||||
|
- pip-compile
|
||||||
|
- requirements.in
|
||||||
|
- "--constraint"
|
||||||
|
- constraints.txt
|
||||||
|
- "--cache-dir"
|
||||||
|
- /var/folders/bc/qlsk3t6x7c9fhhbvvcg68k9c0000gp/T/.tmp1Ts53o
|
||||||
|
env:
|
||||||
|
VIRTUAL_ENV: /var/folders/bc/qlsk3t6x7c9fhhbvvcg68k9c0000gp/T/.tmp1vzBQa/.venv
|
||||||
|
---
|
||||||
|
success: true
|
||||||
|
exit_code: 0
|
||||||
|
----- stdout -----
|
||||||
|
# This file was autogenerated by Puffin v0.0.1 via the following command:
|
||||||
|
# [BIN_PATH] pip-compile requirements.in --constraint constraints.txt --cache-dir [CACHE_DIR]
|
||||||
|
anyio==4.0.0
|
||||||
|
idna==3.4
|
||||||
|
# via anyio
|
||||||
|
sniffio==1.3.0
|
||||||
|
# via anyio
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
Resolved 3 packages in [TIME]
|
||||||
|
|
|
@ -484,19 +484,12 @@ impl<'a, Context: BuildContext + Sync> Resolver<'a, Context> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Got constraints: {:#?}", constraints);
|
|
||||||
|
|
||||||
// If any requirements were further constrained by the user, add those constraints.
|
// If any requirements were further constrained by the user, add those constraints.
|
||||||
for constraint in &self.constraints {
|
for (package, version) in
|
||||||
let package = PubGrubPackage::Package(
|
iter_requirements(self.constraints.iter(), None, None, self.markers)
|
||||||
PackageName::normalize(&constraint.name),
|
{
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
if let Some(range) = constraints.get_mut(&package) {
|
if let Some(range) = constraints.get_mut(&package) {
|
||||||
*range = range.intersection(
|
*range = range.intersection(&version);
|
||||||
&version_range(constraint.version_or_url.as_ref()).unwrap(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue