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

#2498 try different entry points method #2500

Merged
merged 4 commits into from
Nov 30, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

## Bug fixes

- Switched from `pkg_resources` to `importlib_metadata` for handling entry points ([#2500](https://github.com/pybamm-team/PyBaMM/pull/2500))
- Fixed some bugs related to processing `FunctionParameter` to `Interpolant` ([#2494](https://github.com/pybamm-team/PyBaMM/pull/2494))

## Optimizations
Expand Down
8 changes: 5 additions & 3 deletions pybamm/parameters/parameter_sets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warnings
import pkg_resources
import importlib_metadata
import textwrap
from collections.abc import Mapping

Expand Down Expand Up @@ -36,7 +36,9 @@ 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 pkg_resources.iter_entry_points("pybamm_parameter_sets"):
for entry_point in importlib_metadata.entry_points(
group="pybamm_parameter_sets"
):
self.__all_parameter_sets[entry_point.name] = entry_point

def __new__(cls):
Expand All @@ -55,7 +57,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, pkg_resources.EntryPoint):
if isinstance(ps, importlib_metadata.EntryPoint):
ps = self.__all_parameter_sets[key] = ps.load()
return ps

Expand Down