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

DEP: drop importlib_metadata as a dependency on Python 3.12 and newer #1810

Merged
merged 1 commit into from
Jul 24, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
this inheritance may be dropped in a future asdf version. Please migrate to the new
``AsdfSerializationError``. [#1809]

- Drop ``importlib_metadata`` as a dependency on Python 3.12 and newer [#1810]

3.3.0 (2024-07-12)
------------------

Expand Down
13 changes: 9 additions & 4 deletions asdf/_entry_points.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import sys
import warnings

from .exceptions import AsdfWarning
from .extension import ExtensionProxy
from .resource import ResourceMappingProxy

# 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
if sys.version_info >= (3, 12):
from importlib.metadata import entry_points
else:
from importlib_metadata import entry_points

from .exceptions import AsdfWarning
from .extension import ExtensionProxy
from .resource import ResourceMappingProxy

RESOURCE_MAPPINGS_GROUP = "asdf.resource_mappings"
EXTENSIONS_GROUP = "asdf.extensions"
Expand Down
18 changes: 12 additions & 6 deletions asdf/_tests/test_entry_points.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# 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 sys

import pytest

from asdf import _entry_points
Expand All @@ -12,6 +8,16 @@
from asdf.extension import ExtensionProxy
from asdf.resource import ResourceMappingProxy

# 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
if sys.version_info >= (3, 12):
import importlib.metadata as metadata
else:
import importlib_metadata as metadata


@pytest.fixture()
def mock_entry_points():
Expand Down
11 changes: 8 additions & 3 deletions asdf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import math
import re
import struct
import sys
import types
import warnings
from functools import lru_cache
Expand All @@ -12,16 +13,20 @@

import numpy as np
import yaml
from packaging.version import Version

from . import constants, exceptions

# 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
if sys.version_info >= (3, 12):
from importlib.metadata import packages_distributions
else:
from importlib_metadata import packages_distributions

from . import constants, exceptions

# We're importing our own copy of urllib.parse because
# we need to patch it to support asdf:// URIs, but it'd
Expand Down
9 changes: 7 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
else:
import tomllib

from sphinx_asdf.conf import * # noqa: F403

# 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
if sys.version_info >= (3, 12):
from importlib.metadata import distribution
else:
from importlib_metadata import distribution


# 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 @@ -21,7 +21,7 @@ dynamic = [
dependencies = [
"asdf-standard>=1.1.0",
"asdf-transform-schemas>=0.3", # required for asdf-1.0.0 schema
"importlib-metadata>=4.11.4",
"importlib-metadata>=4.11.4 ; python_version<='3.11'",
"jmespath>=0.6.2",
"numpy>=1.22",
"packaging>=19",
Expand Down
Loading