project_wheel_metadata returns email.message.Message instead of importlib.metadata._adapters.Message in python 3.9
GianlucaFicarelli opened this issue · 2 comments
When using python 3.9.18 (but it happens also with other 3.9.x), project_wheel_metadata
returns an instance of email.message.Message
instead of importlib.metadata._adapters.Message
.
The problem is that the returned object doesn't have the property json
as defined by PackageMetadata
import sys
from build.util import project_wheel_metadata
metadata = project_wheel_metadata(".", isolated=False)
>>> print(sys.version)
3.10.8 (main, Nov 16 2022, 15:31:10) [Clang 14.0.0 (clang-1400.0.29.202)]
>>> print(repr(metadata))
<importlib.metadata._adapters.Message object at 0x10e8c3fa0>
>>> hasattr(metadata, "json")
True
>>> print(sys.version)
3.9.18 (main, Oct 17 2023, 16:56:25)
[Clang 14.0.0 (clang-1400.0.29.202)]
>>> print(repr(metadata))
<email.message.Message object at 0x1015f66d0>
>>> hasattr(metadata, "json")
False
>>> print(sys.version)
3.8.15 (default, Nov 16 2022, 15:37:40)
[Clang 14.0.0 (clang-1400.0.29.202)]
>>> print(repr(metadata))
<importlib_metadata._adapters.Message object at 0x10bb06100>
>>> hasattr(metadata, "json")
True
As it's shown above, the json
property works correctly with python 3.10.8 and 3.8.15, but not with python 3.9.18.
Installed packages in python 3.10.8:
build==1.0.3
packaging==23.2
pip==23.3
pyproject_hooks==1.0.0
setuptools==68.2.2
tomli==2.0.1
wheel==0.41.2
Installed packages in python 3.9.18:
build==1.0.3
importlib-metadata==6.8.0
packaging==23.2
pip==23.3
pyproject_hooks==1.0.0
setuptools==68.2.2
tomli==2.0.1
wheel==0.41.2
zipp==3.17.0
Installed packages in python 3.8.15:
build==1.0.3
importlib-metadata==6.8.0
packaging==23.2
pip==23.3
pyproject_hooks==1.0.0
setuptools==68.2.2
tomli==2.0.1
wheel==0.41.2
zipp==3.17.0
The issue seems to be caused by the conditional import in
Line 6 in 71bc938
If import importlib_metadata as metadata
is executed even for python 3.9.18 (in my case), the issue seems resolved.
Thanks Gianluca for making this change. It drastically simplified the code in pytest-checkdocs.