From e27a7cd02ded394bedadea539d8568705a1ed913 Mon Sep 17 00:00:00 2001 From: zacharyburnett Date: Thu, 18 Jul 2024 11:54:31 -0400 Subject: [PATCH 1/8] 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( From 3e0dc1af9beaa1187a9ed7ed37c9ce2bd16eaf11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Ftay=20Fabry?= Date: Mon, 5 Aug 2024 13:49:36 +0200 Subject: [PATCH 2/8] update pint version --- .ruff.toml | 2 +- CHANGELOG.md | 3 ++- pyproject.toml | 2 +- weldx/config.py | 2 +- weldx/constants.py | 1 - weldx/tests/_helpers.py | 6 ++++-- weldx/tests/transformations/_util.py | 5 +---- 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.ruff.toml b/.ruff.toml index f6d0285ea..1979526df 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -77,5 +77,5 @@ required-imports = [ "from __future__ import annotations", ] -[flake8-import-conventions] +[lint.flake8-import-conventions] extend-aliases = { xarray = "xr" } diff --git a/CHANGELOG.md b/CHANGELOG.md index e6def3bce..eae44edb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,12 @@ - rename (fix typo) argument to `lcs_child_in_parent` in `CoordinateSystemManager.add_cs` \[{pull}`936`\]. -- replace usages of ``pkg_resources`` with ``importlib.metadata`` [#941] +- replace usages of `pkg_resources` with `importlib.metadata` \[{pull}`941`\]. ### Dependencies - pin `weldx-widgets>=0.2.3` for viz \[{pull}`939`\]. +- pin `pint>=0.21` \[{pull}`941`\]. ## 0.6.8 (07.06.2024) diff --git a/pyproject.toml b/pyproject.toml index c78d5081b..4a33a85dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ dependencies = [ "networkx>=2.8.2", "numpy>=1.20,<2", "pandas>=1.5", - "pint>=0.18", + "pint>=0.21", "pint-xarray>=0.3", "psutil", "scipy>=1.6.2", diff --git a/weldx/config.py b/weldx/config.py index ec3fd18b6..5afe2958d 100644 --- a/weldx/config.py +++ b/weldx/config.py @@ -2,10 +2,10 @@ from __future__ import annotations +import importlib.metadata from pathlib import Path import asdf -import importlib.metadata import yaml from asdf.config import ResourceMappingProxy from asdf.versioning import AsdfVersion, split_tag_version diff --git a/weldx/constants.py b/weldx/constants.py index 1fe816d2c..fedb49a1f 100644 --- a/weldx/constants.py +++ b/weldx/constants.py @@ -16,7 +16,6 @@ WELDX_UNIT_REGISTRY = pint.UnitRegistry( preprocessors=[ - lambda string: string.replace("%", "percent"), # allow %-sign lambda string: string.replace("Δ°", "delta_deg"), # parse Δ° for temperature ], force_ndarray_like=True, diff --git a/weldx/tests/_helpers.py b/weldx/tests/_helpers.py index 1a06c4161..661388d55 100644 --- a/weldx/tests/_helpers.py +++ b/weldx/tests/_helpers.py @@ -1,10 +1,10 @@ """Provides some utility functions for tests.""" +import importlib.metadata from typing import Any import numpy as np import pint -import importlib.metadata from weldx.constants import Q_ from weldx.geometry import _vector_is_close as vector_is_close @@ -130,7 +130,9 @@ 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 tuple(int(part) for part in importlib.metadata.version("pint").split(".")) >= (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 41afaab8c..904a456f7 100644 --- a/weldx/tests/transformations/_util.py +++ b/weldx/tests/transformations/_util.py @@ -3,7 +3,6 @@ from typing import Any import numpy as np -import importlib.metadata from xarray import DataArray import weldx.transformations as tf @@ -78,9 +77,7 @@ def check_coordinate_system( lcs.orientation, orientation_expected, positive_orientation_expected ) - atol_unit = 1.0 - if tuple(int(part) for part in importlib.metadata.version("pint").split(".")) >= (0, 21): - atol_unit = coordinates_expected.u + atol_unit = coordinates_expected.u assert np.allclose( lcs.coordinates.data, coordinates_expected, atol=1e-9 * atol_unit From dc9bbe8801bc3224331b1fcc064f59baa1afd94c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Ftay=20Fabry?= Date: Mon, 5 Aug 2024 13:52:41 +0200 Subject: [PATCH 3/8] clean up _helpers.py --- weldx/tests/_helpers.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/weldx/tests/_helpers.py b/weldx/tests/_helpers.py index 661388d55..e4bc8b80c 100644 --- a/weldx/tests/_helpers.py +++ b/weldx/tests/_helpers.py @@ -1,6 +1,5 @@ """Provides some utility functions for tests.""" -import importlib.metadata from typing import Any import numpy as np @@ -130,9 +129,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 tuple( - int(part) for part in importlib.metadata.version("pint").split(".") - ) >= (0, 21): + if isinstance(mat_b, pint.Quantity): atol_unit = mat_b.u return np.all(np.isclose(mat_a, mat_b, atol=abs_tol * atol_unit)).__bool__() From b6a03996e142f1917842b1bf9e485ee060afc2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Ftay=20Fabry?= Date: Mon, 5 Aug 2024 14:16:23 +0200 Subject: [PATCH 4/8] use select syntax for entry point --- weldx/config.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/weldx/config.py b/weldx/config.py index 5afe2958d..ea06a4b53 100644 --- a/weldx/config.py +++ b/weldx/config.py @@ -175,7 +175,9 @@ 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 importlib.metadata.entry_points()["weldx.standard"]: + for entry_point in importlib.metadata.entry_points().select( + group="weldx.standard" + ): standards = entry_point.load()() if not isinstance(standards, list): standards = [standards] From 17d790b9c87480b1da929635b53378ff095f1f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Ftay=20Fabry?= Date: Mon, 5 Aug 2024 14:29:09 +0200 Subject: [PATCH 5/8] add py39 dict syntax --- weldx/config.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/weldx/config.py b/weldx/config.py index ea06a4b53..316201fdf 100644 --- a/weldx/config.py +++ b/weldx/config.py @@ -3,6 +3,7 @@ from __future__ import annotations import importlib.metadata +import sys from pathlib import Path import asdf @@ -175,9 +176,13 @@ 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 importlib.metadata.entry_points().select( - group="weldx.standard" - ): + if sys.version_info < (3, 10): + entry_points = importlib.metadata.entry_points()["weldx.standard"] + else: + entry_points = importlib.metadata.entry_points().select( + group="weldx.standard" + ) + for entry_point in entry_points: standards = entry_point.load()() if not isinstance(standards, list): standards = [standards] From a3ead7e202b67ec695c97be9dbad76787ea69971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Ftay=20Fabry?= Date: Mon, 5 Aug 2024 15:09:50 +0200 Subject: [PATCH 6/8] catch empty case --- weldx/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weldx/config.py b/weldx/config.py index 316201fdf..b2a465fb0 100644 --- a/weldx/config.py +++ b/weldx/config.py @@ -177,7 +177,7 @@ def enable_quality_standard(name: str, version: AsdfVersion | str = None): def load_installed_standards(): """Load all standards that are installed to the active virtual environment.""" if sys.version_info < (3, 10): - entry_points = importlib.metadata.entry_points()["weldx.standard"] + entry_points = importlib.metadata.entry_points().get("weldx.standard", []) else: entry_points = importlib.metadata.entry_points().select( group="weldx.standard" From 3c85100f8cb57b88abeb3763cc02629d658f0e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Ftay=20Fabry?= Date: Mon, 5 Aug 2024 15:26:27 +0200 Subject: [PATCH 7/8] rebuild environment --- .github/workflows/docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index aed853505..156c4e416 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -54,7 +54,7 @@ jobs: init-shell: >- bash powershell - cache-environment: true + cache-environment: false - name: activate build env run: micromamba activate rtd From c7585e67b32130d2f3c68878354d15ba151b3a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Ftay=20Fabry?= Date: Mon, 5 Aug 2024 15:49:37 +0200 Subject: [PATCH 8/8] update docs dependencies and env file --- doc/rtd_environment.yml | 4 ++-- pyproject.toml | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/rtd_environment.yml b/doc/rtd_environment.yml index 9c6638dc8..a7f689520 100644 --- a/doc/rtd_environment.yml +++ b/doc/rtd_environment.yml @@ -32,5 +32,5 @@ dependencies: # pip packages - pip - pip: - - ../ - - ./json_mime_render_plugin/ + - weldx @ file:/../..// + - json_mime_render_plugin @ file:/..//json_mime_render_plugin diff --git a/pyproject.toml b/pyproject.toml index 4a33a85dd..4fd4335f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,16 @@ dependencies = [ "sympy>=1.6", "xarray>=2022.9", ] +optional-dependencies.docs = [ + "docutils>=0.19", + "numpydoc>=0.5", + "pydata-sphinx-theme<0.15", # parallel-write-unsafe + "sphinx>=4.1.1,==7.2", + "sphinx-autodoc-typehints>=1.21.8,==2", + "sphinx-copybutton==0.5", + "typing-extensions", + "urllib3<2", +] optional-dependencies.media = [ "av", "dask-image",