Python 3.11 -P option changes one aspect of nspkg.pth namespace packages
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 36k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
When trying to add the -P flag to Python shebangs in Fedora package, @befeleme discovered that our sphinxcontrib-programoutput fails to build documentation when /usr/bin/sphinx-build has -P in the shebang. After a lot of debugging, I've discovered that -P somewhat breaks the behavior wrt old-school namespace packages with nspkg.pth files.
To reproduce, I needed to install a sphinxcontrib-namespaced package globally to site-packages. Then, importing another sphinxcontrib-namespaced package without nspkg.pth from a manually specified $PYTHONPATH location fails with -P.
$ podman run --rm -ti python:3.11.0b3 /bin/bash
...
root@b881d08fc5f2:/# pip install 'sphinxcontrib-htmlhelp==2.0.0'
...
root@b881d08fc5f2:/# ls -1 /usr/local/lib/python3.11/site-packages
...
sphinxcontrib_htmlhelp-2.0.0-py3.9-nspkg.pth
sphinxcontrib_htmlhelp-2.0.0.dist-info
...
root@b881d08fc5f2:/# cd /tmp
root@b881d08fc5f2:/tmp# mkdir -p build/lib/sphinxcontrib/programoutput/
root@b881d08fc5f2:/tmp# touch build/lib/sphinxcontrib/programoutput/__init__.py
root@b881d08fc5f2:/tmp# PYTHONPATH=build/lib python3.11 -c 'import sphinxcontrib.programoutput'
(success)
root@b881d08fc5f2:/tmp# PYTHONPATH=build/lib python3.11 -P -c 'import sphinxcontrib.programoutput'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'sphinxcontrib.programoutput'
When the import is in a script, it behaves the same:
root@b881d08fc5f2:/tmp# cat > script.py
import sphinxcontrib.programoutput
root@b881d08fc5f2:/tmp# PYTHONPATH=build/lib python3.11 script.py
(success)
root@b881d08fc5f2:/tmp# PYTHONPATH=build/lib python3.11 -P script.py
Traceback (most recent call last):
File "/tmp/script.py", line 1, in <module>
import sphinxcontrib.programoutput
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'sphinxcontrib.programoutput'
Your environment
I wasn't able to reproduce this in venv, only when installing the namespace packages globally to system-wide site-packages. I've reproduced on Fedora as well as in the official python:3.11.0b3 Docker image.
- CPython versions tested on: 3.11.0b3
- Operating system and architecture: Fedora Linux, Debian, x86_64
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Iniziate riproducendo il problema di importazione segnalato con Python 3.11, -P, PYTHONPATH e un pacchetto namespace nspkg.pth installato globalmente, come mostrato. Tracciate quindi l’interazione tra -P e l’inizializzazione del percorso di site-packages, poi verificate che l’importazione del pacchetto sphinxcontrib fornito manualmente abbia esito positivo senza regressioni nel comportamento documentato di -P.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 35/100