Incorrect handling of backslashes in RECORD file by importlib.metadata
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
The class importlib.metadata.PackagePath does not correctly handle backslashes in the RECORD dist-info file.
According to the specs, backslashes are allowed:
The path may be either absolute, or relative to the directory containing the .dist-info directory (commonly, the site-packages directory). On Windows, directories may be separated either by forward- or backslashes (/ or \).
This leads to PackagePath.name wrongfully returning the entire path instead of just the filename.
Steps for Reprocution
As an example, take ruff 0.14.14 on Windows
RECORD file contents
..\..\Scripts\ruff.exe,sha256=HJzLwAeBnSdcuXo602XCKCTuDMMrn5dZPIEzmZ0w6QY,31781376
ruff-0.14.14.dist-info/INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
ruff-0.14.14.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
ruff-0.14.14.dist-info\METADATA,sha256=QD17c7tQSny5DBVcDewbxp32FVd0m05EfaH_AQvKuhQ,26651
ruff-0.14.14.dist-info\RECORD,,
ruff-0.14.14.dist-info\WHEEL,sha256=jsSEiVNsW1dJj5gDaReR40i7mhgBjWtms6nAD6EViXU,94
ruff-0.14.14.dist-info\licenses\LICENSE,sha256=JZfYVBIrd93HGXFWTKI1CjdghXXOMkrcVlCisgUcjxg,20731
ruff\__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
ruff\__main__.py,sha256=w1Ehfzzy8tMM7r7dFrKmi3DkmTZyV_xJ40K_sxoO6X0,2908
pip install "ruff==0.14.14"
import importlib.metadata
from pathlib import Path
for pkg in importlib.metadata.distributions():
if pkg.name == "ruff":
for file in pkg.files:
print(file.name, Path(file).name)
Expected Output
ruff.exe ruff.exe
INSTALLER INSTALLER
REQUESTED REQUESTED
METADATA METADATA
RECORD RECORD
WHEEL WHEEL
LICENSE LICENSE
__init__.py __init__.py
__main__.py __main__.py
Actual Output
..\..\Scripts\ruff.exe ruff.exe
INSTALLER INSTALLER
REQUESTED REQUESTED
ruff-0.14.14.dist-info\METADATA METADATA
ruff-0.14.14.dist-info\RECORD RECORD
ruff-0.14.14.dist-info\WHEEL WHEEL
ruff-0.14.14.dist-info\licenses\LICENSE LICENSE
ruff\__init__.py __init__.py
ruff\__main__.py __main__.py
CPython versions tested on:
3.14
Operating systems tested on:
Windows
Linked PRs
- gh-149540
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với importlib.metadata.PackagePath và tái hiện trường hợp Windows bằng nội dung của RECORD cùng ví dụ trong issue. Công việc được xem là hoàn tất khi PackagePath.name chỉ trả về tên tệp đối với các đường dẫn được phân tách bằng dấu gạch chéo ngược, trong khi các trường hợp dùng dấu gạch chéo xuôi được minh họa vẫn tiếp tục tạo ra các tên như mong đợ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
- tooling
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 30/100