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

python list: don't list system interpreters twice when directories are symlinked #12302

Closed
gotmax23 opened this issue Mar 18, 2025 · 7 comments · Fixed by #12367
Closed

python list: don't list system interpreters twice when directories are symlinked #12302

gotmax23 opened this issue Mar 18, 2025 · 7 comments · Fixed by #12367
Labels
bug Something isn't working needs-decision Undecided if this should be done

Comments

@gotmax23
Copy link

Summary

$ cpython-3.13.2-linux-x86_64-gnu     /usr/bin/python3.13
cpython-3.13.2-linux-x86_64-gnu     /bin/python3.13
cpython-3.12.9-linux-x86_64-gnu     /usr/bin/python3.12
cpython-3.12.9-linux-x86_64-gnu     /usr/bin/python3 -> python3.12
cpython-3.12.9-linux-x86_64-gnu     /usr/bin/python -> ./python3
cpython-3.12.9-linux-x86_64-gnu     /bin/python3.12
cpython-3.12.9-linux-x86_64-gnu     /bin/python3 -> python3.12
cpython-3.12.9-linux-x86_64-gnu     /bin/python -> ./python3
cpython-3.11.11-linux-x86_64-gnu    /usr/bin/python3.11
cpython-3.11.11-linux-x86_64-gnu    /bin/python3.11
cpython-3.10.16-linux-x86_64-gnu    /usr/bin/python3.10
cpython-3.10.16-linux-x86_64-gnu    /bin/python3.10
cpython-3.9.21-linux-x86_64-gnu     /usr/bin/python3.9
cpython-3.9.21-linux-x86_64-gnu     /bin/python3.9
cpython-3.8.20-linux-x86_64-gnu     /usr/bin/python3.8
cpython-3.8.20-linux-x86_64-gnu     /bin/python3.8
cpython-3.7.9-linux-x86_64-gnu      .local/share/uv/python/cpython-3.7.9-linux-x86_64-gnu/bin/python3.7 -> python3.7m
pypy-3.10.16-linux-x86_64-gnu       /usr/bin/pypy3 -> pypy3.10
pypy-3.10.16-linux-x86_64-gnu       /bin/pypy3 -> pypy3.10
$ ls -ald /bin
lrwxrwxrwx. 1 root root 7 Jan 23  2024 /bin -> usr/bin

Platform

Linux 6.13.6-100.fc40.x86_64 x86_64 GNU/Linux

Version

uv 0.5.4

Python version

Python 3.12.9

@gotmax23 gotmax23 added the bug Something isn't working label Mar 18, 2025
@zanieb
Copy link
Member

zanieb commented Mar 18, 2025

Related

This is intentional, though this duplicate directory case is a fairly compelling one to de-duplicate (or a case to change the default).

@zanieb zanieb added the needs-decision Undecided if this should be done label Mar 18, 2025
@gotmax23
Copy link
Author

Got it. Not that on some distributions /bin, /sbin, and /usr/sbin are all symlinks to /usr/bin.

@zanieb
Copy link
Member

zanieb commented Mar 18, 2025

Yeah that seems far too noisy.

@gotmax23
Copy link
Author

Yeah that seems far too noisy.

Yup. For the record, this is what it looks like in a Fedora Rawhide container (that has the bin-sbin merge) with all the available Pythons installed:

cpython-3.14.0a6-linux-x86_64-gnu    /usr/sbin/python3.14
cpython-3.14.0a6-linux-x86_64-gnu    /usr/bin/python3.14
cpython-3.14.0a6-linux-x86_64-gnu    /sbin/python3.14
cpython-3.14.0a6-linux-x86_64-gnu    /bin/python3.14
cpython-3.13.2-linux-x86_64-gnu      /usr/sbin/python3.13
cpython-3.13.2-linux-x86_64-gnu      /usr/sbin/python3 -> python3.13
cpython-3.13.2-linux-x86_64-gnu      /usr/sbin/python -> ./python3
cpython-3.13.2-linux-x86_64-gnu      /usr/bin/python3.13
cpython-3.13.2-linux-x86_64-gnu      /usr/bin/python3 -> python3.13
cpython-3.13.2-linux-x86_64-gnu      /usr/bin/python -> ./python3
cpython-3.13.2-linux-x86_64-gnu      /sbin/python3.13
cpython-3.13.2-linux-x86_64-gnu      /sbin/python3 -> python3.13
cpython-3.13.2-linux-x86_64-gnu      /sbin/python -> ./python3
cpython-3.13.2-linux-x86_64-gnu      /bin/python3.13
cpython-3.13.2-linux-x86_64-gnu      /bin/python3 -> python3.13
cpython-3.13.2-linux-x86_64-gnu      /bin/python -> ./python3
cpython-3.12.9-linux-x86_64-gnu      /usr/sbin/python3.12
cpython-3.12.9-linux-x86_64-gnu      /usr/bin/python3.12
cpython-3.12.9-linux-x86_64-gnu      /sbin/python3.12
cpython-3.12.9-linux-x86_64-gnu      /bin/python3.12
cpython-3.11.11-linux-x86_64-gnu     /usr/sbin/python3.11
cpython-3.11.11-linux-x86_64-gnu     /usr/bin/python3.11
cpython-3.11.11-linux-x86_64-gnu     /sbin/python3.11
cpython-3.11.11-linux-x86_64-gnu     /bin/python3.11
cpython-3.10.16-linux-x86_64-gnu     /usr/sbin/python3.10
cpython-3.10.16-linux-x86_64-gnu     /usr/bin/python3.10
cpython-3.10.16-linux-x86_64-gnu     /sbin/python3.10
cpython-3.10.16-linux-x86_64-gnu     /bin/python3.10
cpython-3.9.21-linux-x86_64-gnu      /usr/sbin/python3.9
cpython-3.9.21-linux-x86_64-gnu      /usr/bin/python3.9
cpython-3.9.21-linux-x86_64-gnu      /sbin/python3.9
cpython-3.9.21-linux-x86_64-gnu      /bin/python3.9
pypy-3.11.11-linux-x86_64-gnu        /usr/sbin/pypy3 -> pypy3.11
pypy-3.11.11-linux-x86_64-gnu        /usr/bin/pypy3 -> pypy3.11
pypy-3.11.11-linux-x86_64-gnu        /sbin/pypy3 -> pypy3.11
pypy-3.11.11-linux-x86_64-gnu        /bin/pypy3 -> pypy3.11

Indeed very noisy.

@zanieb
Copy link
Member

zanieb commented Mar 20, 2025

I think we can handle this with is_same_file on directories during PATH iteration — that's quadratic though 🤔. I can't think of why we'd want to discover these all as separate interpreters in any case?

@BurntSushi random but perhaps you have an intuition for how to do that well?

@BurntSushi
Copy link
Member

@zanieb If I'm understanding correctly here, I believe that's where same-file::Handle should come in handy. You can get one of those for each path you want to consider and stuff them in a HashSet. This would avoid needing to do pairwise equality checks for all pairs of paths.

The downside is that they all need to be open file handles. Depending on how many you have, this can run afoul of max open file descriptor limits (which will vary from system to system).

@zanieb
Copy link
Member

zanieb commented Mar 21, 2025

Cool thanks, that's exactly the kind of thing I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-decision Undecided if this should be done
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants