Merge pull request #3655 from hugovk/deprecate-eol-qt

Deprecate support for PyQt4 and PySide
This commit is contained in:
Andrew Murray 2019-02-21 19:22:34 +11:00 committed by GitHub
commit 5d9898b686
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 2 deletions

View File

@ -1,7 +1,16 @@
from .helper import PillowTestCase, hopper
from PIL import ImageQt
import warnings
deprecated = False
with warnings.catch_warnings():
warnings.filterwarnings("error", category=DeprecationWarning)
try:
from PIL import ImageQt
except DeprecationWarning:
deprecated = True
warnings.filterwarnings("ignore", category=DeprecationWarning)
from PIL import ImageQt
if ImageQt.qt_is_installed:
from PIL.ImageQt import qRgba
@ -78,3 +87,6 @@ class TestImageQt(PillowQtTestCase, PillowTestCase):
def test_image(self):
for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
ImageQt.ImageQt(hopper(mode))
def test_deprecated(self):
self.assertEqual(ImageQt.qt_version in ["4", "side"], deprecated)

View File

@ -12,6 +12,17 @@ Deprecated features
Below are features which are considered deprecated. Where appropriate,
a ``DeprecationWarning`` is issued.
PyQt4 and PySide
~~~~~~~~~~~~~~~~
.. deprecated:: 6.0.0
Qt 4 reached end-of-life on 2015-12-19. Its Python bindings are also EOL: PyQt4 since
2018-08-31 and PySide since 2015-10-14.
Support for PyQt4 and PySide has been deprecated from ``ImageQt`` and will be removed in
a future version. Please upgrade to PyQt5 or PySide2.
PIL.*ImagePlugin.__version__ attributes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -7,6 +7,12 @@
The :py:mod:`ImageQt` module contains support for creating PyQt4, PyQt5, PySide or
PySide2 QImage objects from PIL images.
Qt 4 reached end-of-life on 2015-12-19. Its Python bindings are also EOL: PyQt4 since
2018-08-31 and PySide since 2015-10-14.
Support for PyQt4 and PySide is deprecated since Pillow 6.0.0 and will be removed in a
future version. Please upgrade to PyQt5 or PySide2.
.. versionadded:: 1.1.6
.. py:class:: ImageQt.ImageQt(image)

View File

@ -32,6 +32,18 @@ API Changes
Deprecations
^^^^^^^^^^^^
PyQt4 and PySide
~~~~~~~~~~~~~~~~
Qt 4 reached end-of-life on 2015-12-19. Its Python bindings are also EOL: PyQt4 since
2018-08-31 and PySide since 2015-10-14.
Support for PyQt4 and PySide has been deprecated from ``ImageQt`` and will be removed in
a future version. Please upgrade to PyQt5 or PySide2.
PIL.*ImagePlugin.__version__ attributes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These version constants have been deprecated and will be removed in a future
version.

View File

@ -20,6 +20,7 @@ from . import Image
from ._util import isPath, py3
from io import BytesIO
import sys
import warnings
qt_versions = [
['5', 'PyQt5'],
@ -27,6 +28,12 @@ qt_versions = [
['4', 'PyQt4'],
['side', 'PySide']
]
WARNING_TEXT = (
"Support for EOL {} is deprecated and will be removed in a future version. "
"Please upgrade to PyQt5 or PySide2."
)
# If a version has already been imported, attempt it first
qt_versions.sort(key=lambda qt_version: qt_version[1] in sys.modules,
reverse=True)
@ -41,9 +48,13 @@ for qt_version, qt_module in qt_versions:
elif qt_module == 'PyQt4':
from PyQt4.QtGui import QImage, qRgba, QPixmap
from PyQt4.QtCore import QBuffer, QIODevice
warnings.warn(WARNING_TEXT.format(qt_module), DeprecationWarning)
elif qt_module == 'PySide':
from PySide.QtGui import QImage, qRgba, QPixmap
from PySide.QtCore import QBuffer, QIODevice
warnings.warn(WARNING_TEXT.format(qt_module), DeprecationWarning)
except (ImportError, RuntimeError):
continue
qt_is_installed = True
@ -67,7 +78,7 @@ def fromqimage(im):
"""
buffer = QBuffer()
buffer.open(QIODevice.ReadWrite)
# preserve alha channel with png
# preserve alpha channel with png
# otherwise ppm is more friendly with Image.open
if im.hasAlphaChannel():
im.save(buffer, 'png')