コンテンツにスキップ

Python Wheel Metadata を取得する

概要

Python whl が要求する requires を調べたくなり、Python の Wheel ファイルからメタデータを取得する方法を調べた。importlib_metadata パッケージを使うと、Wheel ファイルからメタデータを取得できる。

setup

python -m pip install importlib_metadata

メタデータからrequiresの取得

1
2
3
from importlib_metadata import requires

print(requires("ipython"))
['backcall', 'decorator', 'jedi (>=0.16)', 'matplotlib-inline', 'pickleshare', 'prompt-toolkit (!=3.0.37,<3.1.0,>=3.0.30)', 'pygments (>=2.4.0)', 'stack-data', 'traitlets (>=5)', 'typing-extensions ; python_version < "3.10"', 'pexpect (>4.3) ; sys_platform != "win32"', 'appnope ; sys_platform == "darwin"', 'colorama ; sys_platform == "win32"', "black ; extra == 'all'", "ipykernel ; extra == 'all'", "setuptools (>=18.5) ; extra == 'all'", "sphinx (>=1.3) ; extra == 'all'", "sphinx-rtd-theme ; extra == 'all'", "docrepr ; extra == 'all'", "matplotlib ; extra == 'all'", "stack-data ; extra == 'all'", "pytest (<7) ; extra == 'all'", "typing-extensions ; extra == 'all'", "pytest (<7.1) ; extra == 'all'", "pytest-asyncio ; extra == 'all'", "testpath ; extra == 'all'", "nbconvert ; extra == 'all'", "nbformat ; extra == 'all'", "ipywidgets ; extra == 'all'", "notebook ; extra == 'all'", "ipyparallel ; extra == 'all'", "qtconsole ; extra == 'all'", "curio ; extra == 'all'", "matplotlib (!=3.2.0) ; extra == 'all'", "numpy (>=1.21) ; extra == 'all'", "pandas ; extra == 'all'", "trio ; extra == 'all'", "black ; extra == 'black'", "ipykernel ; extra == 'doc'", "setuptools (>=18.5) ; extra == 'doc'", "sphinx (>=1.3) ; extra == 'doc'", "sphinx-rtd-theme ; extra == 'doc'", "docrepr ; extra == 'doc'", "matplotlib ; extra == 'doc'", "stack-data ; extra == 'doc'", "pytest (<7) ; extra == 'doc'", "typing-extensions ; extra == 'doc'", "pytest (<7.1) ; extra == 'doc'", "pytest-asyncio ; extra == 'doc'", "testpath ; extra == 'doc'", "ipykernel ; extra == 'kernel'", "nbconvert ; extra == 'nbconvert'", "nbformat ; extra == 'nbformat'", "ipywidgets ; extra == 'notebook'", "notebook ; extra == 'notebook'", "ipyparallel ; extra == 'parallel'", "qtconsole ; extra == 'qtconsole'", "pytest (<7.1) ; extra == 'test'", "pytest-asyncio ; extra == 'test'", "testpath ; extra == 'test'", "pytest (<7.1) ; extra == 'test_extra'", "pytest-asyncio ; extra == 'test_extra'", "testpath ; extra == 'test_extra'", "curio ; extra == 'test_extra'", "matplotlib (!=3.2.0) ; extra == 'test_extra'", "nbformat ; extra == 'test_extra'", "numpy (>=1.21) ; extra == 'test_extra'", "pandas ; extra == 'test_extra'", "trio ; extra == 'test_extra'"]