Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable freeze and list to introspect non-virtualenv Pythons #2033

Merged
merged 1 commit into from
Feb 28, 2024

Conversation

charliermarsh
Copy link
Member

Summary

Now that we have the ability to introspect the installed packages for arbitrary Pythons, we can allow pip freeze and pip list to fall back to the "default" Python, if no virtualenv is present.

Closes #2005.

@charliermarsh charliermarsh changed the title Enable freeze and list to enumerate default Python installs Enable freeze and list to introspect non-virtualenv Pythons Feb 28, 2024
@charliermarsh charliermarsh added the compatibility Compatibility with a specification or another tool label Feb 28, 2024
match Virtualenv::from_env(platform.clone(), cache) {
Ok(venv) => venv,
Err(uv_interpreter::Error::VenvNotFound) => {
Virtualenv::from_default_python(&platform, cache)?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does mean that if a virtualenv doesn't exist, we "silently" fall back to the default Python; and you'll never see the "No virtualenv exists" error, only the error you might get if the fallback fails.

It kind of makes me want to change this to user-facing logging?

debug!(
    "Using Python {} environment at {}",
    venv.interpreter().python_version(),
    venv.python_executable().normalized_display().cyan()
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

match Virtualenv::from_env(platform.clone(), cache) {
Ok(venv) => venv,
Err(uv_interpreter::Error::VenvNotFound) => {
Virtualenv::from_default_python(&platform, cache)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

/// The Python interpreter for which packages should be listed.
///
/// By default, `uv` lists packages in the currently activated virtual environment, or an
/// environment located in the current working directory or any parent directory, falling back
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// environment located in the current working directory or any parent directory, falling back
/// environment `.venv` located in the current working directory or any parent directory, falling back

///
/// Supported formats:
/// - `3.10` looks for an installed Python 3.10 using `py --list-paths` on Windows, or
/// `python3.10` on Linux and macOS. (Specifying a patch version is not supported.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patch versions are supported

Base automatically changed from charlie/py to main February 28, 2024 14:48
@charliermarsh charliermarsh merged commit 0270328 into main Feb 28, 2024
7 checks passed
@charliermarsh charliermarsh deleted the charlie/freeze branch February 28, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility with a specification or another tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UV pip list does not give system package list.
2 participants