python / python/importlib_metadata
`Distribution.files` does not show files with absolute RECORD entries on Windows with Python 3.10 and 3.11
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 142
- 派生
- 97
- PR 合并指标
- 30 天内没有已合并 PR
描述
If an installed distribution contains absolute paths in the RECORD file, Distribution.files is missing these files. (installer writes absolute paths for executable scripts on Windows since https://github.com/pypa/installer/pull/286.)
To reproduce:
Build a sample project with an executable script
project structure:
sampleproject/
├── sample/
│ ├── __init__.py
│ └── __main__.py
└── pyproject.toml
pyproject.toml:
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "sample"
version = "0.1"
[project.scripts]
sample = "sample:__main__"
build project:
python -m venv build-venv
build-venv\Scripts\python.exe -m pip install build
build-venv\Scripts\python.exe -m build sampleproject
Install the built wheel with installer and display the distribution files:
python -m venv test-venv
test-venv\Scripts\python.exe -m pip install installer importlib-metadata
test-venv\Scripts\python.exe -m installer sampleproject\dist\sample-0.1-py3-none-any.whl
test-venv\Scripts\python.exe -c "from pprint import pprint; from importlib_metadata import distribution; pprint(distribution('sample').files)"
When using Python 3.12 or later to install the wheel and display the files the correct output is:
[PackagePath('sample-0.1.dist-info/METADATA'),
PackagePath('sample-0.1.dist-info/RECORD'),
PackagePath('sample-0.1.dist-info/WHEEL'),
PackagePath('sample-0.1.dist-info/entry_points.txt'),
PackagePath('sample-0.1.dist-info/top_level.txt'),
PackagePath('C:/temp/test-uninstall/test-venv/Scripts/sample.exe'),
PackagePath('sample/__init__.py'),
PackagePath('sample/__main__.py')]
When using Python 3.11 or 3.10 to install the wheel and display the files the executable script is missing:
[PackagePath('sample-0.1.dist-info/METADATA'),
PackagePath('sample-0.1.dist-info/RECORD'),
PackagePath('sample-0.1.dist-info/WHEEL'),
PackagePath('sample-0.1.dist-info/entry_points.txt'),
PackagePath('sample-0.1.dist-info/top_level.txt'),
PackagePath('sample/__init__.py'),
PackagePath('sample/__main__.py')]
The reason is the following difference in path operations:
>C:\python311\python.exe -c "from pathlib import Path, PurePosixPath; print(Path('C:/a') / PurePosixPath('C:/b/c'))"
C:\a\b\c
>C:\python312\python.exe -c "from pathlib import Path, PurePosixPath; print(Path('C:/a') / PurePosixPath('C:/b/c'))"
C:\b\c
This issue can be worked around by converting the PurePosixPath to str first:
>C:\python311\python.exe -c "from pathlib import Path, PurePosixPath; print(Path('C:/a') / str(PurePosixPath('C:/b/c')))"
C:\b\c
Would you be open to such a fix in https://github.com/python/importlib_metadata/blob/f09a4bd87e3ed8f8c3bda7074bc8f7b0dfb94d72/importlib_metadata/__init__.py#L1046 ?
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 importlib_metadata/init.py 第 1046 行附近开始,在 Windows 上使用 Python 3.10 或 3.11 重现示例 wheel 场景。检查绝对 RECORD 条目的处理,然后验证 Distribution.files 包含可执行文件路径,就像 Python 3.12 及更高版本中一样。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 68/100