Skip to content

Commit 3448053

Browse files
authored
plugin entrypoint compatibility fix for python 3.7 (psyplot#47)
* plugin entrypoint compatibility fix for python 3.7 * use psyplot-ci-orb@1.5.31 * [skip ci] update changelog
1 parent ae1854f commit 3448053

5 files changed

Lines changed: 30 additions & 15 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 2.1
22

33
orbs:
4-
psyplot: psyplot/psyplot-ci-orb@1.5.29
4+
psyplot: psyplot/psyplot-ci-orb@1.5.31
55
mattermost-plugin-notify: nathanaelhoun/mattermost-plugin-notify@1.2.0
66

77
executors:

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v1.4.2
2+
======
3+
Fix for compatibility with python 3.7
4+
15
v1.4.1
26
======
37
Compatibility fixes and minor improvements

psyplot/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,10 @@ def get_versions(requirements=True, key=None):
123123
}
124124
}
125125
"""
126-
from importlib.metadata import entry_points
127-
ret = {'psyplot': _get_versions(requirements)}
126+
from psyplot.utils import plugin_entrypoints
127+
eps = plugin_entrypoints("psyplot", "plugin")
128128

129-
try:
130-
eps = entry_points(group='psyplot', name='plugin')
131-
except TypeError: # python<3.10
132-
eps = [ep for ep in entry_points().get('psyplot', [])
133-
if ep.name == 'plugin']
129+
ret = {'psyplot': _get_versions(requirements)}
134130
for ep in eps:
135131
if str(ep) in rcParams._plugins:
136132
logger.debug('Loading entrypoint %s', ep)

psyplot/config/rcsetup.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -757,14 +757,17 @@ def _load_plugin_entrypoints(self):
757757
------
758758
importlib.metadata.EntryPoint
759759
The entry point for the psyplot plugin module"""
760-
from importlib.metadata import entry_points
760+
from psyplot.utils import plugin_entrypoints
761761

762762
def load_plugin(ep):
763763

764764
try:
765765
ep.module
766766
except AttributeError: # python<3.10
767-
ep.module = ep.pattern.match(ep.value).group("module")
767+
try:
768+
ep.module = ep.pattern.match(ep.value).group("module")
769+
except AttributeError: # python<3.8
770+
ep.module = ep.module_name
768771

769772
if plugins_env == ['no']:
770773
return False
@@ -782,11 +785,7 @@ def load_plugin(ep):
782785

783786
logger = logging.getLogger(__name__)
784787

785-
try:
786-
eps = entry_points(group='psyplot', name='plugin')
787-
except TypeError: # python<3.10
788-
eps = [ep for ep in entry_points().get('psyplot', [])
789-
if ep.name == 'plugin']
788+
eps = plugin_entrypoints("psyplot", "plugin")
790789
for ep in eps:
791790
if not load_plugin(ep):
792791
logger.debug('Skipping entrypoint %s', ep)

psyplot/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# You should have received a copy of the GNU LGPL-3.0 license
2424
# along with this program. If not, see <https://www.gnu.org/licenses/>.
2525

26+
import sys
2627
import re
2728
import six
2829
from difflib import get_close_matches
@@ -31,6 +32,21 @@
3132
from psyplot.docstring import dedent, docstrings
3233

3334

35+
def plugin_entrypoints(group="psyplot", name="name"):
36+
"""This utility function gets the entry points of the psyplot plugins"""
37+
if sys.version_info[:2] > (3, 7):
38+
from importlib.metadata import entry_points
39+
try:
40+
eps = entry_points(group=group, name=name)
41+
except TypeError: # python<3.10
42+
eps = [ep for ep in entry_points().get(group, [])
43+
if ep.name == name]
44+
else:
45+
from pkg_resources import iter_entry_points
46+
eps = iter_entry_points(group=group, name=name)
47+
return eps
48+
49+
3450
class DefaultOrderedDict(OrderedDict):
3551
"""An ordered :class:`collections.defaultdict`
3652

0 commit comments

Comments
 (0)