mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 07:57:27 +03:00 
			
		
		
		
	Merge pull request #191 from wiredfool/namespaced
Changes to put everything under the PIL namespace
This commit is contained in:
		
						commit
						258cf5300d
					
				|  | @ -6,7 +6,7 @@ python: | ||||||
|   - 3.2 |   - 3.2 | ||||||
|   - 3.3 |   - 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: | script: | ||||||
|   - python setup.py clean |   - python setup.py clean | ||||||
|  |  | ||||||
							
								
								
									
										40
									
								
								PIL/Image.py
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								PIL/Image.py
									
									
									
									
									
								
							|  | @ -26,7 +26,7 @@ | ||||||
| 
 | 
 | ||||||
| from __future__ import print_function | from __future__ import print_function | ||||||
| 
 | 
 | ||||||
| VERSION = "1.1.7" | from PIL import VERSION, PILLOW_VERSION, _plugins | ||||||
| 
 | 
 | ||||||
| try: | try: | ||||||
|     import warnings |     import warnings | ||||||
|  | @ -53,7 +53,12 @@ try: | ||||||
|     # the "open" function to identify files, but you cannot load |     # the "open" function to identify files, but you cannot load | ||||||
|     # them.  Note that other modules should not refer to _imaging |     # them.  Note that other modules should not refer to _imaging | ||||||
|     # directly; import Image and use the Image.core variable instead. |     # 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: | except ImportError as v: | ||||||
|     core = _imaging_not_installed() |     core = _imaging_not_installed() | ||||||
|     if str(v)[:20] == "Module use of python" and warnings: |     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", |             "of Python; most PIL functions will be disabled", | ||||||
|             RuntimeWarning |             RuntimeWarning | ||||||
|             ) |             ) | ||||||
|  |     if str(v).startswith("The _imaging extension") and warnings: | ||||||
|  |         warnings.warn(str(v), RuntimeWarning) | ||||||
| 
 | 
 | ||||||
| try: | try: | ||||||
|     import builtins |     import builtins | ||||||
|  | @ -328,34 +335,15 @@ def init(): | ||||||
|     if _initialized >= 2: |     if _initialized >= 2: | ||||||
|         return 0 |         return 0 | ||||||
| 
 | 
 | ||||||
|     visited = {} |     for plugin in _plugins: | ||||||
| 
 |  | ||||||
|     directories = sys.path |  | ||||||
| 
 |  | ||||||
|         try: |         try: | ||||||
|         directories = directories + [os.path.dirname(__file__)] |             if DEBUG: | ||||||
|     except NameError: |                 print ("Importing %s"%plugin) | ||||||
|         pass |             __import__("PIL.%s"%plugin, globals(), locals(), []) | ||||||
| 
 |  | ||||||
|     # 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: |         except ImportError: | ||||||
|             if DEBUG: |             if DEBUG: | ||||||
|                 print("Image: failed to import", end=' ') |                 print("Image: failed to import", end=' ') | ||||||
|                         print(f, ":", sys.exc_info()[1]) |                 print(plugin, ":", sys.exc_info()[1]) | ||||||
|         visited[fullpath] = None |  | ||||||
| 
 | 
 | ||||||
|     if OPEN or SAVE: |     if OPEN or SAVE: | ||||||
|         _initialized = 2 |         _initialized = 2 | ||||||
|  |  | ||||||
|  | @ -82,7 +82,7 @@ VERSION = "0.1.0 pil" | ||||||
| # --------------------------------------------------------------------. | # --------------------------------------------------------------------. | ||||||
| 
 | 
 | ||||||
| from PIL import Image | from PIL import Image | ||||||
| import _imagingcms | from PIL import _imagingcms | ||||||
| 
 | 
 | ||||||
