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 diff --git a/PIL/Image.py b/PIL/Image.py index cafc5a22f..51694ab86 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -26,7 +26,7 @@ from __future__ import print_function -VERSION = "1.1.7" +from PIL import VERSION, PILLOW_VERSION, _plugins try: import warnings @@ -53,7 +53,12 @@ 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 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 +70,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 @@ -328,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/ImageCms.py b/PIL/ImageCms.py index f966bb676..c8745777b 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 PIL 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 288bc2954..ac76e7a83 100644 --- a/PIL/ImageFont.py +++ b/PIL/ImageFont.py @@ -41,7 +41,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..cac68027b 100644 --- a/PIL/ImageGL.py +++ b/PIL/ImageGL.py @@ -17,7 +17,7 @@ # extensions.) ## -import _imaginggl +from PIL import _imaginggl ## # Texture factory. diff --git a/PIL/ImageMath.py b/PIL/ImageMath.py index 6548b0382..395323fd3 100644 --- a/PIL/ImageMath.py +++ b/PIL/ImageMath.py @@ -16,7 +16,7 @@ # from PIL import Image -import _imagingmath +from PIL 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/PIL/WebPImagePlugin.py b/PIL/WebPImagePlugin.py index 260b43e3d..a8be5307c 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 _VALID_WEBP_MODES = { diff --git a/PIL/__init__.py b/PIL/__init__.py index ed54d26f6..7704f2dfa 100644 --- a/PIL/__init__.py +++ b/PIL/__init__.py @@ -10,3 +10,48 @@ # # ;-) + +VERSION = '1.1.7' # PIL version +PILLOW_VERSION = '2.1.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/Tests/test_file_webp.py b/Tests/test_file_webp.py index 30fd94d58..4f8157f69 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/_imaging.c b/_imaging.c index 2ee7eef42..ea31018ec 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.1.0" #include "Python.h" @@ -3430,6 +3431,8 @@ setup_module(PyObject* m) { } #endif + PyDict_SetItemString(d, "PILLOW_VERSION", PyUnicode_FromString(PILLOW_VERSION)); + return 0; } diff --git a/selftest.py b/selftest.py index b0ad4ff67..26fdc2215 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: @@ -182,16 +193,16 @@ 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("WEBP", "_webp") + check_module("FREETYPE2", "PIL._imagingft") + check_module("LITTLECMS", "PIL._imagingcms") + check_module("WEBP", "PIL._webp") try: - import _webp + from PIL import _webp if _webp.WebPDecoderBuggyAlpha(): print("***", "Transparent WEBP", "support not installed") else: diff --git a/setup.py b/setup.py index dbb83fd48..c3de24e6a 100644 --- a/setup.py +++ b/setup.py @@ -317,7 +317,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 @@ -327,23 +327,23 @@ 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( - "_webp", ["_webp.c"], libraries=["webp"])) + "PIL._webp", ["_webp.c"], libraries=["webp"])) if sys.platform == "darwin": # locate Tcl/Tk frameworks @@ -364,16 +364,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 @@ -507,8 +507,11 @@ setup( "Programming Language :: Python :: 3.2", "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", ], - license='Standard PIL License',) + keywords=["Imaging",], + license='Standard PIL License', + zip_safe=True, + ) +