Skip to content

Commit

Permalink
And the wheels, too
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Nov 13, 2023
1 parent d78a1a8 commit fac7362
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
# TODO(konstin): Mock the venv in the installer test so we don't need this anymore
- uses: actions/setup-python@v4
with:
python-version: '3.7'
python-version: '3.8'
- name: "Install Python"
uses: actions/setup-python@v4
with:
Expand Down
34 changes: 18 additions & 16 deletions crates/puffin-cli/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,10 @@ fn compile_python_37() -> Result<()> {
Ok(())
}

/// Test that we select the last 3.7 compatible numpy version instead of trying to compile an
/// Test that we select the last 3.8 compatible numpy version instead of trying to compile an
/// incompatible sdist <https://github.com/astral-sh/puffin/issues/388>
#[test]
fn compile_numpy_py37() -> Result<()> {
fn compile_numpy_py38() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Expand All @@ -653,28 +653,30 @@ fn compile_numpy_py37() -> Result<()> {
requirements_in.write_str("numpy")?;

insta::with_settings!({
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-compile")
.arg("requirements.in")
.arg("--python-version")
.arg("py37")
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.current_dir(&temp_dir), @r###"
filters => INSTA_FILTERS.to_vec()
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-compile")
.arg("requirements.in")
.arg("--python-version")
.arg("py38")
.arg("--cache-dir")
.arg(cache_dir.path())
// Check that we select the wheel and not the sdist
.arg("--no-build")
.env("VIRTUAL_ENV", venv.as_os_str())
.current_dir(&temp_dir), @r###"
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 --python-version py37 --cache-dir [CACHE_DIR]
numpy==1.26.2
# [BIN_PATH] pip-compile requirements.in --python-version py38 --cache-dir [CACHE_DIR]
numpy==1.24.4
----- stderr -----
Resolved 1 package in [TIME]
"###);
});
});

Ok(())
}
Expand Down
20 changes: 3 additions & 17 deletions crates/puffin-cli/tests/pip_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,10 +929,10 @@ fn install_version_then_install_url() -> Result<()> {
Ok(())
}

