Skip to content

Commit 3ed7367

Browse files
committed
Drop dependency on importlib_metadata
This was only required to support Python 3.8 and below, which was dropped recently. Some small shenanigans were required to support Python 3.9.
1 parent b4d4f5b commit 3ed7367

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

continuous-integration/requirements.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ contourpy==1.1.0
5252
# bokeh
5353
# matplotlib
5454
coverage[toml]==7.3.0
55-
# via pytest-cov
55+
# via
56+
# coverage
57+
# pytest-cov
5658
cycler==0.11.0
5759
# via matplotlib
5860
dask[array,complete,dataframe,diagnostics,distributed]==2023.8.1
@@ -86,9 +88,7 @@ idna==3.4
8688
imagesize==1.4.1
8789
# via sphinx
8890
importlib-metadata==6.8.0
89-
# via
90-
# dask
91-
# emsarray (setup.cfg)
91+
# via dask
9292
iniconfig==2.0.0
9393
# via pytest
9494
isort==5.12.0
@@ -307,7 +307,9 @@ urllib3==2.0.4
307307
virtualenv==20.24.3
308308
# via tox
309309
xarray[parallel]==2023.8.0
310-
# via emsarray (setup.cfg)
310+
# via
311+
# emsarray (setup.cfg)
312+
# xarray
311313
xyzservices==2023.7.0
312314
# via bokeh
313315
zict==3.0.0

docs/releases/development.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ Next release (in development)
88
* Fix an error when creating a transect plot that does not intersect the model geometry.
99
Previously this would raise a cryptic error, now it returns an empty transect dataset
1010
(:issue:`119`, :pr:`120`).
11+
* Drop dependency on importlib_metadata.
12+
This was only required to support Python 3.8, which was dropped in a previous release
13+
(:issue:`122`, :pr:`125`).

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ module = [
3636
"cfunits.*",
3737
"cryptography.*",
3838
"geojson.*",
39-
"importlib_metadata.*",
4039
"matplotlib.*",
4140
"netCDF4.*",
4241
"pooch.*",

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ install_requires =
2424
# versions, but this would need testing
2525
bottleneck >=1.3
2626
geojson >=2.5.0
27-
importlib_metadata >=4.0.0
2827
netcdf4 >=1.5.3
2928
numpy >=1.22.0
3029
packaging >=21.3

src/emsarray/conventions/_registry.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@
55
import warnings
66
from contextlib import suppress
77
from functools import cached_property
8+
from importlib import metadata
89
from itertools import chain
910
from typing import Iterable, List, Optional, Tuple, Type
1011

1112
import xarray
1213

1314
from ._base import Convention
1415

15-
if sys.version_info >= (3, 10):
16-
from importlib import metadata
17-
else:
18-
import importlib_metadata as metadata
19-
20-
2116
logger = logging.getLogger(__name__)
2217

2318

@@ -152,7 +147,12 @@ def entry_point_conventions() -> Iterable[Type[Convention]]:
152147
('emsarray.formats', True),
153148
]
154149
for group, deprecated in groups:
155-
for entry_point in metadata.entry_points(group=group):
150+
if sys.version_info >= (3, 10):
151+
entry_points = metadata.entry_points(group=group)
152+
else:
153+
entry_points = metadata.entry_points().get(group, [])
154+
155+
for entry_point in entry_points:
156156
if deprecated:
157157
warnings.warn(
158158
'`emsarray.formats` entrypoint has been renamed to `emsarray.conventions`. '

tests/conventions/test_registry.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Test convention class registration by entry points or manual registration.
33
"""
44
import sys
5+
from importlib import metadata
56
from typing import Dict, List, Tuple
67

78
import pytest
@@ -63,20 +64,19 @@ def monkeypatch_entrypoint(
6364
monkeypatch,
6465
entry_points: Dict[str, List[Tuple[str, str]]],
6566
):
66-
if sys.version_info >= (3, 10):
67-
from importlib import metadata
68-
else:
69-
import importlib_metadata as metadata
70-
7167
_entry_points = {
7268
group: [
7369
metadata.EntryPoint(group=group, name=name, value=value)
7470
for name, value in entries
7571
] for group, entries in entry_points.items()
7672
}
7773

78-
def mocked(group: str) -> List[metadata.EntryPoint]:
79-
return _entry_points.get(group, [])
74+
if sys.version_info >= (3, 10):
75+
def mocked(group: str) -> List[metadata.EntryPoint]:
76+
return _entry_points.get(group, [])
77+
else:
78+
def mocked() -> List[metadata.EntryPoint]:
79+
return _entry_points
8080

8181
monkeypatch.setattr(metadata, 'entry_points', mocked)
8282
return entry_points

0 commit comments

Comments
 (0)