| core = _imagingcms | core = _imagingcms | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -315,7 +315,7 @@ def getdraw(im=None, hints=None): | ||||||
|     handler = None |     handler = None | ||||||
|     if not hints or "nicest" in hints: |     if not hints or "nicest" in hints: | ||||||
|         try: |         try: | ||||||
|             import _imagingagg as handler |             from PIL import _imagingagg as handler | ||||||
|         except ImportError: |         except ImportError: | ||||||
|             pass |             pass | ||||||
|     if handler is None: |     if handler is None: | ||||||
|  |  | ||||||
|  | @ -41,7 +41,7 @@ class _imagingft_not_installed: | ||||||
|         raise ImportError("The _imagingft C module is not installed") |         raise ImportError("The _imagingft C module is not installed") | ||||||
| 
 | 
 | ||||||
| try: | try: | ||||||
|     import _imagingft as core |     from PIL import _imagingft as core | ||||||
| except ImportError: | except ImportError: | ||||||
|     core = _imagingft_not_installed() |     core = _imagingft_not_installed() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ | ||||||
| # extensions.) | # extensions.) | ||||||
| ## | ## | ||||||
| 
 | 
 | ||||||
| import _imaginggl | from PIL import _imaginggl | ||||||
| 
 | 
 | ||||||
| ## | ## | ||||||
| # Texture factory. | # Texture factory. | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| from PIL import Image | from PIL import Image | ||||||
| import _imagingmath | from PIL import _imagingmath | ||||||
| import sys | import sys | ||||||
| 
 | 
 | ||||||
| try: | try: | ||||||
|  |  | ||||||
|  | @ -28,7 +28,9 @@ | ||||||
| try: | try: | ||||||
|     import tkinter |     import tkinter | ||||||
| except ImportError: | except ImportError: | ||||||
|     import Tkinter as tkinter |     import Tkinter | ||||||
|  |     tkinter = Tkinter | ||||||
|  |     del Tkinter | ||||||
| 
 | 
 | ||||||
| from PIL import Image | from PIL import Image | ||||||
| 
 | 
 | ||||||