/// Test that we select the last 3.7 compatible numpy version instead of trying to compile an
/// Test that we select the last 3.8 compatible numpy version instead of trying to compile an
/// incompatible sdist <https://github.com/astral-sh/puffin/issues/388>
#[test]
fn install_numpy_py37() -> Result<()> {
fn install_numpy_py38() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Expand All @@ -942,28 +942,14 @@ fn install_numpy_py37() -> Result<()> {
.arg(venv.as_os_str())
.arg("--python")
// TODO(konstin): Mock the venv in the installer test so we don't need this anymore
.arg(which::which("python3.7").context("python3.7 must be installed")?)
.arg(which::which("python3.8").context("python3.8 must be installed")?)
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());

let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
requirements_txt.write_str("werkzeug==2.0.0")?;

Command::new(get_cargo_bin(BIN_NAME))
.arg("pip-sync")
.arg("requirements.txt")
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.current_dir(&temp_dir)
.assert()
.success();

let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
requirements_txt.write_str("numpy")?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ info:
- "--constraint"
- constraints.txt
- "--cache-dir"
- /var/folders/bc/qlsk3t6x7c9fhhbvvcg68k9c0000gp/T/.tmp1Ts53o
- /tmp/.tmpzpwtXx
env:
VIRTUAL_ENV: /var/folders/bc/qlsk3t6x7c9fhhbvvcg68k9c0000gp/T/.tmp1vzBQa/.venv
VIRTUAL_ENV: /tmp/.tmpwo1pOb/.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
exceptiongroup==1.1.3
# via anyio
idna==3.4
# via anyio
sniffio==1.3.0
# via anyio

----- stderr -----
Resolved 3 packages in [TIME]
Resolved 4 packages in [TIME]

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ info:
- "--constraint"
- constraints.txt
- "--cache-dir"
- /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpvjdHOb
- /tmp/.tmp9F1Ljq
env:
VIRTUAL_ENV: /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpSAaWi3/.venv
VIRTUAL_ENV: /tmp/.tmpNJjhiS/.venv
---
success: true
exit_code: 0
Expand All @@ -22,7 +22,9 @@ asgiref==3.7.2
django==5.0b1
sqlparse==0.4.3
# via django
typing-extensions==4.8.0
# via asgiref

----- stderr -----
Resolved 3 packages in [TIME]
Resolved 4 packages in [TIME]

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ info:
- pip-compile
- pyproject.toml
- "--cache-dir"
- /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpOOTFwj
- /tmp/.tmphqsdmA
env:
VIRTUAL_ENV: /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpU0VXyY/.venv
VIRTUAL_ENV: /tmp/.tmpvlroQ4/.venv
---
success: true
exit_code: 0
Expand All @@ -20,7 +20,9 @@ asgiref==3.7.2
django==5.0b1
sqlparse==0.4.4
# via django
typing-extensions==4.8.0
# via asgiref

----- stderr -----
Resolved 3 packages in [TIME]
Resolved 4 packages in [TIME]

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ info:
- pyproject.toml
- "--all-extras"
- "--cache-dir"
- /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpFzJKRe
- /tmp/.tmpLq97XV
env:
VIRTUAL_ENV: /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpdadcmu/.venv
VIRTUAL_ENV: /tmp/.tmpj8K855/.venv
---
success: true
exit_code: 0
Expand All @@ -23,6 +23,8 @@ asgiref==3.7.2
certifi==2023.7.22
# via httpcore
django==5.0b1
exceptiongroup==1.1.3
# via anyio
h11==0.14.0
# via httpcore
httpcore==0.18.0
Expand All @@ -34,7 +36,9 @@ sniffio==1.3.0
# httpcore
sqlparse==0.4.4
# via django
typing-extensions==4.8.0
# via asgiref

----- stderr -----
Resolved 9 packages in [TIME]
Resolved 11 packages in [TIME]

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ info:
- "--extra"
- foo
- "--cache-dir"
- /var/folders/bc/qlsk3t6x7c9fhhbvvcg68k9c0000gp/T/.tmpAYEAdM
- /tmp/.tmpvkwe04
env:
VIRTUAL_ENV: /var/folders/bc/qlsk3t6x7c9fhhbvvcg68k9c0000gp/T/.tmp1xuOcV/.venv
VIRTUAL_ENV: /tmp/.tmpMFDom0/.venv
---
success: true
exit_code: 0
Expand All @@ -22,7 +22,9 @@ asgiref==3.7.2
django==5.0b1
sqlparse==0.4.4
# via django
typing-extensions==4.8.0
# via asgiref

----- stderr -----
Resolved 3 packages in [TIME]
Resolved 4 packages in [TIME]

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ info:
- "--extra"
- FRiENDlY-...-_-BARd
- "--cache-dir"
- /var/folders/bc/qlsk3t6x7c9fhhbvvcg68k9c0000gp/T/.tmpFyLXQn
- /tmp/.tmpVf4Xxi
env:
VIRTUAL_ENV: /var/folders/bc/qlsk3t6x7c9fhhbvvcg68k9c0000gp/T/.tmpxfZatv/.venv
VIRTUAL_ENV: /tmp/.tmpM4Yfd8/.venv
---
success: true
exit_code: 0
Expand All @@ -22,7 +22,9 @@ asgiref==3.7.2
django==5.0b1
sqlparse==0.4.4
# via django
typing-extensions==4.8.0
# via asgiref

----- stderr -----
Resolved 3 packages in [TIME]
Resolved 4 packages in [TIME]

Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,16 @@ info:
- "--python-version"
- py37
- "--cache-dir"
- /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpzwzUVe
- /tmp/.tmpHz7Dc2
env:
VIRTUAL_ENV: /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpqFv4YL/.venv
VIRTUAL_ENV: /tmp/.tmpoMjDJT/.venv
---
success: true
exit_code: 0
success: false
exit_code: 1
----- stdout -----
# This file was autogenerated by Puffin v0.0.1 via the following command:
# [BIN_PATH] pip-compile requirements.in --python-version py37 --cache-dir [CACHE_DIR]
black==23.10.1
click==8.1.7
# via black
importlib-metadata==6.8.0
# via click
mypy-extensions==1.0.0
# via black
packaging==23.2
# via black
pathspec==0.11.2
# via black
platformdirs==4.0.0
# via black
tomli==2.0.1
# via black
typing-extensions==4.8.0
# via
# black
# importlib-metadata
# platformdirs
zipp==3.17.0
# via importlib-metadata

----- stderr -----
Resolved 10 packages in [TIME]
× No solution found when resolving dependencies:
╰─▶ Because there is no version of black available matching ==23.10.1 and
root depends on black==23.10.1, version solving failed.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ info:
- pip-compile
- requirements.in
- "--cache-dir"
- /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpxF1zFY
- /tmp/.tmpNz0KIo
env:
VIRTUAL_ENV: /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmp33QZdv/.venv
VIRTUAL_ENV: /tmp/.tmpyQ2rTA/.venv
---
success: true
exit_code: 0
Expand All @@ -20,7 +20,9 @@ asgiref==3.7.2
django==5.0b1
sqlparse==0.4.4
# via django
typing-extensions==4.8.0
# via asgiref

----- stderr -----
Resolved 3 packages in [TIME]
Resolved 4 packages in [TIME]

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ info:
- pip-sync
- requirements.txt
- "--cache-dir"
- /tmp/.tmpQ4q9dh
- /tmp/.tmpL9E9fl
env:
VIRTUAL_ENV: /tmp/.tmp6vLqVn/.venv
VIRTUAL_ENV: /tmp/.tmp0yDHj5/.venv
---
success: true
exit_code: 0
Expand All @@ -18,8 +18,6 @@ exit_code: 0
Resolved 1 package in [TIME]
Downloaded 1 package in [TIME]
Unzipped 1 package in [TIME]
Uninstalled 1 package in [TIME]
Installed 1 package in [TIME]
+ numpy==1.21.6
- werkzeug==2.0.0
+ numpy==1.24.4

28 changes: 16 additions & 12 deletions crates/puffin-resolver/src/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ impl<'a> DistFinder<'a> {
fn select(&self, requirement: &Requirement, files: Vec<File>) -> Option<Dist> {
let mut fallback = None;
for file in files.into_iter().rev() {
// Only add dists compatible with the python version.
// This is relevant for source dists which give no other indication of their
// compatibility and wheels which may be tagged `py3-none-any` but
// have `requires-python: ">=3.9"`
// TODO(konstin): https://github.com/astral-sh/puffin/issues/406
if !file
.requires_python
.as_ref()
.map_or(true, |requires_python| {
requires_python.contains(self.interpreter_info.version())
})
{
continue;
}
if let Ok(wheel) = WheelFilename::from_str(file.filename.as_str()) {
if !wheel.is_compatible(self.tags) {
continue;
Expand All @@ -146,18 +160,8 @@ impl<'a> DistFinder<'a> {
} else if let Ok(sdist) =
SourceDistFilename::parse(file.filename.as_str(), &requirement.name)
{
// Only add source dists compatible with the python version
// TODO(konstin): https://github.com/astral-sh/puffin/issues/406
if file
.requires_python
.as_ref()
.map_or(true, |requires_python| {
requires_python.contains(self.interpreter_info.version())
})
{
if requirement.is_satisfied_by(&sdist.version) {
fallback = Some(Dist::from_registry(sdist.name, sdist.version, file));
}
if requirement.is_satisfied_by(&sdist.version) {
fallback = Some(Dist::from_registry(sdist.name, sdist.version, file));
}
}
}
Expand Down
Loading

0 comments on commit fac7362

Please sign in to comment.