From 15e411489ab11d7c49cefcb081b5e6f19625d8bd Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 9 Dec 2022 15:28:19 -0500 Subject: [PATCH 1/2] require importlib_metadata The stdlib importlib.metadata returns duplicate distributions (and entry points) in some circumstances for all python versions up to and including 3.11. https://github.com/python/importlib_metadata/issues/410#issuecomment-1304258228 The above issue can create duplicate asdf extensions. This fixes issue #1254 fix changelog typo --- CHANGES.rst | 7 +++++++ asdf/entry_points.py | 9 ++++----- asdf/tests/test_entry_points.py | 11 ++++------- asdf/util.py | 12 +++++------- docs/conf.py | 11 +++++------ pyproject.toml | 2 +- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 745ddb31f..19ff7af33 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ------------------- diff --git a/asdf/entry_points.py b/asdf/entry_points.py index 30b673c15..741453426 100644 --- a/asdf/entry_points.py +++ b/asdf/entry_points.py @@ -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 diff --git a/asdf/tests/test_entry_points.py b/asdf/tests/test_entry_points.py index 3313e35b7..ac0a63caf 100644 --- a/asdf/tests/test_entry_points.py +++ b/asdf/tests/test_entry_points.py @@ -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 diff --git a/asdf/util.py b/asdf/util.py index df8924975..62a0572c7 100644 --- a/asdf/util.py +++ b/asdf/util.py @@ -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 diff --git a/docs/conf.py b/docs/conf.py index 8bc94c0af..9bdee5a42 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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: diff --git a/pyproject.toml b/pyproject.toml index c439ac8b6..fc35c4b65 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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', From 908b45d5a15e19a173bb47448a7dc1060abd59ab Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 9 Dec 2022 15:55:56 -0500 Subject: [PATCH 2/2] link issue and PR in comment --- asdf/entry_points.py | 2 ++ asdf/tests/test_entry_points.py | 2 ++ asdf/util.py | 2 ++ docs/conf.py | 2 ++ 4 files changed, 8 insertions(+) diff --git a/asdf/entry_points.py b/asdf/entry_points.py index 741453426..896b8aff0 100644 --- a/asdf/entry_points.py +++ b/asdf/entry_points.py @@ -3,6 +3,8 @@ # 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 +# see PR https://github.com/asdf-format/asdf/pull/1260 +# see issue https://github.com/asdf-format/asdf/issues/1254 from importlib_metadata import entry_points from .exceptions import AsdfWarning diff --git a/asdf/tests/test_entry_points.py b/asdf/tests/test_entry_points.py index ac0a63caf..789ff238a 100644 --- a/asdf/tests/test_entry_points.py +++ b/asdf/tests/test_entry_points.py @@ -1,6 +1,8 @@ # 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 +# see PR https://github.com/asdf-format/asdf/pull/1260 +# see issue https://github.com/asdf-format/asdf/issues/1254 import importlib_metadata as metadata import pytest diff --git a/asdf/util.py b/asdf/util.py index 62a0572c7..4ecc83452 100644 --- a/asdf/util.py +++ b/asdf/util.py @@ -14,6 +14,8 @@ # 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 +# see PR https://github.com/asdf-format/asdf/pull/1260 +# see issue https://github.com/asdf-format/asdf/issues/1254 from importlib_metadata import packages_distributions from packaging.version import Version diff --git a/docs/conf.py b/docs/conf.py index 9bdee5a42..1a1e9f659 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -5,6 +5,8 @@ # 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 +# see PR https://github.com/asdf-format/asdf/pull/1260 +# see issue https://github.com/asdf-format/asdf/issues/1254 from importlib_metadata import distribution from sphinx_asdf.conf import * # noqa: F403