From e27a7cd02ded394bedadea539d8568705a1ed913 Mon Sep 17 00:00:00 2001 From: zacharyburnett Date: Thu, 18 Jul 2024 11:54:31 -0400 Subject: [PATCH] replace usages of ``pkg_resources`` with ``importlib.metadata`` add change log entry --- CHANGELOG.md | 2 ++ weldx/config.py | 4 ++-- weldx/tests/_helpers.py | 4 ++-- weldx/tests/transformations/_util.py | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc81211b7..e6def3bce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - rename (fix typo) argument to `lcs_child_in_parent` in `CoordinateSystemManager.add_cs` \[{pull}`936`\]. +- replace usages of ``pkg_resources`` with ``importlib.metadata`` [#941] + ### Dependencies - pin `weldx-widgets>=0.2.3` for viz \[{pull}`939`\]. diff --git a/weldx/config.py b/weldx/config.py index 9033225a5..ec3fd18b6 100644 --- a/weldx/config.py +++ b/weldx/config.py @@ -5,7 +5,7 @@ from pathlib import Path import asdf -import pkg_resources +import importlib.metadata import yaml from asdf.config import ResourceMappingProxy from asdf.versioning import AsdfVersion, split_tag_version @@ -175,7 +175,7 @@ def enable_quality_standard(name: str, version: AsdfVersion | str = None): @staticmethod def load_installed_standards(): """Load all standards that are installed to the active virtual environment.""" - for entry_point in pkg_resources.iter_entry_points("weldx.standard"): + for entry_point in importlib.metadata.entry_points()["weldx.standard"]: standards = entry_point.load()() if not isinstance(standards, list): standards = [standards] diff --git a/weldx/tests/_helpers.py b/weldx/tests/_helpers.py index d63e25111..1a06c4161 100644 --- a/weldx/tests/_helpers.py +++ b/weldx/tests/_helpers.py @@ -4,7 +4,7 @@ import numpy as np import pint -from pkg_resources import get_distribution +import importlib.metadata from weldx.constants import Q_ from weldx.geometry import _vector_is_close as vector_is_close @@ -130,7 +130,7 @@ def matrix_is_close(mat_a, mat_b, abs_tol=1e-9) -> bool: return False atol_unit = 1.0 - if isinstance(mat_b, pint.Quantity) and get_distribution("pint").version >= "0.21": + if isinstance(mat_b, pint.Quantity) and tuple(int(part) for part in importlib.metadata.version("pint").split(".")) >= (0, 21): atol_unit = mat_b.u return np.all(np.isclose(mat_a, mat_b, atol=abs_tol * atol_unit)).__bool__() diff --git a/weldx/tests/transformations/_util.py b/weldx/tests/transformations/_util.py index 86f99a239..41afaab8c 100644 --- a/weldx/tests/transformations/_util.py +++ b/weldx/tests/transformations/_util.py @@ -3,7 +3,7 @@ from typing import Any import numpy as np -from pkg_resources import get_distribution +import importlib.metadata from xarray import DataArray import weldx.transformations as tf @@ -79,7 +79,7 @@ def check_coordinate_system( ) atol_unit = 1.0 - if get_distribution("pint").version >= "0.21": + if tuple(int(part) for part in importlib.metadata.version("pint").split(".")) >= (0, 21): atol_unit = coordinates_expected.u assert np.allclose(