-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Description
Documentation
(Filing as a documentation issue, since I suspect the behavior is intentional and has its valid use cases.)
In Gentoo, we install packages into a temporary directory whose contents resemble the actual filesystem prefix. For some packages that don't use PEP517 build systems, we invoke python -m compileall
to byte-compile the installed modules.
Today I wanted to switch our code to start using the -s
option, and I've noticed that in addition to the path specified, it also strips the path separator following it.
For example, consider the following example:
$ mkdir -p /tmp/destdir/usr/lib/python3.13/site-packages
$ > /tmp/destdir/usr/lib/python3.13/site-packages/foo.py
$ python3.13 -m compileall -s /tmp/destdir /tmp/destdir/usr/lib/python3.13/site-packages/foo.py
Compiling '/tmp/destdir/usr/lib/python3.13/site-packages/foo.py'...
$ strings /tmp/destdir/usr/lib/python3.13/site-packages/__pycache__/foo.cpython-313.pyc
'usr/lib/python3.13/site-packages/foo.py
<module>r
Note that while I expeced it to strip /tmp/destdir
, leaving /usr/lib/python3.13/site-packages/foo.py
, it also stripped the following slash, making the path relative.
Now, I can achieve the desired behavior by adding -p /
:
$ rm /tmp/destdir/usr/lib/python3.13/site-packages/__pycache__/foo.cpython-313.pyc
$ python3.13 -m compileall -s /tmp/destdir -p / /tmp/destdir/usr/lib/python3.13/site-packages/foo.py
Compiling '/tmp/destdir/usr/lib/python3.13/site-packages/foo.py'...
$ strings /tmp/destdir/usr/lib/python3.13/site-packages/__pycache__/foo.cpython-313.pyc
(/usr/lib/python3.13/site-packages/foo.py
<module>r
However, I found that behavior surprising and I think it should be documented better. Particularly, the current documentation states:
cpython/Doc/library/compileall.rst
Lines 58 to 63 in 120c9d4
.. option:: -s strip_prefix | |
.. option:: -p prepend_prefix | |
Remove (``-s``) or append (``-p``) the given prefix of paths | |
recorded in the ``.pyc`` files. | |
Cannot be combined with ``-d``. |
which to me sounds like it would remove the specified string, rather than making the path relative. Perhaps it would make sense to specify explicitly that:
- Removing the prefix makes paths relative to it.
-s
and-p
can be used simultaneously.-p /
can be used to make the path absolute.
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status