From c774f9ab4c02b8dda68a0abb755bb541333fc801 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 8 Apr 2013 20:31:28 -0700 Subject: [PATCH 1/9] merged pull request #88 to master, resolved conflicts --- PIL/Image.py | 2 +- PIL/ImageCms.py | 2 +- PIL/ImageDraw.py | 2 +- PIL/ImageFont.py | 2 +- PIL/ImageGL.py | 4 ++-- PIL/ImageMath.py | 2 +- PIL/ImageTk.py | 6 ++++-- selftest.py | 8 ++++---- setup.py | 16 ++++++++-------- 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index 1e29db198..cb4fc3336 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -53,7 +53,7 @@ try: # the "open" function to identify files, but you cannot load # them. Note that other modules should not refer to _imaging # directly; import Image and use the Image.core variable instead. - import _imaging as core + from . import _imaging as core except ImportError as v: core = _imaging_not_installed() if str(v)[:20] == "Module use of python" and warnings: diff --git a/PIL/ImageCms.py b/PIL/ImageCms.py index c41139b2b..3931f366c 100644 --- a/PIL/ImageCms.py +++ b/PIL/ImageCms.py @@ -82,7 +82,7 @@ VERSION = "0.1.0 pil" # --------------------------------------------------------------------. from PIL import Image -import _imagingcms +from . import _imagingcms core = _imagingcms diff --git a/PIL/ImageDraw.py b/PIL/ImageDraw.py index d8578e4c3..e786ef5a7 100644 --- a/PIL/ImageDraw.py +++ b/PIL/ImageDraw.py @@ -315,7 +315,7 @@ def getdraw(im=None, hints=None): handler = None if not hints or "nicest" in hints: try: - import _imagingagg as handler + from PIL import _imagingagg as handler except ImportError: pass if handler is None: diff --git a/PIL/ImageFont.py b/PIL/ImageFont.py index 8ec60fef9..b5845887f 100644 --- a/PIL/ImageFont.py +++ b/PIL/ImageFont.py @@ -36,7 +36,7 @@ class _imagingft_not_installed: raise ImportError("The _imagingft C module is not installed") try: - import _imagingft as core + from PIL import _imagingft as core except ImportError: core = _imagingft_not_installed() diff --git a/PIL/ImageGL.py b/PIL/ImageGL.py index 5c58b6ca9..147ddc3f0 100644 --- a/PIL/ImageGL.py +++ b/PIL/ImageGL.py @@ -17,7 +17,7 @@ # extensions.) ## -import _imaginggl +from . import _imaginggl ## # Texture factory. @@ -25,4 +25,4 @@ import _imaginggl class TextureFactory: pass # overwritten by the _imaginggl module -from _imaginggl import * +from ._imaginggl import * diff --git a/PIL/ImageMath.py b/PIL/ImageMath.py index 6548b0382..4f3c19273 100644 --- a/PIL/ImageMath.py +++ b/PIL/ImageMath.py @@ -16,7 +16,7 @@ # from PIL import Image -import _imagingmath +from . import _imagingmath import sys try: diff --git a/PIL/ImageTk.py b/PIL/ImageTk.py index c1ea95bc2..1b75422fc 100644 --- a/PIL/ImageTk.py +++ b/PIL/ImageTk.py @@ -28,7 +28,9 @@ try: import tkinter except ImportError: - import Tkinter as tkinter + import Tkinter + tkinter = Tkinter + del Tkinter from PIL import Image @@ -183,7 +185,7 @@ class PhotoImage: except tkinter.TclError as v: # activate Tkinter hook try: - import _imagingtk + from PIL import _imagingtk try: _imagingtk.tkinit(tk.interpaddr(), 1) except AttributeError: diff --git a/selftest.py b/selftest.py index 91a14bb54..91133eeb8 100644 --- a/selftest.py +++ b/selftest.py @@ -182,13 +182,13 @@ if __name__ == "__main__": print("Python modules loaded from", os.path.dirname(Image.__file__)) print("Binary modules loaded from", os.path.dirname(Image.core.__file__)) print("-"*68) - check_module("PIL CORE", "_imaging") - check_module("TKINTER", "_imagingtk") + check_module("PIL CORE", "PIL._imaging") + check_module("TKINTER", "PIL._imagingtk") check_codec("JPEG", "jpeg") check_codec("ZLIB (PNG/ZIP)", "zip") check_codec("G4 TIFF", "group4") - check_module("FREETYPE2", "_imagingft") - check_module("LITTLECMS", "_imagingcms") + check_module("FREETYPE2", "PIL._imagingft") + check_module("LITTLECMS", "PIL._imagingcms") check_module("WEBP", "_webp") print("-"*68) diff --git a/setup.py b/setup.py index 65b8b1e42..235447335 100644 --- a/setup.py +++ b/setup.py @@ -304,7 +304,7 @@ class pil_build_ext(build_ext): defs.append(("WORDS_BIGENDIAN", None)) exts = [(Extension( - "_imaging", files, libraries=libs, define_macros=defs))] + "PIL._imaging", files, libraries=libs, define_macros=defs))] # # additional libraries @@ -314,19 +314,19 @@ class pil_build_ext(build_ext): if feature.freetype_version == 20: defs.append(("USE_FREETYPE_2_0", None)) exts.append(Extension( - "_imagingft", ["_imagingft.c"], libraries=["freetype"], + "PIL._imagingft", ["_imagingft.c"], libraries=["freetype"], define_macros=defs)) if os.path.isfile("_imagingtiff.c") and feature.tiff: exts.append(Extension( - "_imagingtiff", ["_imagingtiff.c"], libraries=["tiff"])) + "PIL._imagingtiff", ["_imagingtiff.c"], libraries=["tiff"])) if os.path.isfile("_imagingcms.c") and feature.lcms: extra = [] if sys.platform == "win32": extra.extend(["user32", "gdi32"]) exts.append(Extension( - "_imagingcms", ["_imagingcms.c"], libraries=["lcms"] + extra)) + "PIL._imagingcms", ["_imagingcms.c"], libraries=["lcms"] + extra)) if os.path.isfile("_webp.c") and feature.webp: exts.append(Extension( @@ -351,16 +351,16 @@ class pil_build_ext(build_ext): break if frameworks: exts.append(Extension( - "_imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"], + "PIL._imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"], extra_compile_args=frameworks, extra_link_args=frameworks)) feature.tcl = feature.tk = 1 # mark as present elif feature.tcl and feature.tk: exts.append(Extension( - "_imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"], + "PIL._imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"], libraries=[feature.tcl, feature.tk])) if os.path.isfile("_imagingmath.c"): - exts.append(Extension("_imagingmath", ["_imagingmath.c"])) + exts.append(Extension("PIL._imagingmath", ["_imagingmath.c"])) self.extensions[:] = exts @@ -494,7 +494,7 @@ setup( "Programming Language :: Python :: 3.3", ], cmdclass={"build_ext": pil_build_ext}, - ext_modules=[Extension("_imaging", ["_imaging.c"])], + ext_modules=[Extension("PIL._imaging", ["_imaging.c"])], packages=find_packages(), scripts=glob.glob("Scripts/pil*.py"), keywords=["Imaging",], From 7f698a6fc5f85d4e857a5e8f92a4e1c786d8d3ed Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 8 Apr 2013 20:55:06 -0700 Subject: [PATCH 2/9] PIL imports work in python3/Ubuntu --- PIL/Image.py | 2 +- PIL/ImageCms.py | 2 +- PIL/ImageGL.py | 4 ++-- PIL/ImageMath.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index cb4fc3336..a8a34d59b 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -53,7 +53,7 @@ try: # the "open" function to identify files, but you cannot load # them. Note that other modules should not refer to _imaging # directly; import Image and use the Image.core variable instead. - from . import _imaging as core + from PIL import _imaging as core except ImportError as v: core = _imaging_not_installed() if str(v)[:20] == "Module use of python" and warnings: diff --git a/PIL/ImageCms.py b/PIL/ImageCms.py index 3931f366c..9a607b699 100644 --- a/PIL/ImageCms.py +++ b/PIL/ImageCms.py @@ -82,7 +82,7 @@ VERSION = "0.1.0 pil" # --------------------------------------------------------------------. from PIL import Image -from . import _imagingcms +from PIL import _imagingcms core = _imagingcms diff --git a/PIL/ImageGL.py b/PIL/ImageGL.py index 147ddc3f0..cac68027b 100644 --- a/PIL/ImageGL.py +++ b/PIL/ImageGL.py @@ -17,7 +17,7 @@ # extensions.) ## -from . import _imaginggl +from PIL import _imaginggl ## # Texture factory. @@ -25,4 +25,4 @@ from . import _imaginggl class TextureFactory: pass # overwritten by the _imaginggl module -from ._imaginggl import * +from _imaginggl import * diff --git a/PIL/ImageMath.py b/PIL/ImageMath.py index 4f3c19273..395323fd3 100644 --- a/PIL/ImageMath.py +++ b/PIL/ImageMath.py @@ -16,7 +16,7 @@ # from PIL import Image -from . import _imagingmath +from PIL import _imagingmath import sys try: From 088c752e4049767b3575fb8bb3c24b1190c5ad62 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 8 Apr 2013 21:43:15 -0700 Subject: [PATCH 3/9] basic sanity check that the version of the _imaging.c and Image.py files are the same --- PIL/Image.py | 8 ++++++++ _imaging.c | 3 +++ 2 files changed, 11 insertions(+) diff --git a/PIL/Image.py b/PIL/Image.py index a8a34d59b..9a1fda875 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -27,6 +27,7 @@ from __future__ import print_function VERSION = "1.1.7" +PILLOW_VERSION = "2.0.0" try: import warnings @@ -54,6 +55,11 @@ try: # them. Note that other modules should not refer to _imaging # directly; import Image and use the Image.core variable instead. from PIL import _imaging as core + if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None): + raise ImportError("The _imaging extension was built for another " + " version of Pillow or PIL. Most PIL functions " + " will be disabled ") + except ImportError as v: core = _imaging_not_installed() if str(v)[:20] == "Module use of python" and warnings: @@ -65,6 +71,8 @@ except ImportError as v: "of Python; most PIL functions will be disabled", RuntimeWarning ) + if str(v).startswith("The _imaging extension") and warnings: + warnings.warn(str(v), RuntimeWarning) try: import builtins diff --git a/_imaging.c b/_imaging.c index c9d3c8247..b58a18d11 100644 --- a/_imaging.c +++ b/_imaging.c @@ -71,6 +71,7 @@ * See the README file for information on usage and redistribution. */ +#define PILLOW_VERSION "2.0.0" #include "Python.h" @@ -3431,6 +3432,8 @@ setup_module(PyObject* m) { } #endif + PyDict_SetItemString(d, "PILLOW_VERSION", PyUnicode_FromString(PILLOW_VERSION)); + return 0; } From 8295e33390413e50116923dc02da7865c1cadda4 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 8 Apr 2013 21:53:59 -0700 Subject: [PATCH 4/9] moved _webp into the PIL namespace --- PIL/WebPImagePlugin.py | 2 +- Tests/test_file_webp.py | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PIL/WebPImagePlugin.py b/PIL/WebPImagePlugin.py index 9321c05f3..bc2a31315 100644 --- a/PIL/WebPImagePlugin.py +++ b/PIL/WebPImagePlugin.py @@ -1,7 +1,7 @@ from PIL import Image from PIL import ImageFile from io import BytesIO -import _webp +from PIL import _webp def _accept(prefix): return prefix[:4] == b"RIFF" and prefix[8:16] == b"WEBPVP8 " diff --git a/Tests/test_file_webp.py b/Tests/test_file_webp.py index 5d48f0aff..1d5337af1 100644 --- a/Tests/test_file_webp.py +++ b/Tests/test_file_webp.py @@ -3,7 +3,7 @@ from tester import * from PIL import Image try: - import _webp + from PIL import _webp except: skip('webp support not installed') diff --git a/setup.py b/setup.py index 235447335..429cec61d 100644 --- a/setup.py +++ b/setup.py @@ -330,7 +330,7 @@ class pil_build_ext(build_ext): if os.path.isfile("_webp.c") and feature.webp: exts.append(Extension( - "_webp", ["_webp.c"], libraries=["webp"])) + "PIL._webp", ["_webp.c"], libraries=["webp"])) if sys.platform == "darwin": From 517e0210ab915374da6744f1d6d4a1e41169ea85 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 8 Apr 2013 22:41:31 -0700 Subject: [PATCH 5/9] webp to PIL in selftest --- selftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selftest.py b/selftest.py index 91133eeb8..37db42263 100644 --- a/selftest.py +++ b/selftest.py @@ -189,7 +189,7 @@ if __name__ == "__main__": check_codec("G4 TIFF", "group4") check_module("FREETYPE2", "PIL._imagingft") check_module("LITTLECMS", "PIL._imagingcms") - check_module("WEBP", "_webp") + check_module("WEBP", "PIL._webp") print("-"*68) # use doctest to make sure the test program behaves as documented! From 7f178bc0b680f59fe03b1372c805c20f42c78b21 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 8 Apr 2013 22:42:49 -0700 Subject: [PATCH 6/9] selftests pass with namespaces on py2.7/3.2 --- selftest.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/selftest.py b/selftest.py index 37db42263..3c1846d59 100644 --- a/selftest.py +++ b/selftest.py @@ -3,13 +3,24 @@ from __future__ import print_function ROOT = "." import os, sys -sys.path.insert(0, ROOT) + +# Path silliness. This selftest needs to be able to import itself, so +#it needs . in the path. However, since the compiled versions of the +#PIL bits are not in PIL, they're in dist, or build, or actually +#installed. In fact, importing from ./PIL is going to fail on any +#.c/so item. So. We remove it from the path, import all the PIL stuff +#from elsewhere, then pop the current directory back on the path so +#that we can import this and run the doctest + +del(sys.path[0]) from PIL import Image from PIL import ImageDraw from PIL import ImageFilter from PIL import ImageMath +sys.path.insert(0,ROOT) + try: Image.core.ping except ImportError as v: From 026f6bb61eca4a2fdf3c92097ee3394953214be3 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 15 Apr 2013 10:57:37 -0700 Subject: [PATCH 7/9] namespaced operation works when installed as a zipped egg using 'sudo python[3] setup.py easy_install -l --zip-ok .' --- PIL/Image.py | 40 ++++++++++------------------------------ PIL/__init__.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ setup.py | 1 + 3 files changed, 56 insertions(+), 30 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index a24750648..51694ab86 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -26,8 +26,7 @@ from __future__ import print_function -VERSION = "1.1.7" -PILLOW_VERSION = "2.0.0" +from PIL import VERSION, PILLOW_VERSION, _plugins try: import warnings @@ -336,34 +335,15 @@ def init(): if _initialized >= 2: return 0 - visited = {} - - directories = sys.path - - try: - directories = directories + [os.path.dirname(__file__)] - except NameError: - pass - - # only check directories (including current, if present in the path) - for directory in filter(isDirectory, directories): - fullpath = os.path.abspath(directory) - if fullpath in visited: - continue - for file in os.listdir(directory): - if file[-14:] == "ImagePlugin.py": - f, e = os.path.splitext(file) - try: - sys.path.insert(0, directory) - try: - __import__(f, globals(), locals(), []) - finally: - del sys.path[0] - except ImportError: - if DEBUG: - print("Image: failed to import", end=' ') - print(f, ":", sys.exc_info()[1]) - visited[fullpath] = None + for plugin in _plugins: + try: + if DEBUG: + print ("Importing %s"%plugin) + __import__("PIL.%s"%plugin, globals(), locals(), []) + except ImportError: + if DEBUG: + print("Image: failed to import", end=' ') + print(plugin, ":", sys.exc_info()[1]) if OPEN or SAVE: _initialized = 2 diff --git a/PIL/__init__.py b/PIL/__init__.py index ed54d26f6..a50fae3ce 100644 --- a/PIL/__init__.py +++ b/PIL/__init__.py @@ -10,3 +10,48 @@ # # ;-) + +VERSION = '1.1.7' # PIL version +PILLOW_VERSION = '2.0.0' # Pillow + +_plugins = ['ArgImagePlugin', + 'BmpImagePlugin', + 'BufrStubImagePlugin', + 'CurImagePlugin', + 'DcxImagePlugin', + 'EpsImagePlugin', + 'FitsStubImagePlugin', + 'FliImagePlugin', + 'FpxImagePlugin', + 'GbrImagePlugin', + 'GifImagePlugin', + 'GribStubImagePlugin', + 'Hdf5StubImagePlugin', + 'IcnsImagePlugin', + 'IcoImagePlugin', + 'ImImagePlugin', + 'ImtImagePlugin', + 'IptcImagePlugin', + 'JpegImagePlugin', + 'McIdasImagePlugin', + 'MicImagePlugin', + 'MpegImagePlugin', + 'MspImagePlugin', + 'PalmImagePlugin', + 'PcdImagePlugin', + 'PcxImagePlugin', + 'PdfImagePlugin', + 'PixarImagePlugin', + 'PngImagePlugin', + 'PpmImagePlugin', + 'PsdImagePlugin', + 'SgiImagePlugin', + 'SpiderImagePlugin', + 'SunImagePlugin', + 'TgaImagePlugin', + 'TiffImagePlugin', + 'WebPImagePlugin', + 'WmfImagePlugin', + 'XbmImagePlugin', + 'XpmImagePlugin', + 'XVThumbImagePlugin'] diff --git a/setup.py b/setup.py index 429cec61d..847d4b9ce 100644 --- a/setup.py +++ b/setup.py @@ -499,4 +499,5 @@ setup( scripts=glob.glob("Scripts/pil*.py"), keywords=["Imaging",], license='Standard PIL License', + zip_safe=True, ) From 3eb0bdb4651251b37691af9ed97ea9973b0ad192 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Fri, 19 Apr 2013 17:18:10 -0700 Subject: [PATCH 8/9] check to see that we're not cross loading the PIL libraries --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f3f98e5d1..3b8f23421 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ python: - 3.2 - 3.3 -install: "sudo apt-get -qq install libfreetype6-dev liblcms1-dev libwebp-dev" +install: "sudo apt-get -qq install libfreetype6-dev liblcms1-dev libwebp-dev python-imaging" script: - python setup.py clean From baba2810ae952551684f6e08d1965d2d66749af8 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Tue, 21 May 2013 21:46:36 -0700 Subject: [PATCH 9/9] version updates --- PIL/__init__.py | 2 +- _imaging.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PIL/__init__.py b/PIL/__init__.py index a50fae3ce..7704f2dfa 100644 --- a/PIL/__init__.py +++ b/PIL/__init__.py @@ -12,7 +12,7 @@ # ;-) VERSION = '1.1.7' # PIL version -PILLOW_VERSION = '2.0.0' # Pillow +PILLOW_VERSION = '2.1.0' # Pillow _plugins = ['ArgImagePlugin', 'BmpImagePlugin', diff --git a/_imaging.c b/_imaging.c index 4732b6079..ea31018ec 100644 --- a/_imaging.c +++ b/_imaging.c @@ -71,7 +71,7 @@ * See the README file for information on usage and redistribution. */ -#define PILLOW_VERSION "2.0.0" +#define PILLOW_VERSION "2.1.0" #include "Python.h"