Skip to content

Commit

Permalink
Merge pull request #1662 from astrofrog/pyside2
Browse files Browse the repository at this point in the history
Fix compatibility with PySide2 and drop support for PySide and PyQt4
  • Loading branch information
astrofrog authored Apr 18, 2018
2 parents caa8d60 + 80b3c4a commit 79da3d1
Show file tree
Hide file tree
Showing 73 changed files with 651 additions and 493 deletions.
48 changes: 30 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env:
- QT_PKG=pyqt5
- SETUP_XVFB=True
- CONDA_DEPENDENCIES="pip dill ipython matplotlib scipy cython h5py pygments pyzmq scikit-image pandas sphinx xlrd pillow pytest mock coverage pyyaml sphinx_rtd_theme qtpy traitlets ipykernel qtconsole spectral-cube pytest-cov mpl-scatter-density bottleneck"
- PIP_DEPENDENCIES="coveralls pyavm astrodendro plotly objgraph pytest-qt"
- PIP_DEPENDENCIES="coveralls pyavm astrodendro plotly objgraph pytest-qt pytest-faulthandler"
- PIP_FALLBACK=false
- REMOVE_INSTALL_REQUIRES=0
- secure: NvQVc3XmmjXNVKrmaD31IgltsOImlnt3frAl4wU0pM223iejr7V57hz/V5Isx6sTANWEiRBMG27v2T8e5IiB7DQTxFUleZk3DWXQV1grw/GarEGUawXAgwDWpF0AE/7BRVJYqo2Elgaqf28+Jkun8ewvfPCiEROD2jWEpnZj+IQ=
Expand Down Expand Up @@ -90,19 +90,25 @@ matrix:
- os: linux
stage: Full
env: PYTHON_VERSION=2.7
MATPLOTLIB_VERSION=1.5
NUMPY_VERSION=1.11
MATPLOTLIB_VERSION=2.0
PANDAS_VERSION=0.18
SETUPTOOLS=1.0
IPYTHON_VERSION=4
QT_PKG=pyqt
NUMPY_VERSION=1.11

# Test with PySide2

- os: osx
stage: Full
env: PYTHON_VERSION=3.6
CONDA_CHANNELS="astropy-ci-extras astropy glueviz conda-forge"
QT_PKG=pyside2

# Test with PySide, but due to segmentation faults, mark as an
# allowed failure.
- os: linux
stage: Full
env: PYTHON_VERSION=2.7
QT_PKG=pyside
env: PYTHON_VERSION=3.6
CONDA_CHANNELS="astropy-ci-extras astropy glueviz conda-forge"
QT_PKG=pyside2

# Test without any Qt installation, which will also cause all qt
# sub-directories to be removed, to make sure that no non-Qt code has
Expand All @@ -115,19 +121,24 @@ matrix:

allow_failures:

- os: linux
env: PYTHON_VERSION=2.7 NUMPY_VERSION=dev
# For now PySide2 can give segfaults when the process terminates - see
# https://bugreports.qt.io/browse/PYSIDE-585
# We therefore need to mark these as allowed failures for now

- os: osx
env: PYTHON_VERSION=3.6
CONDA_CHANNELS="astropy-ci-extras astropy glueviz conda-forge"
QT_PKG=pyside2

- os: linux
env: PYTHON_VERSION=2.7 QT_PKG=pyside
env: PYTHON_VERSION=3.6
CONDA_CHANNELS="astropy-ci-extras astropy glueviz conda-forge"
QT_PKG=pyside2

before_install:

# Prepare dependency list. Note that in future, PyQt5 will be the pyqt conda
# package with a version of 5.x rather than a pyqt5 package, so we explicitly
# request pyqt=4 for PyQt4.
- if [[ $QT_PKG == pyside ]]; then export CONDA_DEPENDENCIES="pyside "$CONDA_DEPENDENCIES; fi
- if [[ $QT_PKG == pyqt ]]; then export CONDA_DEPENDENCIES="pyqt=4 "$CONDA_DEPENDENCIES; fi
# Prepare dependency list.
- if [[ $QT_PKG == pyside2 ]]; then export CONDA_DEPENDENCIES="pyside2 "$CONDA_DEPENDENCIES; fi
- if [[ $QT_PKG == pyqt5 ]]; then export CONDA_DEPENDENCIES="pyqt=5 "$CONDA_DEPENDENCIES; fi

# Documentation dependencies
Expand All @@ -151,7 +162,7 @@ install:
- LC_ALL=C

