python / python/cpython

Python 3.11 -P option changes one aspect of nspkg.pth namespace packages

Đang mở
#94,741 9 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện lỗi import đã được báo cáo với Python 3.11, -P, PYTHONPATH và một namespace package nspkg.pth được cài đặt trên toàn hệ thống như minh họa. Theo dõi cách -P và quá trình khởi tạo đường dẫn site-packages tương tác với nhau, sau đó xác minh rằng việc import gói sphinxcontrib được cung cấp thủ công thành công mà không làm hồi quy hành vi -P đã được ghi lại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.