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

pick up site packages from the interpreter's sys.path #2636

Closed
wants to merge 41 commits into from

Conversation

ChannyClaus
Copy link
Contributor

@ChannyClaus ChannyClaus commented Mar 23, 2024

Summary

Resolves #2500

This change got way bigger and more complex than initially thought 😭 (happy to break up into multiple smaller PRs if preferred!) - the main changes are as follows:

  • Expose sys.path from the chosen interpreter to be able to pick up more import paths beyond purelib / platlib
  • install from uv-dispatch to take an additional argument reinstall so that venv creation with --seed can always force reinstall (this seemed the least amount of change required to not break the behavior of --seed). This was necessary since uv will think pip already exists with this change (in the base interpreter) and would skip installing it for the venv.
  • (WIP) uv pip install with reinstall option seems to pick up site package paths multiple times
$ cargo run pip install homeassistant --reinstall --cache-dir chantest --verbose |& grep site
DEBUG Site packages: ["/Users/chan.kang/repos/.venv/lib/python3.12/site-packages"]
DEBUG Site packages: ["/Users/chan.kang/repos/uv/chantest/.tmpdROCqV/.venv/lib/python3.12/site-packages", "/Users/chan.kang/repos/.venv/lib/python3.12/site-packages"]

probably it should be done once for the lifetime of a single command invocation? still looking into it.

Test Plan

$ docker run -v /Users/chankang/repos/uv:/uv  $(docker build -q .)
Package    Version  Location                            Installer
---------- -------- ----------------------------------- ---------
dnf        4.19.0   /usr/lib/python3.12/site-packages
libcomps   0.1.20   /usr/lib64/python3.12/site-packages
libdnf     0.73.0   /usr/lib64/python3.12/site-packages
pip        23.2.1   /usr/lib/python3.12/site-packages   rpm
pyparsing  3.0.9    /usr/lib/python3.12/site-packages   rpm
rpm        4.19.1.1 /usr/lib64/python3.12/site-packages
setuptools 67.7.2   /usr/lib/python3.12/site-packages   rpm
Resolved 5 packages in 700ms
Downloaded 5 packages in 92ms
Installed 5 packages in 21ms
 + certifi==2024.2.2
 + charset-normalizer==3.3.2
 + idna==3.6
 + requests==2.31.0
 + urllib3==2.2.1
Package    Version
---------- --------
certifi    2024.2.2
dnf        4.19.0
idna       3.6
libdnf     0.73.0
pip        23.2.1
pyparsing  3.0.9
requests   2.31.0
setuptools 67.7.2
urllib3    2.2.1

where

$ cat Dockerfile 
FROM fedora:39

RUN yum update -y
RUN yum install pip python cmake perl rust cargo -y

COPY reproduce.sh .
ENTRYPOINT [ "bash", "reproduce.sh" ]
$ cat reproduce.sh 
pip list -v

cd uv && cargo run --quiet pip install requests --system && cargo run --quiet pip list --system

@ChannyClaus
Copy link
Contributor Author

ChannyClaus commented Mar 23, 2024

fixing CI and probably will add tests (it's turning out to be kinda non-trivial hmm, still looking though), should be done sometime today or tomorrow.

@@ -520,6 +520,7 @@ def main() -> None:
"prefix": sys.prefix,
"base_executable": getattr(sys, "_base_executable", None),
"sys_executable": sys.executable,
"sys_path": sys.path,
Copy link
Contributor

Choose a reason for hiding this comment

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

is it desirable for cwd to be in here? (if not, it should be removed, accounting for sys.flags.safe_path)

Copy link
Contributor Author

@ChannyClaus ChannyClaus Mar 25, 2024

Choose a reason for hiding this comment

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

probably will leave this value as is so that it still equals to sys.path (it may be confusing if it's called sys_path but the value returned isn't sys.path) - but added filtering via suffix site/dist packages where it's used.

@ChannyClaus
Copy link
Contributor Author

ChannyClaus commented Mar 25, 2024

taking longer than expected :.( - down to a couple of failing tests (having trouble reproducing it locally atm) + system setup jobs failing for windows, will continue to look.

@ChannyClaus
Copy link
Contributor Author

@zanieb do you happen to know why incompatible_python_compatible_override_available_no_wheels might be failing here? it seems to have succeeded for macos after rebase, but the identical code on my fork fails here

also on CI machines i've noticed if i run it multiple times, it only fails the first time and succeeds in all subsequent runs... 🤔

@ChannyClaus
Copy link
Contributor Author

😆 ok after rebasing this time it seems like the only failures are windows; i'll try to get these resolved this week.

@zanieb
Copy link
Member

zanieb commented Mar 29, 2024

What kind of problems are you having with the test suite? Have you merged main lately? We've recently improved the test snapshot filtering (i.e. #2678)

@ChannyClaus
Copy link
Contributor Author

What kind of problems are you having with the test suite? Have you merged main lately? We've recently improved the test snapshot filtering (i.e. #2678)

the most cryptic test started succeeding after rebasing a couple of times this week 🥲 i think i should be good once i figure out this windows issue (seemed like it can be resolved with something similar to fs::canonicalize)

thank you!

@@ -656,7 +657,7 @@ jobs:
yum install tar gzip which -y
- uses: actions/checkout@v4
- name: "Install Python"
run: yum install python3 python3-pip -y
run: yum install python3 -y && python3 -m ensurepip
Copy link
Contributor Author

@ChannyClaus ChannyClaus Mar 31, 2024

Choose a reason for hiding this comment

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

pip installed via yum install python3-pip has RECORD missing, which causes issues described in pypa/pip#11631 (this issue can be reproduced pulling the docker image used and running the command here)

@ChannyClaus
Copy link
Contributor Author

closing since this PR is too stale at this point

@ChannyClaus ChannyClaus closed this May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uv pip list / freeze / show --system do not show all system packages on Fedora
3 participants