mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 21:50:54 +03:00
Merge pull request #3233 from hugovk/PYTHONOPTIMIZE
Fix code for PYTHONOPTIMIZE
This commit is contained in:
commit
fa14698e66
|
@ -30,8 +30,10 @@ matrix:
|
||||||
- python: '3.5'
|
- python: '3.5'
|
||||||
- python: '3.5'
|
- python: '3.5'
|
||||||
dist: trusty
|
dist: trusty
|
||||||
|
env: PYTHONOPTIMIZE=1
|
||||||
- python: '3.4'
|
- python: '3.4'
|
||||||
dist: trusty
|
dist: trusty
|
||||||
|
env: PYTHONOPTIMIZE=2
|
||||||
- env: DOCKER="alpine" DOCKER_TAG="pytest"
|
- env: DOCKER="alpine" DOCKER_TAG="pytest"
|
||||||
- env: DOCKER="arch" DOCKER_TAG="pytest" # contains PyQt5
|
- env: DOCKER="arch" DOCKER_TAG="pytest" # contains PyQt5
|
||||||
- env: DOCKER="ubuntu-trusty-x86" DOCKER_TAG="pytest"
|
- env: DOCKER="ubuntu-trusty-x86" DOCKER_TAG="pytest"
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
from helper import unittest, PillowTestCase, hopper, on_appveyor
|
from helper import unittest, PillowTestCase, hopper, on_appveyor
|
||||||
|
|
||||||
try:
|
|
||||||
from PIL import PyAccess
|
|
||||||
except ImportError:
|
|
||||||
# Skip in setUp()
|
|
||||||
pass
|
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
# CFFI imports pycparser which doesn't support PYTHONOPTIMIZE=2
|
||||||
|
# https://github.com/eliben/pycparser/pull/198#issuecomment-317001670
|
||||||
|
if os.environ.get("PYTHONOPTIMIZE") == "2":
|
||||||
|
cffi = None
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
from PIL import PyAccess
|
||||||
|
import cffi
|
||||||
|
except ImportError:
|
||||||
|
cffi = None
|
||||||
|
|
||||||
|
|
||||||
class AccessTest(PillowTestCase):
|
class AccessTest(PillowTestCase):
|
||||||
# initial value
|
# initial value
|
||||||
|
@ -113,38 +118,20 @@ class TestImageGetPixel(AccessTest):
|
||||||
self.check(mode, 2**16-1)
|
self.check(mode, 2**16-1)
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(cffi is None, "No cffi")
|
||||||
class TestCffiPutPixel(TestImagePutPixel):
|
class TestCffiPutPixel(TestImagePutPixel):
|
||||||
_need_cffi_access = True
|
_need_cffi_access = True
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
try:
|
|
||||||
import cffi
|
|
||||||
assert cffi # silence warning
|
|
||||||
except ImportError:
|
|
||||||
self.skipTest("No cffi")
|
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(cffi is None, "No cffi")
|
||||||
class TestCffiGetPixel(TestImageGetPixel):
|
class TestCffiGetPixel(TestImageGetPixel):
|
||||||
_need_cffi_access = True
|
_need_cffi_access = True
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
try:
|
|
||||||
import cffi
|
|
||||||
assert cffi # silence warning
|
|
||||||
except ImportError:
|
|
||||||
self.skipTest("No cffi")
|
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(cffi is None, "No cffi")
|
||||||
class TestCffi(AccessTest):
|
class TestCffi(AccessTest):
|
||||||
_need_cffi_access = True
|
_need_cffi_access = True
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
try:
|
|
||||||
import cffi
|
|
||||||
assert cffi # silence warning
|
|
||||||
except ImportError:
|
|
||||||
self.skipTest("No cffi")
|
|
||||||
|
|
||||||
def _test_get_access(self, im):
|
def _test_get_access(self, im):
|
||||||
"""Do we get the same thing as the old pixel access
|
"""Do we get the same thing as the old pixel access
|
||||||
|
|
||||||
|
|
|
@ -215,7 +215,7 @@ class TestImageFont(PillowTestCase):
|
||||||
|
|
||||||
# Act/Assert
|
# Act/Assert
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
AssertionError,
|
ValueError,
|
||||||
draw.multiline_text, (0, 0), TEST_TEXT, font=ttf, align="unknown")
|
draw.multiline_text, (0, 0), TEST_TEXT, font=ttf, align="unknown")
|
||||||
|
|
||||||
def test_draw_align(self):
|
def test_draw_align(self):
|
||||||
|
|
|
@ -246,7 +246,7 @@ class ImageDraw(object):
|
||||||
elif align == "right":
|
elif align == "right":
|
||||||
left += (max_width - widths[idx])
|
left += (max_width - widths[idx])
|
||||||
else:
|
else:
|
||||||
assert False, 'align must be "left", "center" or "right"'
|
raise ValueError('align must be "left", "center" or "right"')
|
||||||
self.text((left, top), line, fill, font, anchor,
|
self.text((left, top), line, fill, font, anchor,
|
||||||
direction=direction, features=features)
|
direction=direction, features=features)
|
||||||
top += line_spacing
|
top += line_spacing
|
||||||
|
|
|
@ -32,13 +32,6 @@ if sys.version_info.major > 2:
|
||||||
else:
|
else:
|
||||||
import Tkinter as tkinter
|
import Tkinter as tkinter
|
||||||
|
|
||||||
# required for pypy, which always has cffi installed
|
|
||||||
try:
|
|
||||||
from cffi import FFI
|
|
||||||
ffi = FFI()
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
@ -192,7 +185,11 @@ class PhotoImage(object):
|
||||||
from . import _imagingtk
|
from . import _imagingtk
|
||||||
try:
|
try:
|
||||||
if hasattr(tk, 'interp'):
|
if hasattr(tk, 'interp'):
|
||||||
# Pypy is using a ffi cdata element
|
# Required for PyPy, which always has CFFI installed
|
||||||
|
from cffi import FFI
|
||||||
|
ffi = FFI()
|
||||||
|
|
||||||
|
# PyPy is using an FFI CDATA element
|
||||||
# (Pdb) self.tk.interp
|
# (Pdb) self.tk.interp
|
||||||
# <cdata 'Tcl_Interp *' 0x3061b50>
|
# <cdata 'Tcl_Interp *' 0x3061b50>
|
||||||
_imagingtk.tkinit(
|
_imagingtk.tkinit(
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"""Pillow {} (Fork of the Python Imaging Library)
|
"""Pillow (Fork of the Python Imaging Library)
|
||||||
|
|
||||||
Pillow is the friendly PIL fork by Alex Clark and Contributors.
|
Pillow is the friendly PIL fork by Alex Clark and Contributors.
|
||||||
https://github.com/python-pillow/Pillow/
|
https://github.com/python-pillow/Pillow/
|
||||||
|
@ -24,8 +24,6 @@ PILLOW_VERSION = __version__ = _version.__version__
|
||||||
|
|
||||||
del _version
|
del _version
|
||||||
|
|
||||||
__doc__ = __doc__.format(__version__) # include version in docstring
|
|
||||||
|
|
||||||
|
|
||||||
_plugins = ['BlpImagePlugin',
|
_plugins = ['BlpImagePlugin',
|
||||||
'BmpImagePlugin',
|
'BmpImagePlugin',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user