Skip to content

Commit

Permalink
require importlib_metadata
Browse files Browse the repository at this point in the history
The stdlib importlib.metadata returns duplicate distributions
(and entry points) in some circumstances for all python versions
up to and including 3.11.

python/importlib_metadata#410 (comment)

The above issue can create duplicate asdf extensions.

This fixes issue asdf-format#1254

fix changelog typo
  • Loading branch information
braingram committed Dec 9, 2022
1 parent 3d960d5 commit f57a7d9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2.14.3 (unreleased)
-------------------

The ASDF Standard is at v1.6.0

- Use importlib_metadata for all python versions [#1260]

2.14.2 (2022-12-05)
-------------------

Expand Down
9 changes: 4 additions & 5 deletions asdf/entry_points.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import sys
import warnings

if sys.version_info < (3, 10):
from importlib_metadata import entry_points
else:
from importlib.metadata import entry_points
# The standard library importlib.metadata returns duplicate entrypoints
# for all python versions up to and including 3.11
# https://github.com/python/importlib_metadata/issues/410#issuecomment-1304258228
from importlib_metadata import entry_points

from .exceptions import AsdfWarning
from .extension import ExtensionProxy
Expand Down
11 changes: 4 additions & 7 deletions asdf/tests/test_entry_points.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import sys

# The standard library importlib.metadata returns duplicate entrypoints
# for all python versions up to and including 3.11
# https://github.com/python/importlib_metadata/issues/410#issuecomment-1304258228
import importlib_metadata as metadata
import pytest

if sys.version_info < (3, 10):
import importlib_metadata as metadata
else:
import importlib.metadata as metadata

from asdf import entry_points
from asdf._version import version as asdf_package_version
from asdf.exceptions import AsdfWarning
Expand Down
12 changes: 5 additions & 7 deletions asdf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@
import math
import re
import struct
import sys
import types
from functools import lru_cache
from importlib import metadata
from urllib.request import pathname2url

import numpy as np

# The standard library importlib.metadata returns duplicate entrypoints
# for all python versions up to and including 3.11
# https://github.com/python/importlib_metadata/issues/410#issuecomment-1304258228
from importlib_metadata import packages_distributions
from packaging.version import Version

from . import constants

if sys.version_info < (3, 10):
from importlib_metadata import packages_distributions
else:
from importlib.metadata import packages_distributions


# We're importing our own copy of urllib.parse because
# we need to patch it to support asdf:// URIs, but it'd
# be irresponsible to do this for all users of a
Expand Down
11 changes: 5 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from pathlib import Path

import tomli
from sphinx_asdf.conf import * # noqa: F403

try:
from importlib.metadata import distribution
except ImportError:
from importlib_metadata import distribution

# The standard library importlib.metadata returns duplicate entrypoints
# for all python versions up to and including 3.11
# https://github.com/python/importlib_metadata/issues/410#issuecomment-1304258228
from importlib_metadata import distribution
from sphinx_asdf.conf import * # noqa: F403

# Get configuration information from `pyproject.toml`
with open(Path(__file__).parent.parent / "pyproject.toml", "rb") as configuration_file:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies = [
'asdf-transform-schemas >=0.2.2',
'asdf-unit-schemas >= 0.1.0',
'importlib_resources >=3; python_version <"3.9"',
'importlib-metadata >=3; python_version <"3.10"',
'importlib-metadata >=4.11.4',
'jmespath >=0.6.2',
'jsonschema >=4.0.1',
'numpy >=1.18',
Expand Down

0 comments on commit f57a7d9

Please sign in to comment.