|  | @ -183,7 +185,7 @@ class PhotoImage: | ||||||
|         except tkinter.TclError as v: |         except tkinter.TclError as v: | ||||||
|             # activate Tkinter hook |             # activate Tkinter hook | ||||||
|             try: |             try: | ||||||
|                 import _imagingtk |                 from PIL import _imagingtk | ||||||
|                 try: |                 try: | ||||||
|                     _imagingtk.tkinit(tk.interpaddr(), 1) |                     _imagingtk.tkinit(tk.interpaddr(), 1) | ||||||
|                 except AttributeError: |                 except AttributeError: | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| from PIL import Image | from PIL import Image | ||||||
| from PIL import ImageFile | from PIL import ImageFile | ||||||
| from io import BytesIO | from io import BytesIO | ||||||
| import _webp | from PIL import _webp | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| _VALID_WEBP_MODES = { | _VALID_WEBP_MODES = { | ||||||
|  |  | ||||||
|  | @ -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'] | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ from tester import * | ||||||
| from PIL import Image | from PIL import Image | ||||||
| 
 | 
 | ||||||
| try: | try: | ||||||
|     import _webp |     from PIL import _webp | ||||||
| except: | except: | ||||||
|     skip('webp support not installed') |     skip('webp support not installed') | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -71,6 +71,7 @@ | ||||||
|  * See the README file for information on usage and redistribution. |  * See the README file for information on usage and redistribution. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | #define PILLOW_VERSION "2.1.0" | ||||||
| 
 | 
 | ||||||
| #include "Python.h" | #include "Python.h" | ||||||
| 
 | 
 | ||||||
|  | @ -3430,6 +3431,8 @@ setup_module(PyObject* m) { | ||||||
|   } |   } | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  |     PyDict_SetItemString(d, "PILLOW_VERSION", PyUnicode_FromString(PILLOW_VERSION)); | ||||||
|  | 
 | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										25
									
								
								selftest.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								selftest.py
									
									
									
									
									
								
							|  | @ -3,13 +3,24 @@ from __future__ import print_function | ||||||
| ROOT = "." | ROOT = "." | ||||||
| 
 | 
 | ||||||
| import os, sys | 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 Image | ||||||
| from PIL import ImageDraw | from PIL import ImageDraw | ||||||
| from PIL import ImageFilter | from PIL import ImageFilter | ||||||
| from PIL import ImageMath | from PIL import ImageMath | ||||||
| 
 | 
 | ||||||
|  | sys.path.insert(0,ROOT) | ||||||
|  | 
 | ||||||
| try: | try: | ||||||
|     Image.core.ping |     Image.core.ping | ||||||
| except ImportError as v: | except ImportError as v: | ||||||
|  | @ -182,16 +193,16 @@ if __name__ == "__main__": | ||||||
|     print("Python modules loaded from", os.path.dirname(Image.__file__)) |     print("Python modules loaded from", os.path.dirname(Image.__file__)) | ||||||
|     print("Binary modules loaded from", os.path.dirname(Image.core.__file__)) |     print("Binary modules loaded from", os.path.dirname(Image.core.__file__)) | ||||||
|     print("-"*68) |     print("-"*68) | ||||||
|     check_module("PIL CORE", "_imaging") |     check_module("PIL CORE", "PIL._imaging") | ||||||
|     check_module("TKINTER", "_imagingtk") |     check_module("TKINTER", "PIL._imagingtk") | ||||||
|     check_codec("JPEG", "jpeg") |     check_codec("JPEG", "jpeg") | ||||||
|     check_codec("ZLIB (PNG/ZIP)", "zip") |     check_codec("ZLIB (PNG/ZIP)", "zip") | ||||||
|     check_codec("G4 TIFF", "group4") |     check_codec("G4 TIFF", "group4") | ||||||
|     check_module("FREETYPE2", "_imagingft") |     check_module("FREETYPE2", "PIL._imagingft") | ||||||
|     check_module("LITTLECMS", "_imagingcms") |     check_module("LITTLECMS", "PIL._imagingcms") | ||||||
|     check_module("WEBP", "_webp") |     check_module("WEBP", "PIL._webp") | ||||||
|     try: |     try: | ||||||
|         import _webp |         from PIL import _webp | ||||||
|         if _webp.WebPDecoderBuggyAlpha(): |         if _webp.WebPDecoderBuggyAlpha(): | ||||||
|             print("***", "Transparent WEBP", "support not installed") |             print("***", "Transparent WEBP", "support not installed") | ||||||
|         else: |         else: | ||||||
|  |  | ||||||
							
								
								
									
										25
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								setup.py
									
									
									
									
									
								
							|  | @ -317,7 +317,7 @@ class pil_build_ext(build_ext): | ||||||
|             defs.append(("WORDS_BIGENDIAN", None)) |             defs.append(("WORDS_BIGENDIAN", None)) | ||||||
| 
 | 
 | ||||||
|         exts = [(Extension( |         exts = [(Extension( | ||||||
|             "_imaging", files, libraries=libs, define_macros=defs))] |             "PIL._imaging", files, libraries=libs, define_macros=defs))] | ||||||
| 
 | 
 | ||||||
|         # |         # | ||||||
|         # additional libraries |         # additional libraries | ||||||
|  | @ -327,23 +327,23 @@ class pil_build_ext(build_ext): | ||||||
|             if feature.freetype_version == 20: |             if feature.freetype_version == 20: | ||||||
|                 defs.append(("USE_FREETYPE_2_0", None)) |                 defs.append(("USE_FREETYPE_2_0", None)) | ||||||
|             exts.append(Extension( |             exts.append(Extension( | ||||||
|                 "_imagingft", ["_imagingft.c"], libraries=["freetype"], |                 "PIL._imagingft", ["_imagingft.c"], libraries=["freetype"], | ||||||
|                 define_macros=defs)) |                 define_macros=defs)) | ||||||
| 
 | 
 | ||||||
|         if os.path.isfile("_imagingtiff.c") and feature.tiff: |         if os.path.isfile("_imagingtiff.c") and feature.tiff: | ||||||
|             exts.append(Extension( |             exts.append(Extension( | ||||||
|                 "_imagingtiff", ["_imagingtiff.c"], libraries=["tiff"])) |                 "PIL._imagingtiff", ["_imagingtiff.c"], libraries=["tiff"])) | ||||||
| 
 | 
 | ||||||
|         if os.path.isfile("_imagingcms.c") and feature.lcms: |         if os.path.isfile("_imagingcms.c") and feature.lcms: | ||||||
|             extra = [] |             extra = [] | ||||||
|             if sys.platform == "win32": |             if sys.platform == "win32": | ||||||
|                 extra.extend(["user32", "gdi32"]) |                 extra.extend(["user32", "gdi32"]) | ||||||
|             exts.append(Extension( |             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: |         if os.path.isfile("_webp.c") and feature.webp: | ||||||
|             exts.append(Extension( |             exts.append(Extension( | ||||||
|                 "_webp", ["_webp.c"], libraries=["webp"])) |                 "PIL._webp", ["_webp.c"], libraries=["webp"])) | ||||||
| 
 | 
 | ||||||
|         if sys.platform == "darwin": |         if sys.platform == "darwin": | ||||||
|             # locate Tcl/Tk frameworks |             # locate Tcl/Tk frameworks | ||||||
|  | @ -364,16 +364,16 @@ class pil_build_ext(build_ext): | ||||||
|                     break |                     break | ||||||
|             if frameworks: |             if frameworks: | ||||||
|                 exts.append(Extension( |                 exts.append(Extension( | ||||||
|                     "_imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"], |                     "PIL._imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"], | ||||||
|                     extra_compile_args=frameworks, extra_link_args=frameworks)) |                     extra_compile_args=frameworks, extra_link_args=frameworks)) | ||||||
|                 feature.tcl = feature.tk = 1  # mark as present |                 feature.tcl = feature.tk = 1  # mark as present | ||||||
|         elif feature.tcl and feature.tk: |         elif feature.tcl and feature.tk: | ||||||
|             exts.append(Extension( |             exts.append(Extension( | ||||||
|                 "_imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"], |                 "PIL._imagingtk", ["_imagingtk.c", "Tk/tkImaging.c"], | ||||||
|                 libraries=[feature.tcl, feature.tk])) |                 libraries=[feature.tcl, feature.tk])) | ||||||
| 
 | 
 | ||||||
