Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

project_wheel_metadata returns email.message.Message instead of importlib.metadata._adapters.Message in python 3.9 #692

Closed
GianlucaFicarelli opened this issue Oct 17, 2023 · 2 comments · Fixed by #693

Comments

@GianlucaFicarelli
Copy link
Contributor

GianlucaFicarelli commented Oct 17, 2023

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
@GianlucaFicarelli
Copy link
Contributor Author

The issue seems to be caused by the conditional import in

elif sys.version_info < (3, 9, 10) or (3, 10, 0) <= sys.version_info < (3, 10, 2):

If import importlib_metadata as metadata is executed even for python 3.9.18 (in my case), the issue seems resolved.

@jaraco
Copy link
Member

jaraco commented Mar 21, 2024

Thanks Gianluca for making this change. It drastically simplified the code in pytest-checkdocs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants