From 9a393a6e762f9ae4e9cc57d7d90ede6bc19e431a Mon Sep 17 00:00:00 2001 From: Philipp Sommer Date: Sun, 21 Nov 2021 23:34:14 +0100 Subject: [PATCH 1/7] fix compatibility issues for python 3.10 closes #42 --- psyplot/__init__.py | 25 ++++++++++++++----------- psyplot/__main__.py | 2 +- psyplot/config/rcsetup.py | 18 +++++++++--------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/psyplot/__init__.py b/psyplot/__init__.py index 0358f05..2b2f278 100755 --- a/psyplot/__init__.py +++ b/psyplot/__init__.py @@ -123,24 +123,27 @@ def get_versions(requirements=True, key=None): } } """ - from pkg_resources import iter_entry_points + from importlib.metadata import entry_points ret = {'psyplot': _get_versions(requirements)} - for ep in iter_entry_points(group='psyplot', name='plugin'): + for ep in entry_points(group='psyplot', name='plugin'): if str(ep) in rcParams._plugins: logger.debug('Loading entrypoint %s', ep) - if key is not None and not key(ep.module_name): + if key is not None and not key(ep.module): continue try: mod = ep.load() except (ImportError, ModuleNotFoundError) as e: - logger.debug("Could not import %s" % ep, exc_info=True) - logger.warning("Could not import %s" % ep) - try: - ret[str(ep.module_name)] = mod.get_versions(requirements) - except AttributeError: - ret[str(ep.module_name)] = { - 'version': getattr(mod, 'plugin_version', - getattr(mod, '__version__', ''))} + logger.debug("Could not import %s" % (ep, ), exc_info=True) + logger.warning("Could not import %s" % (ep, ), exc_info=True) + else: + try: + ret[str(ep.module)] = mod.get_versions(requirements) + except AttributeError: + ret[str(ep.module)] = { + 'version': getattr( + mod, 'plugin_version', + getattr(mod, '__version__', '')) + } if key is None: try: import psyplot_gui diff --git a/psyplot/__main__.py b/psyplot/__main__.py index 5acd83f..796e754 100644 --- a/psyplot/__main__.py +++ b/psyplot/__main__.py @@ -61,7 +61,7 @@ def main(args=None): The parser that has been used from the command line""" try: from psyplot_gui import get_parser as _get_parser - except ImportError: + except (ImportError, ModuleNotFoundError) as e: logger.debug('Failed to import gui', exc_info=True) parser = get_parser(create=False) parser.update_arg('output', required=True) diff --git a/psyplot/config/rcsetup.py b/psyplot/config/rcsetup.py index 3e90954..c1bc73e 100755 --- a/psyplot/config/rcsetup.py +++ b/psyplot/config/rcsetup.py @@ -755,16 +755,16 @@ def _load_plugin_entrypoints(self): Yields ------ - pkg_resources.EntryPoint + importlib.metadata.EntryPoint The entry point for the psyplot plugin module""" - from pkg_resources import iter_entry_points + from importlib.metadata import entry_points def load_plugin(ep): if plugins_env == ['no']: return False - elif ep.module_name in exclude_plugins: + elif ep.module in exclude_plugins: return False - elif include_plugins and ep.module_name not in include_plugins: + elif include_plugins and ep.module not in include_plugins: return False return True @@ -776,7 +776,7 @@ def load_plugin(ep): logger = logging.getLogger(__name__) - for ep in iter_entry_points(group='psyplot', name='plugin'): + for ep in entry_points(group='psyplot', name='plugin'): if not load_plugin(ep): logger.debug('Skipping entrypoint %s', ep) continue @@ -811,7 +811,7 @@ def load_plugins(self, raise_error=False): def_keys = {'default': defaultParams} def register_pm(ep, name): - full_name = '%s:%s' % (ep.module_name, name) + full_name = '%s:%s' % (ep.module, name) ret = True if pm_env == ['no']: ret = False @@ -828,8 +828,8 @@ def register_pm(ep, name): try: plugin_mod = ep.load() except (ModuleNotFoundError, ImportError): - logger.debug("Failed to import %s!" % ep, exc_info=True) - logger.warning("Failed to import %s!" % ep) + logger.debug("Failed to import %s!" % (ep, ), exc_info=True) + logger.warning("Failed to import %s!" % (ep, )) continue rc = plugin_mod.rcParams @@ -852,7 +852,7 @@ def register_pm(ep, name): else: warn(msg) for d in plugin_plotters.values(): - d['plugin'] = ep.module_name + d['plugin'] = ep.module plotters.update(plugin_plotters) def_plots[ep] = list(plugin_plotters) From d1373c11c9ab9e0583eb454bc274c0d25c1107b5 Mon Sep 17 00:00:00 2001 From: Philipp Sommer Date: Mon, 22 Nov 2021 00:14:43 +0100 Subject: [PATCH 2/7] compatibility fixes for python<3.10 --- psyplot/__init__.py | 14 +++++++++++++- psyplot/config/rcsetup.py | 13 ++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/psyplot/__init__.py b/psyplot/__init__.py index 2b2f278..eacf72a 100755 --- a/psyplot/__init__.py +++ b/psyplot/__init__.py @@ -125,9 +125,21 @@ def get_versions(requirements=True, key=None): """ from importlib.metadata import entry_points ret = {'psyplot': _get_versions(requirements)} - for ep in entry_points(group='psyplot', name='plugin'): + + try: + eps = entry_points(group='psyplot', name='plugin') + except TypeError: # python<3.10 + eps = [ep for ep in entry_points()['psyplot'] + if ep.name == 'plugin'] + for ep in eps: if str(ep) in rcParams._plugins: logger.debug('Loading entrypoint %s', ep) + + try: + ep.module + except AttributeError: # python<3.10 + ep.module = ep.pattern.match(ep.value).group("module") + if key is not None and not key(ep.module): continue try: diff --git a/psyplot/config/rcsetup.py b/psyplot/config/rcsetup.py index c1bc73e..5abb261 100755 --- a/psyplot/config/rcsetup.py +++ b/psyplot/config/rcsetup.py @@ -760,6 +760,12 @@ def _load_plugin_entrypoints(self): from importlib.metadata import entry_points def load_plugin(ep): + + try: + ep.module + except AttributeError: # python<3.10 + ep.module = ep.pattern.match(ep.value).group("module") + if plugins_env == ['no']: return False elif ep.module in exclude_plugins: @@ -776,7 +782,12 @@ def load_plugin(ep): logger = logging.getLogger(__name__) - for ep in entry_points(group='psyplot', name='plugin'): + try: + eps = entry_points(group='psyplot', name='plugin') + except TypeError: # python<3.10 + eps = [ep for ep in entry_points()['psyplot'] + if ep.name == 'plugin'] + for ep in eps: if not load_plugin(ep): logger.debug('Skipping entrypoint %s', ep) continue From 7db0f45dde4139b745006fe0f949f932b361b938 Mon Sep 17 00:00:00 2001 From: Philipp Sommer Date: Mon, 22 Nov 2021 09:13:25 +0100 Subject: [PATCH 3/7] minor --- psyplot/__init__.py | 2 +- psyplot/config/rcsetup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/psyplot/__init__.py b/psyplot/__init__.py index eacf72a..7f40203 100755 --- a/psyplot/__init__.py +++ b/psyplot/__init__.py @@ -129,7 +129,7 @@ def get_versions(requirements=True, key=None): try: eps = entry_points(group='psyplot', name='plugin') except TypeError: # python<3.10 - eps = [ep for ep in entry_points()['psyplot'] + eps = [ep for ep in entry_points().get('psyplot', []) if ep.name == 'plugin'] for ep in eps: if str(ep) in rcParams._plugins: diff --git a/psyplot/config/rcsetup.py b/psyplot/config/rcsetup.py index 5abb261..c186e7a 100755 --- a/psyplot/config/rcsetup.py +++ b/psyplot/config/rcsetup.py @@ -785,7 +785,7 @@ def load_plugin(ep): try: eps = entry_points(group='psyplot', name='plugin') except TypeError: # python<3.10 - eps = [ep for ep in entry_points()['psyplot'] + eps = [ep for ep in entry_points().get('psyplot', []) if ep.name == 'plugin'] for ep in eps: if not load_plugin(ep): From 7f1ca3562c7fbd72af75dd35d17c441b284350e0 Mon Sep 17 00:00:00 2001 From: Philipp Sommer Date: Mon, 22 Nov 2021 11:41:26 +0100 Subject: [PATCH 4/7] remove _validate parameter when loading figure compatibility fix for matplotlib=3.5 --- psyplot/project.py | 1 + 1 file changed, 1 insertion(+) diff --git a/psyplot/project.py b/psyplot/project.py index cda542e..6336ce0 100755 --- a/psyplot/project.py +++ b/psyplot/project.py @@ -1634,6 +1634,7 @@ def load_figure(d, new_fig=True): subplotpars = d.pop('subplotpars', None) if subplotpars is not None: subplotpars.pop('validate', None) + subplotpars.pop('_validate', None) subplotpars = mfig.SubplotParams(**subplotpars) if new_fig: nums = plt.get_fignums() From 531e55dee7fe07b23c74a5ec778482368af06964 Mon Sep 17 00:00:00 2001 From: Philipp Sommer Date: Mon, 22 Nov 2021 11:44:35 +0100 Subject: [PATCH 5/7] add pipeline parameter for python version --- .circleci/config.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7a6b8d4..7520dfd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,6 +25,10 @@ parameters: description: Build the documentation type: boolean default: true + python_version: + description: The python version to build + type: string + default: "3.8" workflows: build-and-test: @@ -36,6 +40,7 @@ workflows: setup_env: << pipeline.parameters.run-tests >> build_args: "--no-test" build_docs: << pipeline.parameters.build_docs >> + python_version: << pipeline.parameters.python_version >> # HACK: force netcdf4 and hdf5 version to resolve dependency issue env_packages: dask netcdf4 scipy netcdf4=1.5.7 h5py=3.4.0 hdf5=1.12.1 - psyplot/test-parallel: From 92113a53021f519fc1069e1ae1e7c8c3f8233081 Mon Sep 17 00:00:00 2001 From: Philipp Sommer Date: Mon, 22 Nov 2021 12:12:08 +0100 Subject: [PATCH 6/7] remove unnecessary specifications as these issues seem to be resolved --- .circleci/config.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7520dfd..a8c6cdf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,8 +41,7 @@ workflows: build_args: "--no-test" build_docs: << pipeline.parameters.build_docs >> python_version: << pipeline.parameters.python_version >> - # HACK: force netcdf4 and hdf5 version to resolve dependency issue - env_packages: dask netcdf4 scipy netcdf4=1.5.7 h5py=3.4.0 hdf5=1.12.1 + env_packages: dask netcdf4 scipy - psyplot/test-parallel: name: test-xarray-latest parallelism: 2 From bb913176681b4ceeb5eec21ffcd0ca4a531ab52e Mon Sep 17 00:00:00 2001 From: Philipp Sommer Date: Mon, 22 Nov 2021 14:17:41 +0100 Subject: [PATCH 7/7] [skip ci] update changelog --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bc85dc8..499da4c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,7 @@ Fixed ----- - the update method now only takes the coordinates that are dimensions in the dataset see `#39 `__ +- psyplot is now compatible with matplotlib 3.5 and python 3.10 Changed -------