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

replace usages of pkg_resources with importlib.metadata #941

Merged
merged 8 commits into from
Aug 5, 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: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
init-shell: >-
bash
powershell
cache-environment: true
cache-environment: false

- name: activate build env
run: micromamba activate rtd
Expand Down
2 changes: 1 addition & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ required-imports = [
"from __future__ import annotations",
]

[flake8-import-conventions]
[lint.flake8-import-conventions]
extend-aliases = { xarray = "xr" }
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +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` \[{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)

Expand Down
4 changes: 2 additions & 2 deletions doc/rtd_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ dependencies:
# pip packages
- pip
- pip:
- ../
- ./json_mime_render_plugin/
- weldx @ file:/../..//
- json_mime_render_plugin @ file:/..//json_mime_render_plugin
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,23 @@ 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",
"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",
Expand Down
11 changes: 9 additions & 2 deletions weldx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

from __future__ import annotations

import importlib.metadata
import sys
from pathlib import Path

import asdf
import pkg_resources
import yaml
from asdf.config import ResourceMappingProxy
from asdf.versioning import AsdfVersion, split_tag_version
Expand Down Expand Up @@ -175,7 +176,13 @@
@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"):
if sys.version_info < (3, 10):
entry_points = importlib.metadata.entry_points().get("weldx.standard", [])

Check warning on line 180 in weldx/config.py

View check run for this annotation

Codecov / codecov/patch

weldx/config.py#L180

Added line #L180 was not covered by tests
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]
Expand Down
1 change: 0 additions & 1 deletion weldx/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions weldx/tests/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import pint
from pkg_resources import get_distribution

from weldx.constants import Q_
from weldx.geometry import _vector_is_close as vector_is_close
Expand Down Expand Up @@ -130,7 +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 get_distribution("pint").version >= "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__()
5 changes: 1 addition & 4 deletions weldx/tests/transformations/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Any

import numpy as np
from pkg_resources import get_distribution
from xarray import DataArray

import weldx.transformations as tf
Expand Down Expand Up @@ -78,9 +77,7 @@ def check_coordinate_system(
lcs.orientation, orientation_expected, positive_orientation_expected
)

atol_unit = 1.0
if get_distribution("pint").version >= "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
Expand Down
Loading