Add pip compile test where specific Python versions are available on the system (#1111)

Extends https://github.com/astral-sh/puffin/pull/1106 with the scenario
from https://github.com/zanieb/packse/pull/95 which tests that `pip
compile` will use the matching system Python version for builds when
available
This commit is contained in:
Zanie Blue
2024-01-26 12:38:24 -06:00
committed by GitHub
parent 91f421cf97
commit 5cc4e5d31e
4 changed files with 144 additions and 15 deletions
+27 -3
View File
@@ -5,16 +5,38 @@
//!
#![cfg(all(feature = "python", feature = "pypi"))]
use std::path::PathBuf;
use std::process::Command;
use anyhow::Result;
use assert_fs::fixture::{FileWriteStr, PathChild};
use common::{create_venv, BIN_NAME, INSTA_FILTERS};
#[cfg(unix)]
use fs_err::os::unix::fs::symlink as symlink_file;
#[cfg(windows)]
use fs_err::os::windows::fs::symlink_file;
use insta_cmd::_macro_support::insta;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
use common::{create_venv, BIN_NAME, INSTA_FILTERS};
use puffin_interpreter::find_requested_python;
mod common;
/// Create a directory with the requested Python binaries available.
pub(crate) fn create_bin_with_executables(
temp_dir: &assert_fs::TempDir,
python: Vec<&str>,
) -> Result<PathBuf> {
let bin = temp_dir.child("bin");
fs_err::create_dir(&bin)?;
for request in python {
let executable = find_requested_python(request)?;
let name = executable
.file_name()
.expect("Discovered executable must have a filename");
symlink(&executable, bin.child(name))?;
}
Ok(bin.canonicalize()?)
}
{{#scenarios}}
/// {{name}}
@@ -34,6 +56,8 @@ fn {{module_name}}() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = create_venv(&temp_dir, &cache_dir, "{{environment.python}}");
let python_versions = vec![{{#environment.additional_python}}"{{.}}", {{/environment.additional_python}}];
let bin = create_bin_with_executables(&temp_dir, python_versions)?;
// In addition to the standard filters, swap out package names for more realistic messages
let mut filters = INSTA_FILTERS.to_vec();
@@ -69,7 +93,7 @@ fn {{module_name}}() -> Result<()> {
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.env("PUFFIN_NO_WRAP", "1")
.env("PUFFIN_PYTHON_PATH", "")
.env("PUFFIN_PYTHON_PATH", bin)
.current_dir(&temp_dir), @r###"<snapshot>
"###);
});
+1 -1
View File
@@ -45,7 +45,7 @@ import textwrap
from pathlib import Path
PACKSE_COMMIT = "e944cb4c8f5d68457d0462ee19106509f63b8d34"
PACKSE_COMMIT = "a451c95105db0c2897d0ad1bde0703ba0fc40d3a"
TOOL_ROOT = Path(__file__).parent
TEMPLATES = TOOL_ROOT / "templates"
INSTALL_TEMPLATE = TEMPLATES / "install.mustache"