From 642beccc48ea4c57b8148c0bf39da3da3808230c Mon Sep 17 00:00:00 2001 From: Philipp Sommer Date: Thu, 6 Jan 2022 09:10:36 +0100 Subject: [PATCH 1/3] plugin entrypoint compatibility fix for python 3.7 --- psyplot/__init__.py | 10 +++------- psyplot/config/rcsetup.py | 13 ++++++------- psyplot/utils.py | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/psyplot/__init__.py b/psyplot/__init__.py index 7f40203..c129bd5 100755 --- a/psyplot/__init__.py +++ b/psyplot/__init__.py @@ -123,14 +123,10 @@ def get_versions(requirements=True, key=None): } } """ - from importlib.metadata import entry_points - ret = {'psyplot': _get_versions(requirements)} + from psyplot.utils import plugin_entrypoints + eps = plugin_entrypoints("psyplot", "plugin") - try: - eps = entry_points(group='psyplot', name='plugin') - except TypeError: # python<3.10 - eps = [ep for ep in entry_points().get('psyplot', []) - if ep.name == 'plugin'] + ret = {'psyplot': _get_versions(requirements)} for ep in eps: if str(ep) in rcParams._plugins: logger.debug('Loading entrypoint %s', ep) diff --git a/psyplot/config/rcsetup.py b/psyplot/config/rcsetup.py index cfacfd5..8124674 100755 --- a/psyplot/config/rcsetup.py +++ b/psyplot/config/rcsetup.py @@ -757,14 +757,17 @@ def _load_plugin_entrypoints(self): ------ importlib.metadata.EntryPoint The entry point for the psyplot plugin module""" - from importlib.metadata import entry_points + from psyplot.utils import plugin_entrypoints def load_plugin(ep): try: ep.module except AttributeError: # python<3.10 - ep.module = ep.pattern.match(ep.value).group("module") + try: + ep.module = ep.pattern.match(ep.value).group("module") + except AttributeError: # python<3.8 + ep.module = ep.module_name if plugins_env == ['no']: return False @@ -782,11 +785,7 @@ def load_plugin(ep): logger = logging.getLogger(__name__) - try: - eps = entry_points(group='psyplot', name='plugin') - except TypeError: # python<3.10 - eps = [ep for ep in entry_points().get('psyplot', []) - if ep.name == 'plugin'] + eps = plugin_entrypoints("psyplot", "plugin") for ep in eps: if not load_plugin(ep): logger.debug('Skipping entrypoint %s', ep) diff --git a/psyplot/utils.py b/psyplot/utils.py index b10f66e..b508d6f 100644 --- a/psyplot/utils.py +++ b/psyplot/utils.py @@ -23,6 +23,7 @@ # You should have received a copy of the GNU LGPL-3.0 license # along with this program. If not, see . +import sys import re import six from difflib import get_close_matches @@ -31,6 +32,21 @@ from psyplot.docstring import dedent, docstrings +def plugin_entrypoints(group="psyplot", name="name"): + """This utility function gets the entry points of the psyplot plugins""" + if sys.version_info[:2] > (3, 7): + from importlib.metadata import entry_points + try: + eps = entry_points(group=group, name=name) + except TypeError: # python<3.10 + eps = [ep for ep in entry_points().get(group, []) + if ep.name == name] + else: + from pkg_resources import iter_entry_points + eps = iter_entry_points(group=group, name=name) + return eps + + class DefaultOrderedDict(OrderedDict): """An ordered :class:`collections.defaultdict` From 4f2c792516586bd21c9851cd8e26bd8dc8861cc7 Mon Sep 17 00:00:00 2001 From: Philipp Sommer Date: Sun, 13 Feb 2022 21:26:20 +0100 Subject: [PATCH 2/3] use psyplot-ci-orb@1.5.31 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 67cd829..09d8850 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,7 @@ version: 2.1 orbs: - psyplot: psyplot/psyplot-ci-orb@1.5.29 + psyplot: psyplot/psyplot-ci-orb@1.5.31 mattermost-plugin-notify: nathanaelhoun/mattermost-plugin-notify@1.2.0 executors: From 8dbd8c1f5ebb88d19a69488ead08271ba9521419 Mon Sep 17 00:00:00 2001 From: Philipp Sommer Date: Sun, 13 Feb 2022 22:04:35 +0100 Subject: [PATCH 3/3] [skip ci] update changelog --- CHANGELOG.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 499da4c..56755df 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,7 @@ +v1.4.2 +====== +Fix for compatibility with python 3.7 + v1.4.1 ====== Compatibility fixes and minor improvements