Skip to content

Commit

Permalink
Improve display of Python versions (#1029)
Browse files Browse the repository at this point in the history
In #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
  • Loading branch information
zanieb authored Jan 22, 2024
1 parent e6f5c83 commit e21948f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 21 deletions.
5 changes: 5 additions & 0 deletions crates/puffin-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
10 changes: 6 additions & 4 deletions crates/puffin/src/commands/freeze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
8 changes: 4 additions & 4 deletions crates/puffin/src/commands/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)]
Expand Down
6 changes: 4 additions & 2 deletions crates/puffin/src/commands/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions crates/puffin/src/commands/pip_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions crates/puffin/src/commands/pip_uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion crates/puffin/src/commands/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand Down
12 changes: 6 additions & 6 deletions crates/puffin/tests/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
}, {
Expand All @@ -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
"###);
});
Expand All @@ -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"),
]
}, {
Expand All @@ -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
"###);
});
Expand All @@ -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"),
]
}, {
Expand All @@ -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
Expand Down

0 comments on commit e21948f

Please sign in to comment.