From 3eb2b5b5b607c042331d82ae59e5a1740f66bae7 Mon Sep 17 00:00:00 2001 From: kratman Date: Thu, 14 Sep 2023 13:01:43 -0400 Subject: [PATCH 1/7] First attempt at the removal --- pybamm/util.py | 6 +++--- tests/unit/test_parameters/test_parameter_sets_class.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pybamm/util.py b/pybamm/util.py index 5f84f37e0a..94963f5789 100644 --- a/pybamm/util.py +++ b/pybamm/util.py @@ -18,7 +18,7 @@ from warnings import warn import numpy as np -import pkg_resources +import importlib_metadata as il import pybamm @@ -272,8 +272,8 @@ def have_jax(): def is_jax_compatible(): """Check if the available version of jax and jaxlib are compatible with PyBaMM""" return ( - pkg_resources.get_distribution("jax").version == JAX_VERSION - and pkg_resources.get_distribution("jaxlib").version == JAXLIB_VERSION + il.distribution("jax").version == JAX_VERSION + and il.distribution("jaxlib").version == JAXLIB_VERSION ) diff --git a/tests/unit/test_parameters/test_parameter_sets_class.py b/tests/unit/test_parameters/test_parameter_sets_class.py index f548fd7955..7dbc11d305 100644 --- a/tests/unit/test_parameters/test_parameter_sets_class.py +++ b/tests/unit/test_parameters/test_parameter_sets_class.py @@ -4,7 +4,7 @@ from tests import TestCase import pybamm -import pkg_resources +import importlib_metadata as il import unittest @@ -25,7 +25,7 @@ def test_all_registered(self): """Check that all parameter sets have been registered with the ``pybamm_parameter_sets`` entry point""" known_entry_points = set( - ep.name for ep in pkg_resources.iter_entry_points("pybamm_parameter_sets") + ep.name for ep in il.entry_points("pybamm_parameter_sets") ) self.assertEqual(set(pybamm.parameter_sets.keys()), known_entry_points) self.assertEqual(len(known_entry_points), len(pybamm.parameter_sets)) From 460330d94fd23c3e75afcf089c4374a02f08483e Mon Sep 17 00:00:00 2001 From: kratman Date: Thu, 14 Sep 2023 13:11:43 -0400 Subject: [PATCH 2/7] Fix the test --- tests/unit/test_parameters/test_parameter_sets_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_parameters/test_parameter_sets_class.py b/tests/unit/test_parameters/test_parameter_sets_class.py index 7dbc11d305..0413e9e52c 100644 --- a/tests/unit/test_parameters/test_parameter_sets_class.py +++ b/tests/unit/test_parameters/test_parameter_sets_class.py @@ -25,7 +25,7 @@ def test_all_registered(self): """Check that all parameter sets have been registered with the ``pybamm_parameter_sets`` entry point""" known_entry_points = set( - ep.name for ep in il.entry_points("pybamm_parameter_sets") + ep.name for ep in il.entry_points().select(group="pybamm_parameter_sets") ) self.assertEqual(set(pybamm.parameter_sets.keys()), known_entry_points) self.assertEqual(len(known_entry_points), len(pybamm.parameter_sets)) From 34aca1c81b5ac70e8f7238c31d1af662238377c5 Mon Sep 17 00:00:00 2001 From: kratman Date: Thu, 14 Sep 2023 13:46:05 -0400 Subject: [PATCH 3/7] Adjust import name --- pybamm/util.py | 2 +- tests/unit/test_parameters/test_parameter_sets_class.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pybamm/util.py b/pybamm/util.py index 94963f5789..49453beb7c 100644 --- a/pybamm/util.py +++ b/pybamm/util.py @@ -18,7 +18,7 @@ from warnings import warn import numpy as np -import importlib_metadata as il +import importlib.metadata as il import pybamm diff --git a/tests/unit/test_parameters/test_parameter_sets_class.py b/tests/unit/test_parameters/test_parameter_sets_class.py index 0413e9e52c..6e90881d9e 100644 --- a/tests/unit/test_parameters/test_parameter_sets_class.py +++ b/tests/unit/test_parameters/test_parameter_sets_class.py @@ -4,7 +4,7 @@ from tests import TestCase import pybamm -import importlib_metadata as il +import importlib.metadata as il import unittest From 07f7068d3b1916ad39e62c57b57188a86141578c Mon Sep 17 00:00:00 2001 From: kratman Date: Thu, 14 Sep 2023 14:00:16 -0400 Subject: [PATCH 4/7] Fix the selection --- tests/unit/test_parameters/test_parameter_sets_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_parameters/test_parameter_sets_class.py b/tests/unit/test_parameters/test_parameter_sets_class.py index 6e90881d9e..509e6adade 100644 --- a/tests/unit/test_parameters/test_parameter_sets_class.py +++ b/tests/unit/test_parameters/test_parameter_sets_class.py @@ -25,7 +25,7 @@ def test_all_registered(self): """Check that all parameter sets have been registered with the ``pybamm_parameter_sets`` entry point""" known_entry_points = set( - ep.name for ep in il.entry_points().select(group="pybamm_parameter_sets") + ep.name for ep in il.entry_points()["pybamm_parameter_sets"] ) self.assertEqual(set(pybamm.parameter_sets.keys()), known_entry_points) self.assertEqual(len(known_entry_points), len(pybamm.parameter_sets)) From 446ada26f73883708591c281126bb772104350de Mon Sep 17 00:00:00 2001 From: kratman Date: Tue, 19 Sep 2023 09:11:15 -0400 Subject: [PATCH 5/7] Empty commit From 4df48500834377d06ddcaa5ba6452cae03bbb725 Mon Sep 17 00:00:00 2001 From: kratman Date: Tue, 19 Sep 2023 10:56:30 -0400 Subject: [PATCH 6/7] Fixes from review --- pybamm/parameters/parameter_sets.py | 11 ++++++++++- pybamm/util.py | 6 +++--- .../unit/test_parameters/test_parameter_sets_class.py | 3 +-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pybamm/parameters/parameter_sets.py b/pybamm/parameters/parameter_sets.py index 1da7f239dd..3174bcc1f4 100644 --- a/pybamm/parameters/parameter_sets.py +++ b/pybamm/parameters/parameter_sets.py @@ -1,3 +1,4 @@ +import sys import warnings import importlib.metadata import textwrap @@ -37,9 +38,17 @@ class ParameterSets(Mapping): def __init__(self): # Dict of entry points for parameter sets, lazily load entry points as self.__all_parameter_sets = dict() - for entry_point in importlib.metadata.entry_points()["pybamm_parameter_sets"]: + for entry_point in self.get_entries("pybamm_parameter_sets"): self.__all_parameter_sets[entry_point.name] = entry_point + @staticmethod + def get_entries(group_name): + # Wrapper for the importlib version logic + if sys.version_info < (3, 10): + return importlib.metadata.entry_points()[group_name] + else: + return importlib.metadata.entry_points(group=group_name) + def __new__(cls): """Ensure only one instance of ParameterSets exists""" if not hasattr(cls, "instance"): diff --git a/pybamm/util.py b/pybamm/util.py index 8be89c2689..562352bfac 100644 --- a/pybamm/util.py +++ b/pybamm/util.py @@ -18,7 +18,7 @@ from warnings import warn import numpy as np -import importlib.metadata as il +import importlib.metadata import pybamm @@ -272,8 +272,8 @@ def have_jax(): def is_jax_compatible(): """Check if the available version of jax and jaxlib are compatible with PyBaMM""" return ( - il.distribution("jax").version.startswith(JAX_VERSION) - and il.distribution("jaxlib").version.startswith(JAXLIB_VERSION) + importlib.metadata.distribution("jax").version.startswith(JAX_VERSION) + and importlib.metadata.distribution("jaxlib").version.startswith(JAXLIB_VERSION) ) diff --git a/tests/unit/test_parameters/test_parameter_sets_class.py b/tests/unit/test_parameters/test_parameter_sets_class.py index 509e6adade..b14000f987 100644 --- a/tests/unit/test_parameters/test_parameter_sets_class.py +++ b/tests/unit/test_parameters/test_parameter_sets_class.py @@ -4,7 +4,6 @@ from tests import TestCase import pybamm -import importlib.metadata as il import unittest @@ -25,7 +24,7 @@ def test_all_registered(self): """Check that all parameter sets have been registered with the ``pybamm_parameter_sets`` entry point""" known_entry_points = set( - ep.name for ep in il.entry_points()["pybamm_parameter_sets"] + ep.name for ep in pybamm.parameter_sets.get_entries("pybamm_parameter_sets") ) self.assertEqual(set(pybamm.parameter_sets.keys()), known_entry_points) self.assertEqual(len(known_entry_points), len(pybamm.parameter_sets)) From 31c362d7c8c8fb5828b291878c1c14907a6a5868 Mon Sep 17 00:00:00 2001 From: "Eric G. Kratz" Date: Fri, 22 Sep 2023 07:59:02 -0400 Subject: [PATCH 7/7] Update pybamm/parameters/parameter_sets.py --- pybamm/parameters/parameter_sets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pybamm/parameters/parameter_sets.py b/pybamm/parameters/parameter_sets.py index 3174bcc1f4..6c6201d9af 100644 --- a/pybamm/parameters/parameter_sets.py +++ b/pybamm/parameters/parameter_sets.py @@ -44,7 +44,7 @@ def __init__(self): @staticmethod def get_entries(group_name): # Wrapper for the importlib version logic - if sys.version_info < (3, 10): + if sys.version_info < (3, 10): # pragma: no cover return importlib.metadata.entry_points()[group_name] else: return importlib.metadata.entry_points(group=group_name)