Python 3.11 -P option changes one aspect of nspkg.pth namespace packages
还没有人认领这个 Issue。
评估
调研方向
首先,按照所示内容,使用 Python 3.11、-P、PYTHONPATH 以及全局安装的 nspkg.pth 命名空间包重现报告的导入失败。跟踪 -P 与 site-packages 路径初始化之间的交互,然后验证手动提供的 sphinxcontrib 包能够成功导入,同时不会导致已记录的 -P 行为发生回归。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 558
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/cpython 的其他 Issue
-
docs pending
难度 2/5 1-3 小时 新手友好度 78/100
-
stdlib type-feature
难度 2/5 1-3 小时 新手友好度 78/100
-
stdlib type-feature
难度 2/5 1-3 小时 新手友好度 72/100
-
build type-bug
难度 2/5 1-3 小时 新手友好度 76/100
-
stdlib topic-email type-feature
难度 2/5 1-3 小时 新手友好度 70/100
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 90/100
-
bug
难度 2/5 1-3 小时 新手友好度 86/100
zostera/django-bootstrap4#894 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
use-agent-os/agent-os#3276 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
难度 2/5 1-3 小时 新手友好度 88/100
NousResearch/hermes-agent#117848 ·