diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 63bae33d00be..bfc03a2be0b8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: diff --git a/crates/puffin-cli/tests/pip_compile.rs b/crates/puffin-cli/tests/pip_compile.rs index e75427f9374f..a1d8b4935e66 100644 --- a/crates/puffin-cli/tests/pip_compile.rs +++ b/crates/puffin-cli/tests/pip_compile.rs @@ -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 #[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"); @@ -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(()) } diff --git a/crates/puffin-cli/tests/pip_sync.rs b/crates/puffin-cli/tests/pip_sync.rs index 5161b5ab13e8..001fd730e79b 100644 --- a/crates/puffin-cli/tests/pip_sync.rs +++ b/crates/puffin-cli/tests/pip_sync.rs @@ -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 #[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"); @@ -942,7 +942,7 @@ 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) @@ -950,20 +950,6 @@ fn install_numpy_py37() -> Result<()> { .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")?; diff --git a/crates/puffin-cli/tests/snapshots/pip_compile__compile_constraints_markers.snap b/crates/puffin-cli/tests/snapshots/pip_compile__compile_constraints_markers.snap index 070d5bf3201b..58972ccecfc2 100644 --- a/crates/puffin-cli/tests/snapshots/pip_compile__compile_constraints_markers.snap +++ b/crates/puffin-cli/tests/snapshots/pip_compile__compile_constraints_markers.snap @@ -8,9 +8,9 @@ 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 @@ -18,11 +18,13 @@ exit_code: 0 # 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] diff --git a/crates/puffin-cli/tests/snapshots/pip_compile__compile_constraints_txt.snap b/crates/puffin-cli/tests/snapshots/pip_compile__compile_constraints_txt.snap index e2b3adf725e5..39e6cc1cac07 100644 --- a/crates/puffin-cli/tests/snapshots/pip_compile__compile_constraints_txt.snap +++ b/crates/puffin-cli/tests/snapshots/pip_compile__compile_constraints_txt.snap @@ -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 @@ -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] diff --git a/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml.snap b/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml.snap index 1ace0bbb35f3..9760080af339 100644 --- a/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml.snap +++ b/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml.snap @@ -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 @@ -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] diff --git a/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml_all_extras.snap b/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml_all_extras.snap index 2e65eb521d31..273970671e74 100644 --- a/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml_all_extras.snap +++ b/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml_all_extras.snap @@ -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 @@ -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 @@ -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] diff --git a/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml_extra.snap b/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml_extra.snap index 78e32bbacef9..73f1e2c7710d 100644 --- a/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml_extra.snap +++ b/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml_extra.snap @@ -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 @@ -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] diff --git a/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml_extra_name_normalization.snap b/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml_extra_name_normalization.snap index 5eac4f49f1de..dae69a364c97 100644 --- a/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml_extra_name_normalization.snap +++ b/crates/puffin-cli/tests/snapshots/pip_compile__compile_pyproject_toml_extra_name_normalization.snap @@ -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 @@ -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] diff --git a/crates/puffin-cli/tests/snapshots/pip_compile__compile_python_37.snap b/crates/puffin-cli/tests/snapshots/pip_compile__compile_python_37.snap index ec4e94eb422b..288ba44826d0 100644 --- a/crates/puffin-cli/tests/snapshots/pip_compile__compile_python_37.snap +++ b/crates/puffin-cli/tests/snapshots/pip_compile__compile_python_37.snap @@ -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. diff --git a/crates/puffin-cli/tests/snapshots/pip_compile__compile_requirements_in.snap b/crates/puffin-cli/tests/snapshots/pip_compile__compile_requirements_in.snap index 04474bfc932c..15ee38575163 100644 --- a/crates/puffin-cli/tests/snapshots/pip_compile__compile_requirements_in.snap +++ b/crates/puffin-cli/tests/snapshots/pip_compile__compile_requirements_in.snap @@ -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 @@ -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] diff --git a/crates/puffin-cli/tests/snapshots/pip_sync__install_numpy_py37.snap b/crates/puffin-cli/tests/snapshots/pip_sync__install_numpy_py38.snap similarity index 72% rename from crates/puffin-cli/tests/snapshots/pip_sync__install_numpy_py37.snap rename to crates/puffin-cli/tests/snapshots/pip_sync__install_numpy_py38.snap index fbcec7ef732a..a7d0072a3f63 100644 --- a/crates/puffin-cli/tests/snapshots/pip_sync__install_numpy_py37.snap +++ b/crates/puffin-cli/tests/snapshots/pip_sync__install_numpy_py38.snap @@ -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 @@ -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 diff --git a/crates/puffin-resolver/src/finder.rs b/crates/puffin-resolver/src/finder.rs index ab399b51ef4e..7f26d1f6f2e4 100644 --- a/crates/puffin-resolver/src/finder.rs +++ b/crates/puffin-resolver/src/finder.rs @@ -136,6 +136,20 @@ impl<'a> DistFinder<'a> { fn select(&self, requirement: &Requirement, files: Vec) -> Option { 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; @@ -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)); } } } diff --git a/crates/puffin-resolver/src/resolver.rs b/crates/puffin-resolver/src/resolver.rs index 20543c577211..17aceb395d97 100644 --- a/crates/puffin-resolver/src/resolver.rs +++ b/crates/puffin-resolver/src/resolver.rs @@ -536,6 +536,21 @@ impl<'a, Context: BuildContext + Sync> Resolver<'a, Context> { // distributions. let mut version_map: VersionMap = BTreeMap::new(); for file in metadata.files { + // 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.build_context.interpreter_info().version()) + }) + { + continue; + } if let Ok(filename) = WheelFilename::from_str(file.filename.as_str()) { if filename.is_compatible(self.tags) { let version = PubGrubVersion::from(filename.version.clone()); @@ -554,22 +569,11 @@ impl<'a, Context: BuildContext + Sync> Resolver<'a, Context> { } else if let Ok(filename) = SourceDistFilename::parse(file.filename.as_str(), &package_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.build_context.interpreter_info().version()) - }) + let version = PubGrubVersion::from(filename.version.clone()); + if let std::collections::btree_map::Entry::Vacant(entry) = + version_map.entry(version) { - let version = PubGrubVersion::from(filename.version.clone()); - if let std::collections::btree_map::Entry::Vacant(entry) = - version_map.entry(version) - { - entry.insert(DistFile::from(SdistFile(file))); - } + entry.insert(DistFile::from(SdistFile(file))); } } }