From 28f27ef3b895d2f53b15d369bcc97b0fae0010ac Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Fri, 11 Aug 2023 11:29:45 +0100 Subject: [PATCH] Fix imports and remaining tests --- doc/customizing_guide/customization.rst | 2 +- glue_qt/app/qt/feedback.py | 6 +++--- glue_qt/app/qt/preferences.py | 2 +- glue_qt/app/qt/tests/test_application.py | 2 +- glue_qt/app/qt/tests/test_preferences.py | 2 +- glue_qt/app/qt/versions.py | 4 ++-- glue_qt/conftest.py | 7 ------- .../qt/tests/test_subset_facet.py | 2 +- glue_qt/main.py | 20 +++++++++---------- glue_qt/utils/qt/dialogs.py | 7 +++++-- glue_qt/utils/qt/tests/test_dialogs.py | 4 ++-- 11 files changed, 27 insertions(+), 31 deletions(-) diff --git a/doc/customizing_guide/customization.rst b/doc/customizing_guide/customization.rst index 2012e5c1d..f36840cfa 100644 --- a/doc/customizing_guide/customization.rst +++ b/doc/customizing_guide/customization.rst @@ -321,7 +321,7 @@ that will get called when the preferences dialog is closed. This method should then set any settings appropriately in the application state. The following is an example of a custom preference pane:: - from glue.config import settings, preference_panes + from glue_qt.config import settings, preference_panes from qtpy import QtWidgets diff --git a/glue_qt/app/qt/feedback.py b/glue_qt/app/qt/feedback.py index 5949d070f..93c1a4788 100644 --- a/glue_qt/app/qt/feedback.py +++ b/glue_qt/app/qt/feedback.py @@ -2,12 +2,12 @@ Widgets for sending feedback reports """ import os +import pkg_resources from qtpy import QtGui, QtWidgets from urllib.parse import urlencode from urllib.request import Request, urlopen from glue_qt.utils.qt import load_ui -from glue._deps import get_status_as_odict __all__ = ['submit_bug_report', 'submit_feedback'] @@ -18,8 +18,8 @@ def diagnostics(): Return a some system informaton useful for debugging """ versions = "" - for package, version in get_status_as_odict().items(): - versions += "* {0}: {1}\n".format(package, version) + for pkg in pkg_resources.working_set: + versions += "* {0}: {1}\n".format(pkg.key, pkg.version) return versions.strip() diff --git a/glue_qt/app/qt/preferences.py b/glue_qt/app/qt/preferences.py index 1f173f38a..c38ee98e9 100644 --- a/glue_qt/app/qt/preferences.py +++ b/glue_qt/app/qt/preferences.py @@ -108,7 +108,7 @@ def __init__(self, application, parent=None): self.panes = [] - from glue.config import preference_panes + from glue_qt.config import preference_panes for label, widget_cls in sorted(preference_panes): pane = widget_cls() self.ui.tab_widget.addTab(pane, label) diff --git a/glue_qt/app/qt/tests/test_application.py b/glue_qt/app/qt/tests/test_application.py index b01500296..d02fa6c23 100644 --- a/glue_qt/app/qt/tests/test_application.py +++ b/glue_qt/app/qt/tests/test_application.py @@ -232,7 +232,7 @@ def test_subset_facet(self): act = self.app._layer_widget._actions['facet'] self.app.data_collection.append(Data(x=[1, 2, 3])) - with patch('glue.dialogs.subset_facet.qt.SubsetFacetDialog.exec_'): + with patch('glue_qt.dialogs.subset_facet.qt.SubsetFacetDialog.exec_'): act._do_action() def test_move_viewer_to_tab(self): diff --git a/glue_qt/app/qt/tests/test_preferences.py b/glue_qt/app/qt/tests/test_preferences.py index ebf9b27b8..2a2ae7add 100644 --- a/glue_qt/app/qt/tests/test_preferences.py +++ b/glue_qt/app/qt/tests/test_preferences.py @@ -205,7 +205,7 @@ def finalize(self): preference_panes = [('Custom', CustomPreferences)] - with patch('glue.config.preference_panes', preference_panes): + with patch('glue_qt.config.preference_panes', preference_panes): dialog = PreferencesDialog(self.app) dialog.show() diff --git a/glue_qt/app/qt/versions.py b/glue_qt/app/qt/versions.py index f9c596b2a..d2e0cafda 100644 --- a/glue_qt/app/qt/versions.py +++ b/glue_qt/app/qt/versions.py @@ -1,4 +1,5 @@ import os +import pkg_resources from glue import __version__ @@ -7,7 +8,6 @@ from glue.utils import nonpartial from glue_qt.utils.qt import load_ui, CenteredDialog -from glue._deps import get_status_as_odict __all__ = ['QVersionsDialog'] @@ -31,7 +31,7 @@ def __init__(self, *args, **kwargs): self.ui.button_copy.clicked.connect(nonpartial(self._copy)) def _update_deps(self): - status = get_status_as_odict() + status = {pkg.key: pkg.version for pkg in pkg_resources.working_set} self._text = "" for name, version in [('Glue', __version__)] + list(status.items()): QtWidgets.QTreeWidgetItem(self.ui.version_tree.invisibleRootItem(), diff --git a/glue_qt/conftest.py b/glue_qt/conftest.py index 92d500cf1..015a0da20 100644 --- a/glue_qt/conftest.py +++ b/glue_qt/conftest.py @@ -76,13 +76,6 @@ def pytest_configure(config): load_plugins() -def pytest_report_header(config): - from glue import __version__ - glue_version = "%20s:\t%s" % ("glue", __version__) - from glue._deps import get_status - return os.linesep + glue_version + os.linesep + os.linesep + get_status() - - def pytest_unconfigure(config): os.environ.pop('GLUE_TESTING') diff --git a/glue_qt/dialogs/subset_facet/qt/tests/test_subset_facet.py b/glue_qt/dialogs/subset_facet/qt/tests/test_subset_facet.py index 18fd7b06f..9b8ce243e 100644 --- a/glue_qt/dialogs/subset_facet/qt/tests/test_subset_facet.py +++ b/glue_qt/dialogs/subset_facet/qt/tests/test_subset_facet.py @@ -6,7 +6,7 @@ from ..subset_facet import SubsetFacetDialog -patched_facet = patch('glue.dialogs.subset_facet.qt.subset_facet.facet_subsets') +patched_facet = patch('glue_qt.dialogs.subset_facet.qt.subset_facet.facet_subsets') class TestSubsetFacet(object): diff --git a/glue_qt/main.py b/glue_qt/main.py index 8fcc896c2..e40c5c863 100755 --- a/glue_qt/main.py +++ b/glue_qt/main.py @@ -142,9 +142,9 @@ def start_glue(gluefile=None, config=None, datafiles=None, maximized=True, except ImportError: # Not all PyQt installations have this module pass - from glue.utils.qt.decorators import die_on_error + from glue_qt.utils.qt.decorators import die_on_error - from glue.utils.qt import get_qapp + from glue_qt.utils.qt import get_qapp app = get_qapp() splash = get_splash() @@ -155,7 +155,7 @@ def start_glue(gluefile=None, config=None, datafiles=None, maximized=True, # plugins. load_plugins(splash=splash, require_qt_plugins=True) - from glue.app.qt import GlueApplication + from glue_qt.app.qt import GlueApplication datafiles = datafiles or [] @@ -206,7 +206,7 @@ def execute_script(script): def get_splash(): """Instantiate a splash screen""" - from glue.app.qt.splash_screen import QtSplashScreen + from glue_qt.app.qt.splash_screen import QtSplashScreen splash = QtSplashScreen() return splash @@ -261,12 +261,12 @@ def main(argv=sys.argv): 'glue.io.formats.fits'] -REQUIRED_PLUGINS_QT = ['glue.plugins.tools.pv_slicer.qt', - 'glue.viewers.image.qt', - 'glue.viewers.scatter.qt', - 'glue.viewers.histogram.qt', - 'glue.viewers.profile.qt', - 'glue.viewers.table.qt'] +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): diff --git a/glue_qt/utils/qt/dialogs.py b/glue_qt/utils/qt/dialogs.py index 2d6081c9f..4b40626de 100644 --- a/glue_qt/utils/qt/dialogs.py +++ b/glue_qt/utils/qt/dialogs.py @@ -93,7 +93,10 @@ def center(self): # Adapted from StackOverflow # https://stackoverflow.com/questions/20243637/pyqt4-center-window-on-active-screen frameGm = self.frameGeometry() - screen = QtWidgets.QApplication.desktop().screenNumber(QtWidgets.QApplication.desktop().cursor().pos()) - centerPoint = QtWidgets.QApplication.desktop().screenGeometry(screen).center() + try: + screen = QtWidgets.QApplication.desktop().screenNumber(QtWidgets.QApplication.desktop().cursor().pos()) + centerPoint = QtWidgets.QApplication.desktop().screenGeometry(screen).center() + except AttributeError: + centerPoint = QtWidgets.QApplication.primaryScreen().geometry().center() frameGm.moveCenter(centerPoint) self.move(frameGm.topLeft()) diff --git a/glue_qt/utils/qt/tests/test_dialogs.py b/glue_qt/utils/qt/tests/test_dialogs.py index 439143128..ff94074f7 100644 --- a/glue_qt/utils/qt/tests/test_dialogs.py +++ b/glue_qt/utils/qt/tests/test_dialogs.py @@ -29,11 +29,11 @@ class Bar: Bar.LABEL = 'Baz' - with mock.patch('glue.utils.qt.dialogs.pick_item') as d: + with mock.patch('glue_qt.utils.qt.dialogs.pick_item') as d: pick_class([Foo, Bar], default=Foo) d.assert_called_once_with([Foo, Bar], ['Foo', 'Baz'], default=Foo) - with mock.patch('glue.utils.qt.dialogs.pick_item') as d: + with mock.patch('glue_qt.utils.qt.dialogs.pick_item') as d: pick_class([Foo, Bar], sort=True) d.assert_called_once_with([Bar, Foo], ['Baz', 'Foo'])