From af1c542698582a66a8a63ce0eb676d24d2f214ad Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Wed, 28 Dec 2022 10:44:07 +0100 Subject: [PATCH 1/7] #2534 fix --- pybamm/parameters/parameter_sets.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pybamm/parameters/parameter_sets.py b/pybamm/parameters/parameter_sets.py index 6144d1fdfc..e6a74906b6 100644 --- a/pybamm/parameters/parameter_sets.py +++ b/pybamm/parameters/parameter_sets.py @@ -1,5 +1,6 @@ import warnings import importlib_metadata +import setuptools._vendor.importlib_metadata as setuptools_metadata import textwrap from collections.abc import Mapping @@ -57,7 +58,9 @@ def __load_entry_point__(self, key) -> callable: if key not in self.__all_parameter_sets: raise KeyError(f"Unknown parameter set: {key}") ps = self.__all_parameter_sets[key] - if isinstance(ps, importlib_metadata.EntryPoint): + if isinstance( + ps, (importlib_metadata.EntryPoint, setuptools_metadata.EntryPoint) + ): ps = self.__all_parameter_sets[key] = ps.load() return ps From 1649bda69fab05c25840f0b988a25e9159cb0878 Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Wed, 28 Dec 2022 12:50:24 +0100 Subject: [PATCH 2/7] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc701aa0d5..0982b0bb39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ## Bug fixes +- Fixed bug with `EntryPoints` in Spyder IDE ([#2584](https://github.com/pybamm-team/PyBaMM/pull/2584)) - Fixed electrolyte conservation when options {"surface form": "algebraic"} are used - Fixed "constant concentration" electrolyte model so that "porosity times concentration" is conserved when porosity changes ([#2529](https://github.com/pybamm-team/PyBaMM/pull/2529)) - Fix installation on `Google Colab` (`pybtex` and `Colab` issue) ([#2526](https://github.com/pybamm-team/PyBaMM/pull/2526)) From 8a737f294c0a1673858730c38b6025731ad747a6 Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Wed, 28 Dec 2022 14:07:11 +0100 Subject: [PATCH 3/7] docs --- pybamm/parameters/parameter_sets.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pybamm/parameters/parameter_sets.py b/pybamm/parameters/parameter_sets.py index e6a74906b6..85c820c09b 100644 --- a/pybamm/parameters/parameter_sets.py +++ b/pybamm/parameters/parameter_sets.py @@ -1,6 +1,6 @@ import warnings import importlib_metadata -import setuptools._vendor.importlib_metadata as setuptools_metadata +import setuptools import textwrap from collections.abc import Mapping @@ -59,7 +59,11 @@ def __load_entry_point__(self, key) -> callable: raise KeyError(f"Unknown parameter set: {key}") ps = self.__all_parameter_sets[key] if isinstance( - ps, (importlib_metadata.EntryPoint, setuptools_metadata.EntryPoint) + ps, + ( + importlib_metadata.EntryPoint, + setuptools._vendor.importlib_metadata.EntryPoint, + ), ): ps = self.__all_parameter_sets[key] = ps.load() return ps From 8551da9c24f7bf4cad82b9a319518438892b2504 Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Wed, 28 Dec 2022 14:32:54 +0100 Subject: [PATCH 4/7] try another doc fix --- pybamm/parameters/parameter_sets.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pybamm/parameters/parameter_sets.py b/pybamm/parameters/parameter_sets.py index 85c820c09b..1f1665b5b2 100644 --- a/pybamm/parameters/parameter_sets.py +++ b/pybamm/parameters/parameter_sets.py @@ -5,6 +5,15 @@ from collections.abc import Mapping +def _is_entry_point(ps): + if isinstance(ps, importlib_metadata.EntryPoint): + return True + # Do this check separately to avoid calling setuptools unless necessary + if isinstance(ps, setuptools._vendor.importlib_metadata.EntryPoint): + return True + return False + + class ParameterSets(Mapping): """ Dict-like interface for accessing registered pybamm parameter sets. @@ -58,13 +67,7 @@ def __load_entry_point__(self, key) -> callable: if key not in self.__all_parameter_sets: raise KeyError(f"Unknown parameter set: {key}") ps = self.__all_parameter_sets[key] - if isinstance( - ps, - ( - importlib_metadata.EntryPoint, - setuptools._vendor.importlib_metadata.EntryPoint, - ), - ): + if _is_entry_point(ps): ps = self.__all_parameter_sets[key] = ps.load() return ps From f01006b3e819a16b4cf17f697177d83dff9e7527 Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Wed, 28 Dec 2022 14:41:41 +0100 Subject: [PATCH 5/7] use try-except --- pybamm/parameters/parameter_sets.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pybamm/parameters/parameter_sets.py b/pybamm/parameters/parameter_sets.py index 1f1665b5b2..2d8e666838 100644 --- a/pybamm/parameters/parameter_sets.py +++ b/pybamm/parameters/parameter_sets.py @@ -9,8 +9,12 @@ def _is_entry_point(ps): if isinstance(ps, importlib_metadata.EntryPoint): return True # Do this check separately to avoid calling setuptools unless necessary - if isinstance(ps, setuptools._vendor.importlib_metadata.EntryPoint): - return True + # and add the try-except in case setuptools._vendor is not available + try: + if isinstance(ps, setuptools._vendor.importlib_metadata.EntryPoint): + return True + except AttributeError: + return False return False From 0fc3032be7bf69d7e6495e27f50c3f2b0ca2671a Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Wed, 28 Dec 2022 19:03:54 +0100 Subject: [PATCH 6/7] try try-except instead --- pybamm/parameters/parameter_sets.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/pybamm/parameters/parameter_sets.py b/pybamm/parameters/parameter_sets.py index 2d8e666838..bb5ef177b9 100644 --- a/pybamm/parameters/parameter_sets.py +++ b/pybamm/parameters/parameter_sets.py @@ -1,23 +1,10 @@ import warnings -import importlib_metadata import setuptools +import importlib_metadata import textwrap from collections.abc import Mapping -def _is_entry_point(ps): - if isinstance(ps, importlib_metadata.EntryPoint): - return True - # Do this check separately to avoid calling setuptools unless necessary - # and add the try-except in case setuptools._vendor is not available - try: - if isinstance(ps, setuptools._vendor.importlib_metadata.EntryPoint): - return True - except AttributeError: - return False - return False - - class ParameterSets(Mapping): """ Dict-like interface for accessing registered pybamm parameter sets. @@ -71,8 +58,10 @@ def __load_entry_point__(self, key) -> callable: if key not in self.__all_parameter_sets: raise KeyError(f"Unknown parameter set: {key}") ps = self.__all_parameter_sets[key] - if _is_entry_point(ps): + try: ps = self.__all_parameter_sets[key] = ps.load() + except AttributeError: + pass return ps def __iter__(self): From c0eb90a18aed39289de0039de207217a5295838d Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Wed, 28 Dec 2022 19:08:51 +0100 Subject: [PATCH 7/7] flake8 --- pybamm/parameters/parameter_sets.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pybamm/parameters/parameter_sets.py b/pybamm/parameters/parameter_sets.py index bb5ef177b9..19871f1ee6 100644 --- a/pybamm/parameters/parameter_sets.py +++ b/pybamm/parameters/parameter_sets.py @@ -1,5 +1,4 @@ import warnings -import setuptools import importlib_metadata import textwrap from collections.abc import Mapping