pip
pip copied to clipboard
pip compiles pyc files for installed scripts
Description
When pip installs a wheel with custom scripts that have a .py extension, it creates corresponding .pyc files. This pollutes the bin directory, and doesn't accomplish anything, since I don't think Python loads .pyc files for scripts.
Expected behavior
Now granted, the wheel spec does say:
Compile any installed .py to .pyc. (Uninstallers should be smart enough to remove .pyc even if it is not mentioned in RECORD.)
(emphasis mine)
But I think common sense suggests that only .py files in the purelib and platlib directories should be compiled.
pip version
22.2.2
Python version
3.10.4
OS
Ubuntu 22.04
How to Reproduce
Install docutils, then look in the bin directory.
Output
$ python3 -mvenv ./venv
$ ./venv/bin/pip install -U pip
[...]
$ ./venv/bin/pip install docutils
Collecting docutils
Downloading docutils-0.19-py3-none-any.whl (570 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 570.5/570.5 kB 2.2 MB/s eta 0:00:00
Installing collected packages: docutils
Successfully installed docutils-0.19
$ ls ./venv/bin/__pycache__/
rst2html.cpython-310.pyc rst2latex.cpython-310.pyc rst2odt_prepstyles.cpython-310.pyc rst2xetex.cpython-310.pyc
rst2html4.cpython-310.pyc rst2man.cpython-310.pyc rst2pseudoxml.cpython-310.pyc rst2xml.cpython-310.pyc
rst2html5.cpython-310.pyc rst2odt.cpython-310.pyc rst2s5.cpython-310.pyc rstpep2html.cpython-310.pyc
Code of Conduct
- [X] I agree to follow the PSF Code of Conduct.
IMO, this isn't worth worrying about. It should be rare (these days, entry points are recommended over scripts anyway) and it doesn't cause any real problem, just clutter.
Having said that, if someone were to create a PR, it could be considered.
FWIW, installer seems to already implement this: https://github.com/pypa/installer/blob/70ae05bb25c66e621064f2c031a04ac1192be30b/src/installer/destinations.py#L243