# Uninstall PyQt if we are using PySide
- if [ $QT_PKG == pyside ]; then conda remove --no-pin --force pyqt sip || true; fi
- if [ $QT_PKG == pyside2 ]; then conda remove --no-pin --force pyqt sip || true; fi

# Uninstall any version of Qt if QT_PKG is False, and remove all qt
# sub-directories
Expand All @@ -161,6 +172,7 @@ install:
conda remove --no-pin --force qtpy || true;
conda remove --no-pin --force pyqt || true;
conda remove --no-pin --force pyside || true;
conda remove --no-pin --force pyside2 || true;
conda remove --no-pin --force qt || true;
pip uninstall --yes qtpy || true;
find . -name "qt" -type d -exec rm -r {} \; || true;
Expand Down Expand Up @@ -189,7 +201,7 @@ install:

# We need to install glue in order to make sure that the entry points are
# installed.
- pip install . --no-deps
- pip install . --no-deps --verbose

# Check that all the plugins load correctly
- python -c 'from glue.logger import logger; logger.setLevel("DEBUG"); from glue.main import load_plugins; load_plugins()'
Expand Down
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ v0.13.0 (unreleased)
subsets to define the areas in which to compute profiles rather
than custom ROIs. [#1635]

* Added support for PySide2 and remove support for PyQt4 and
PySide. [#1662]

* Remove support for Matplotlib 1.5. [#1662]

* Renamed ``qt4_to_mpl_color`` to ``qt_to_mpl_color`` and
``mpl_to_qt4_color`` to ``mpl_to_qt_color``. [#1662]

* Improve performance when changing visual attributes of subsets.
[#1617]

Expand Down
14 changes: 0 additions & 14 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,6 @@
('py:class', 'list'), ('py:obj', 'numpy array'),
('py:obj', 'integer'), ('py:obj', 'Callable'),
('py:obj', 'list'),
('py:class', 'PySide.QtGui.QMainWindow'),
('py:class', 'PySide.QtGui.QWidget'),
('py:class', 'PyQt4.QtGui.QTextEdit'),
('py:class', 'PyQt4.QtGui.QTabBar'),
('py:class', 'PyQt4.QtGui.QLabel'),
('py:class', 'PyQt4.QtGui.QComboBox'),
('py:class', 'PyQt4.QtGui.QMessageBox'),
('py:class', 'PyQt4.QtGui.QToolBar'),
('py:class', 'PyQt4.QtCore.QMimeData'),
('py:class', 'PyQt4.QtCore.QAbstractListModel'),
('py:class', 'PyQt4.QtCore.QThread'),
('py:class', 'PyQt4.QtGui.QStyledItemDelegate'),
('py:class', 'PyQt5.QtWidgets.QMainWindow'),
('py:class', 'PyQt5.QtWidgets.QWidget'),
('py:class', 'PyQt5.QtWidgets.QTextEdit'),
Expand All @@ -335,8 +323,6 @@
('py:class', 'glue.viewers.scatter.layer_artist.ScatterLayerBase'),
('py:class', 'glue.viewers.image.layer_artist.ImageLayerBase'),
('py:class', 'glue.viewers.image.layer_artist.RGBImageLayerBase'),
('py:class', 'PyQt4.QtGui.QMainWindow'),
('py:class', 'PyQt4.QtGui.QWidget'),
('py:mod', 'glue.core'),
('py:mod', 'glue.viewers'),
('py:mod', 'glue.viewers.scatter'),
Expand Down
9 changes: 3 additions & 6 deletions doc/developer_guide/qt_development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ Using QtPy
----------

If you are interested in working on some of the Qt-specific code, it's
important that you don't import any code directly from PyQt4, PyQt5, or PySide.
important that you don't import any code directly from PyQt or PySide.
Since we want to maintain backward-compatibility with all of these, you should
always use the `QtPy <https://pypi.python.org/pypi/QtPy>`__ package. The way to
use this package is to import from the ``qtpy`` module as if it was the
``PyQt5`` module, and QtPy will automatically translate this into the
appropriate imports for PySide or PyQt4 if needed. For instance, instead of::
appropriate imports for PyQt or PySide if needed. For instance, instead of::

from PyQt4 import QtCore
from PyQt5 import QtCore

you should do::

from qtpy import QtCore

Note that if the PyQt4 and PyQt5 import paths would be different, you should
use the PyQt5 one.
4 changes: 2 additions & 2 deletions doc/developer_guide/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ we merge changes into the code base, all the tests are run on `Travis
<https://travis-ci.org>`_ and `AppVeyor <https://www.appveyor.com/>`_. This is
referred to as *Continuous Integration*. One of the nice things about continuous integration is that it allows us to
automatically run the tests for different operating systems, Python versions,
versions of Numpy, and Qt frameworks (PyQt4, PyQt5, and PySide).
versions of Numpy, and Qt frameworks (PyQt5, and PySide2).

`Travis <https://travis-ci.org>`_ runs tests on Linux and MacOS X, and `AppVeyor
<https://www.appveyor.com/>`_ runs the tests on Windows. When you open a pull
Expand All @@ -60,4 +60,4 @@ will look something like this:
.. image:: ci_status.png

In this example, the tests failed on Travis, but passed on Windows. You can
then get more information about which set-ups failed by clicking on 'Details'.
then get more information about which set-ups failed by clicking on 'Details'.
4 changes: 2 additions & 2 deletions doc/installation/dependencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Glue has the following required dependencies:
* `Pandas <http://pandas.pydata.org/>`_ 0.14 or later
* `Astropy <http://www.astropy.org>`_ 1.0 or higher
* `setuptools <http://setuptools.readthedocs.io/en/latest/>`_ 1.0 or later
* Either `PySide <https://wiki.qt.io/PySide>`__ or `PyQt
<https://riverbankcomputing.com/software/pyqt/intro>`__ (both PyQt4 and PyQt5 are supported)
* Either `PyQt5 <https://www.riverbankcomputing.com/software/pyqt/intro>`__ or
`PySide2 <https://wiki.qt.io/PySide2>`__
* `QtPy <https://pypi.python.org/pypi/QtPy/>`__ 1.2 or higher - this is an
abstraction layer for the Python Qt packages
* `IPython <http://ipython.org>`_ 4.0 or higher
Expand Down
6 changes: 3 additions & 3 deletions doc/installation/qt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Installing PyQt or PySide
If you are using Linux, PyQt and PySide will typically be available in the
built-in package manager. For example, if you are using Ubuntu, then you can do::

sudo apt-get install python-qt4
sudo apt-get install python-qt5

for Python 2, and::

sudo apt-get install python3-pyqt4
sudo apt-get install python3-pyqt5

for Python 3. If you are using MacOS X, then if you are using MacPorts to
manage your Python installation, you can do::

sudo port install py35-pyqt4
sudo port install py35-pyqt5

assuming you are using Python 3.5 (modify the ``py35`` version as needed).
24 changes: 6 additions & 18 deletions glue/_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,6 @@ def __str__(self):
return "%20s:\t%s" % (self.module, status)


class PyQt4(QtDependency):

@property
def version(self):
try:
from PyQt4 import Qt
return "PyQt: {0} - Qt: {1}".format(Qt.PYQT_VERSION_STR, Qt.QT_VERSION_STR)
except (ImportError, AttributeError):
return 'unknown version'


class PyQt5(QtDependency):

@property
Expand All @@ -129,14 +118,14 @@ def version(self):
return 'unknown version'


class PySide(QtDependency):
class PySide2(QtDependency):

@property
def version(self):
try:
import PySide
from PySide import QtCore
return "PySide: {0} - Qt: {1}".format(PySide.__version__, QtCore.__version__)
import PySide2
from PySide2 import QtCore
return "PySide2: {0} - Qt: {1}".format(PySide2.__version__, QtCore.__version__)
except (ImportError, AttributeError):
return 'unknown version'

Expand All @@ -149,16 +138,15 @@ def version(self):
)

gui_framework = (
PyQt4('PyQt4', ''),
PyQt5('PyQt5', ''),
PySide('PySide', '')
PySide2('PySide2', '')
)

required = (
Dependency('qtpy', 'Required', min_version='1.2'),
Dependency('setuptools', 'Required', min_version='1.0'),
Dependency('numpy', 'Required', min_version='1.9'),
Dependency('matplotlib', 'Required for plotting', min_version='1.4'),
Dependency('matplotlib', 'Required for plotting', min_version='2.0'),
Dependency('pandas', 'Adds support for Excel files and DataFrames', min_version='0.14'),
Dependency('astropy', 'Used for FITS I/O, table reading, and WCS Parsing', min_version='1.3'),
Dependency('dill', 'Used when saving Glue sessions', min_version='0.2'),
Expand Down
5 changes: 1 addition & 4 deletions glue/_mpl_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ def set_mpl_backend():
# standardize mpl setup
rcdefaults()

if PYQT5:
rcParams['backend'] = 'Qt5Agg'
else:
rcParams['backend'] = 'Qt4Agg'
rcParams['backend'] = 'Qt5Agg'

# disable key bindings in matplotlib
for setting in list(rcParams.keys()):
Expand Down
Loading

0 comments on commit 79da3d1

Please sign in to comment.