python / python/importlib_metadata

`Distribution.files` does not show files with absolute RECORD entries on Windows with Python 3.10 and 3.11

オープン 初心者向け
#535 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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 ?

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

importlib_metadata/init.py の1046行目付近から始め、Windows上でPython 3.10または3.11を使ってサンプルwheelのシナリオを再現します。絶対パスのRECORDエントリの処理を確認し、その後、Python 3.12以降と同様にDistribution.filesに実行可能ファイルのパスが含まれていることを検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
68/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。