mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +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.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
|
||||
|
|
40
PIL/Image.py
40
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
|
||||
|
||||
for plugin in _plugins:
|
||||
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]
|
||||
if DEBUG:
|
||||
print ("Importing %s"%plugin)
|
||||
__import__("PIL.%s"%plugin, globals(), locals(), [])
|
||||
except ImportError:
|
||||
if DEBUG:
|
||||
print("Image: failed to import", end=' ')
|
||||
print(f, ":", sys.exc_info()[1])
|
||||
visited[fullpath] = None
|
||||
print(plugin, ":", sys.exc_info()[1])
|
||||
|
||||
if OPEN or SAVE:
|
||||
_initialized = 2
|
||||
|
|
|
@ -82,7 +82,7 @@ VERSION = "0.1.0 pil"
|
|||
# --------------------------------------------------------------------.
|
||||
|
||||
from PIL import Image
|
||||
import _imagingcms
|
||||
from PIL import _imagingcms
|
||||
|
||||
core = _imagingcms
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
# extensions.)
|
||||
##
|
||||
|
||||
import _imaginggl
|
||||
from PIL import _imaginggl
|
||||
|
||||
##
|
||||
# Texture factory.
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#
|
||||
|
||||
from PIL import Image
|
||||
import _imagingmath
|
||||
from PIL import _imagingmath
|
||||
import sys
|
||||
|
||||
try:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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
|
||||
|
||||
try:
|
||||
import _webp
|
||||
from PIL import _webp
|
||||
except:
|
||||
skip('webp support not installed')
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
25
selftest.py
25
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:
|
||||
|
|
23
setup.py
23
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',)
|
||||
license='Standard PIL License',
|
||||
zip_safe=True,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user