|         if os.path.isfile("_imagingmath.c"): |         if os.path.isfile("_imagingmath.c"): | ||||||
|             exts.append(Extension("_imagingmath", ["_imagingmath.c"])) |             exts.append(Extension("PIL._imagingmath", ["_imagingmath.c"])) | ||||||
| 
 | 
 | ||||||
|         self.extensions[:] = exts |         self.extensions[:] = exts | ||||||
| 
 | 
 | ||||||
|  | @ -507,8 +507,11 @@ setup( | ||||||
|         "Programming Language :: Python :: 3.2", |         "Programming Language :: Python :: 3.2", | ||||||
|         "Programming Language :: Python :: 3.3", ], |         "Programming Language :: Python :: 3.3", ], | ||||||
|     cmdclass={"build_ext": pil_build_ext}, |     cmdclass={"build_ext": pil_build_ext}, | ||||||
|     ext_modules=[Extension("_imaging", ["_imaging.c"])], |     ext_modules=[Extension("PIL._imaging", ["_imaging.c"])], | ||||||
|     packages=find_packages(), |     packages=find_packages(), | ||||||
|     scripts=glob.glob("Scripts/pil*.py"), |     scripts=glob.glob("Scripts/pil*.py"), | ||||||
|     keywords=["Imaging", ], |     keywords=["Imaging",], | ||||||
|     license='Standard PIL License',) |     license='Standard PIL License', | ||||||
|  |     zip_safe=True, | ||||||
|  |     ) | ||||||
|  | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user