Improve display of Python versions (#1029)

In https://github.com/astral-sh/puffin/pull/986 there was some confusion
about what these values are set to and I noticed that we never actually
display the target version being used for a resolution.

- Consistently display the Python interpreter being used, i.e. make it
clear that we are referring the the interpreter/installed Python version
and always show the version number
- Display the target Python version during solving
This commit is contained in:
Zanie Blue 2024-01-22 12:46:18 -06:00 committed by GitHub
parent e6f5c8360c
commit e21948f353
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 34 additions and 21 deletions

View file

@ -257,6 +257,11 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
FxHashMap::default();
let mut next = root;
debug!(
"Solving with target Python version {}",
self.python_requirement.target()
);
loop {
// Run unit propagation.
state.unit_propagation(next)?;

View file

@ -18,14 +18,16 @@ use crate::printer::Printer;
pub(crate) fn freeze(cache: &Cache, strict: bool, mut printer: Printer) -> Result<ExitStatus> {
// Detect the current Python interpreter.
let platform = Platform::current()?;
let python = Virtualenv::from_env(platform, cache)?;
let venv = Virtualenv::from_env(platform, cache)?;
debug!(
"Using Python interpreter: {}",
python.python_executable().display()
"Using Python {} environment at {}",
venv.interpreter().python_version(),
venv.python_executable().display().cyan()
);
// Build the installed index.
let site_packages = SitePackages::from_executable(&python)?;
let site_packages = SitePackages::from_executable(&venv)?;
for dist in site_packages
.iter()
.sorted_unstable_by(|a, b| a.name().cmp(b.name()))

View file

@ -125,11 +125,10 @@ pub(crate) async fn pip_compile(
// Detect the current Python interpreter.
let platform = Platform::current()?;
let interpreter = Interpreter::find(python_version.as_ref(), platform, &cache)?;
debug!(
"Using Python {} at {}",
interpreter.markers().python_version,
interpreter.sys_executable().display()
"Using Python {} interpreter at {} for builds",
interpreter.python_version(),
interpreter.sys_executable().display().cyan()
);
// Create a shared in-memory index.
@ -258,6 +257,7 @@ pub(crate) async fn pip_compile(
&build_dispatch,
)
.with_reporter(ResolverReporter::from(printer));
let resolution = match resolver.resolve().await {
Err(puffin_resolver::ResolveError::NoSolution(err)) => {
#[allow(clippy::print_stderr)]

View file

@ -89,9 +89,11 @@ pub(crate) async fn pip_install(
let platform = Platform::current()?;
let venv = Virtualenv::from_env(platform, &cache)?;
debug!(
"Using Python interpreter: {}",
venv.python_executable().display()
"Using Python {} environment at {}",
venv.interpreter().python_version(),
venv.python_executable().display().cyan()
);
let _lock = venv.lock()?;
// Determine the set of installed packages.

View file

@ -54,9 +54,11 @@ pub(crate) async fn pip_sync(
let platform = Platform::current()?;
let venv = Virtualenv::from_env(platform, &cache)?;
debug!(
"Using Python interpreter: {}",
venv.python_executable().display()
"Using Python {} environment at {}",
venv.interpreter().python_version(),
venv.python_executable().display().cyan()
);
let _lock = venv.lock()?;
// Determine the current environment markers.

View file

@ -28,9 +28,11 @@ pub(crate) async fn pip_uninstall(
let platform = Platform::current()?;
let venv = Virtualenv::from_env(platform, &cache)?;
debug!(
"Using Python interpreter: {}",
venv.python_executable().display()
"Using Python {} environment at {}",
venv.interpreter().python_version(),
venv.python_executable().display().cyan()
);
let _lock = venv.lock()?;
// Index the current `site-packages` directory.

View file

@ -106,7 +106,7 @@ async fn venv_impl(
writeln!(
printer,
"Using Python {} at {}",
"Using Python {} interpreter at {}",
interpreter.python_version(),
interpreter.sys_executable().display().cyan()
)

View file

@ -18,7 +18,7 @@ fn create_venv() -> Result<()> {
insta::with_settings!({
filters => vec![
(r"Using Python 3\.\d+\.\d+ at .+", "Using Python [VERSION] at [PATH]"),
(r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]"),
(temp_dir.to_str().unwrap(), "/home/ferris/project"),
]
}, {
@ -33,7 +33,7 @@ fn create_venv() -> Result<()> {
----- stdout -----
----- stderr -----
Using Python [VERSION] at [PATH]
Using Python [VERSION] interpreter at [PATH]
Creating virtual environment at: /home/ferris/project/.venv
"###);
});
@ -50,7 +50,7 @@ fn create_venv_defaults_to_cwd() -> Result<()> {
insta::with_settings!({
filters => vec![
(r"Using Python 3\.\d+\.\d+ at .+", "Using Python [VERSION] at [PATH]"),
(r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]"),
(temp_dir.to_str().unwrap(), "/home/ferris/project"),
]
}, {
@ -64,7 +64,7 @@ fn create_venv_defaults_to_cwd() -> Result<()> {
----- stdout -----
----- stderr -----
Using Python [VERSION] at [PATH]
Using Python [VERSION] interpreter at [PATH]
Creating virtual environment at: .venv
"###);
});
@ -81,7 +81,7 @@ fn seed() -> Result<()> {
insta::with_settings!({
filters => vec![
(r"Using Python 3\.\d+\.\d+ at .+", "Using Python [VERSION] at [PATH]"),
(r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]"),
(temp_dir.to_str().unwrap(), "/home/ferris/project"),
]
}, {
@ -97,7 +97,7 @@ fn seed() -> Result<()> {
----- stdout -----
----- stderr -----
Using Python [VERSION] at [PATH]
Using Python [VERSION] interpreter at [PATH]
Creating virtual environment at: /home/ferris/project/.venv
+ setuptools==69.0.3
+ pip==23.3.2