-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Implement --user
flag and user scheme support for uv pip
#2352
Conversation
* to use requested python, virtualenv and default python in order * ensure the scheme directories exist
Co-authored-by: konsti <konstin@mailbox.org>
This looks like a nice PR! The main blocker is that I need to decide if we want to support |
pub(crate) fn query_user_scheme_info(interpreter: &Path) -> Result<Self, Error> { | ||
let script = include_str!("get_interpreter_info.py"); | ||
let envs = vec![("_UV_USE_USER_SCHEME", "1")]; | ||
let output = Self::execute_script(interpreter, script, Some(envs))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this intentionally not cache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noticed that query_cached
uses the executable's last modified time
as a cache key. In the case of user scheme, the interpreter may remain the same, e.g. the system Python interpreter, but the InterpreterInfo.scheme
changes to the user site, e.g. ~/.local
.
I will take a further look into using uv_cache
to cache the script execution here.
Again, just want to say: this is very nice work! In fact I'm more inclined to support this now that we have a nice PR for it. But I do want to understand the implications a little more first. |
// <https://github.com/pypa/pip/blob/a33caa26f2bf525eafb4ec004f9c1bd18d238a31/src/pip/_internal/commands/install.py#L686> | ||
if user | ||
&& venv.interpreter().is_virtualenv() | ||
&& !venv.cfg().unwrap().include_system_site_packages() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use is_some_and
or unwrap_or
here instead of unwrapping?
Thank you for the comments 😄
It seems there might be some confusion stemming from an issue discussed here: #2077 (comment)
As far as i know, both I don't have the full context so the complexity might arise specifically in the context of using Airflow. It would be great if the author of that comment could provide some further details. For reference, I conducted a quick local test combining the
|
There's some more discussion on this active in #2077 |
I may expand the section on |
Is there any blocker that requires some help to merge this PR? |
In #2077, there were extensive discussions, and from what I gathered, it seemed the I kept this PR open in case things change, and if the |
This comment was marked as off-topic.
This comment was marked as off-topic.
@Malix-off can you please discuss this on the issue instead of this pull request? I'd prefer to keep the discussion here focused on implementation details. Thanks. |
This comment was marked as resolved.
This comment was marked as resolved.
Noticed that |
Summary
Hi team, excited for your awesome work of
uv
.This PR attempts to implement
--user
flag foruv pip
subcommands:install
,freeze
,list
andshow
.Closes #2077
also #1584
Per PEP 370 – Per user site-packages directory,
pip
supports user scheme package installation which would be useful for multi-user environment or CI use cases without the need of virtual environment or breaking system Python packages.Example usage:
Implementation details
The implementation aims to bring minimal changes to the existing functionalities of
uv pip
, as well as supporting--user
for pip compatibility.Here are some breakdowns of the implementation:
_infer_user()
tocrates/uv-interpreter/src/get_interpreter_info.py
which returns the user scheme if specifiedPythonEnvironment::from_user_scheme()
which queries the interpreter info with user scheme, thus theplatlib
,purelib
,scripts
,data
andinclude
should point to the user siteuv pip
subcommands when the--user
flag is present, making the subcommands use only the user site for package search and installation.Right now the implementation doesn't include the global packages mentioned in User Installs since we only consider site packages from the
scheme.purelib
. I'm thinking about adding that later for better compatibility withpip install
.I am new to
uv
, looking forward to the team's feedback and suggestions :)Test Plan
May need some advice and guidance on what's the best practice on testing this.