From d403f2f68024df2a9d263023144c6773581f805d Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Fri, 18 Aug 2023 13:04:18 +0100 Subject: [PATCH 1/2] Removed load_plugins and use the one from glue-core --- glue_qt/main.py | 100 +----------------------------------------------- 1 file changed, 1 insertion(+), 99 deletions(-) diff --git a/glue_qt/main.py b/glue_qt/main.py index 2462ee97..53409e5c 100755 --- a/glue_qt/main.py +++ b/glue_qt/main.py @@ -6,6 +6,7 @@ from glue import __version__ from glue.logger import logger +from glue.main import load_plugins def parse(argv): @@ -253,104 +254,5 @@ def main(argv=sys.argv): start_glue(**kwargs) -_loaded_plugins = set() -_installed_plugins = set() - -REQUIRED_PLUGINS = ['glue.plugins.coordinate_helpers', - 'glue.core.data_exporters', - 'glue.io.formats.fits'] - - -REQUIRED_PLUGINS_QT = ['glue_qt.plugins.tools.pv_slicer.qt', - 'glue_qt.viewers.image.qt', - 'glue_qt.viewers.scatter.qt', - 'glue_qt.viewers.histogram.qt', - 'glue_qt.viewers.profile.qt', - 'glue_qt.viewers.table.qt'] - - -def load_plugins(splash=None, require_qt_plugins=False): - - # Search for plugins installed via entry_points. Basically, any package can - # define plugins for glue, and needs to define an entry point using the - # following format: - # - # entry_points = """ - # [glue.plugins] - # webcam_importer=glue_exp.importers.webcam:setup - # vizier_importer=glue_exp.importers.vizier:setup - # dataverse_importer=glue_exp.importers.dataverse:setup - # """ - # - # where ``setup`` is a function that does whatever is needed to set up the - # plugin, such as add items to various registries. - - import setuptools - logger.info("Loading external plugins using " - "setuptools=={0}".format(setuptools.__version__)) - - from glue._plugin_helpers import iter_plugin_entry_points, PluginConfig - config = PluginConfig.load() - - n_plugins = len(list(iter_plugin_entry_points())) - - for iplugin, item in enumerate(iter_plugin_entry_points()): - if item.module not in _installed_plugins: - _installed_plugins.add(item.name) - - if item.module in _loaded_plugins: - logger.info("Plugin {0} already loaded".format(item.name)) - continue - - if not config.plugins[item.name]: - continue - - # We don't use item.load() because that then checks requirements of all - # the imported packages, which can lead to errors like this one that - # don't really matter: - # - # Exception: (pytest 2.6.0 (/Users/tom/miniconda3/envs/py27/lib/python2.7/site-packages), - # Requirement.parse('pytest>=2.8'), set(['astropy'])) - # - # Just to be clear, this kind of error does indicate that there is an - # old version of a package in the environment, but this can confuse - # users as importing astropy directly would work (as setuptools then - # doesn't do a stringent test of dependency versions). Often this kind - # of error can occur if there is a conda version of a package and and - # older pip version. - - try: - module = import_module(item.module) - function = getattr(module, item.attr) - function() - except Exception as exc: - # Here we check that some of the 'core' plugins load well and - # raise an actual exception if not. - if item.module in REQUIRED_PLUGINS: - raise - elif item.module in REQUIRED_PLUGINS_QT and require_qt_plugins: - raise - else: - logger.info("Loading plugin {0} failed " - "(Exception: {1})".format(item.name, exc)) - else: - logger.info("Loading plugin {0} succeeded".format(item.name)) - _loaded_plugins.add(item.module) - - if splash is not None: - splash.set_progress(100. * iplugin / float(n_plugins)) - - try: - config.save() - except Exception as e: - logger.warn("Failed to load plugin configuration") - - # Reload the settings now that we have loaded plugins, since some plugins - # may have added some settings. Note that this will not re-read settings - # that were previously read. - from glue._settings_helpers import load_settings - load_settings() - - if __name__ == "__main__": sys.exit(main(sys.argv)) # pragma: no cover From f8571ad716547a3c5406f417a5034b41483a437a Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Fri, 18 Aug 2023 13:04:47 +0100 Subject: [PATCH 2/2] Remove unused import --- glue_qt/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/glue_qt/main.py b/glue_qt/main.py index 53409e5c..4f6634bd 100755 --- a/glue_qt/main.py +++ b/glue_qt/main.py @@ -2,7 +2,6 @@ import sys import optparse -from importlib import import_module from glue import __version__ from glue.logger import logger