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

Use importlib_metadata for Python < 3.10.2 #693

Merged
merged 5 commits into from Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -36,7 +36,7 @@ dependencies = [
"pyproject_hooks",
# not actually a runtime dependency, only supplied as there is not "recommended dependency" support
'colorama; os_name == "nt"',
'importlib-metadata >= 4.6; python_version < "3.10"', # Not required for 3.8+, but fixes a stdlib bug
'importlib-metadata >= 4.6; python_full_version < "3.10.2"', # Not required for 3.8+, but fixes a stdlib bug
'tomli >= 1.1.0; python_version < "3.11"',
]

Expand Down
7 changes: 4 additions & 3 deletions src/build/_importlib.py
Expand Up @@ -3,12 +3,13 @@

if sys.version_info < (3, 8):
import importlib_metadata as metadata
elif sys.version_info < (3, 9, 10) or (3, 10, 0) <= sys.version_info < (3, 10, 2):
henryiii marked this conversation as resolved.
Show resolved Hide resolved
elif sys.version_info >= (3, 10, 2):
from importlib import metadata
else:
try:
import importlib_metadata as metadata
except ModuleNotFoundError:
# helps bootstrapping when dependencies aren't installed
from importlib import metadata
else:
from importlib import metadata

__all__ = ['metadata']
3 changes: 3 additions & 0 deletions tests/test_util.py
Expand Up @@ -14,6 +14,7 @@ def test_wheel_metadata(package_test_setuptools, isolated):

assert metadata['name'] == 'test-setuptools'
assert metadata['version'] == '1.0.0'
assert isinstance(metadata.json, dict)


@pytest.mark.network
Expand All @@ -26,6 +27,7 @@ def test_wheel_metadata_isolation(package_test_flit):

assert metadata['name'] == 'test_flit'
assert metadata['version'] == '1.0.0'
assert isinstance(metadata.json, dict)

with pytest.raises(
build.BuildBackendException,
Expand All @@ -42,3 +44,4 @@ def test_with_get_requires(package_test_metadata):
assert metadata['name'] == 'test-metadata'
assert str(metadata['version']) == '1.0.0'
assert metadata['summary'] == 'hello!'
assert isinstance(metadata.json, dict)