Make things more Python 3 friendly. Python 3 still doesn't work because

of C code that doesn't compile with Python 3.
This commit is contained in:
Marc Abramowitz 2012-06-11 22:13:40 -07:00
parent a5738ae5a4
commit 01917a4faf
2 changed files with 42 additions and 33 deletions

View File

@ -2,7 +2,6 @@ import glob
import os import os
import platform import platform
import re import re
import string
import struct import struct
import sys import sys
@ -159,8 +158,8 @@ class pil_build_ext(build_ext):
TCL_ROOT = os.path.abspath(TCL_ROOT) TCL_ROOT = os.path.abspath(TCL_ROOT)
if os.path.isfile(os.path.join(TCL_ROOT, "include", "tk.h")): if os.path.isfile(os.path.join(TCL_ROOT, "include", "tk.h")):
# FIXME: use distutils logging (?) # FIXME: use distutils logging (?)
print "--- using Tcl/Tk libraries at", TCL_ROOT print("--- using Tcl/Tk libraries at", TCL_ROOT)
print "--- using Tcl/Tk version", TCL_VERSION print("--- using Tcl/Tk version", TCL_VERSION)
TCL_ROOT = _lib_include(TCL_ROOT) TCL_ROOT = _lib_include(TCL_ROOT)
break break
else: else:
@ -280,7 +279,7 @@ class pil_build_ext(build_ext):
defs.append(("HAVE_LIBZ", None)) defs.append(("HAVE_LIBZ", None))
if sys.platform == "win32": if sys.platform == "win32":
libs.extend(["kernel32", "user32", "gdi32"]) libs.extend(["kernel32", "user32", "gdi32"])
if struct.unpack("h", "\0\1")[0] == 1: if struct.unpack("h", "\0\1".encode('ascii'))[0] == 1:
defs.append(("WORDS_BIGENDIAN", None)) defs.append(("WORDS_BIGENDIAN", None))
exts = [(Extension( exts = [(Extension(
@ -317,7 +316,7 @@ class pil_build_ext(build_ext):
for root in framework_roots: for root in framework_roots:
if (os.path.exists(os.path.join(root, "Tcl.framework")) and if (os.path.exists(os.path.join(root, "Tcl.framework")) and
os.path.exists(os.path.join(root, "Tk.framework"))): os.path.exists(os.path.join(root, "Tk.framework"))):
print "--- using frameworks at", root print("--- using frameworks at", root)
frameworks = ["-framework", "Tcl", "-framework", "Tk"] frameworks = ["-framework", "Tcl", "-framework", "Tk"]
dir = os.path.join(root, "Tcl.framework", "Headers") dir = os.path.join(root, "Tcl.framework", "Headers")
_add_directory(self.compiler.include_dirs, dir, 0) _add_directory(self.compiler.include_dirs, dir, 0)
@ -353,15 +352,15 @@ class pil_build_ext(build_ext):
def summary_report(self, feature, unsafe_zlib): def summary_report(self, feature, unsafe_zlib):
print "-" * 68 print("-" * 68)
print "SETUP SUMMARY (Pillow", VERSION, "/ PIL %s)" % PIL_VERSION print("SETUP SUMMARY (Pillow", VERSION, "/ PIL %s)" % PIL_VERSION)
print "-" * 68 print("-" * 68)
print "version ", VERSION print("version ", VERSION)
v = string.split(sys.version, "[") v = sys.version.split("[")
print "platform ", sys.platform, string.strip(v[0]) print("platform ", sys.platform, v[0].strip())
for v in v[1:]: for v in v[1:]:
print " ", string.strip("[" + v) print(" ", ("[" + v).strip())
print "-" * 68 print("-" * 68)
options = [ options = [
(feature.tcl and feature.tk, "TKINTER"), (feature.tcl and feature.tk, "TKINTER"),
@ -375,34 +374,34 @@ class pil_build_ext(build_ext):
all = 1 all = 1
for option in options: for option in options:
if option[0]: if option[0]:
print "---", option[1], "support available" print("---", option[1], "support available")
else: else:
print "***", option[1], "support not available", print("***", option[1], "support not available")
if option[1] == "TKINTER" and _tkinter: if option[1] == "TKINTER" and _tkinter:
version = _tkinter.TCL_VERSION version = _tkinter.TCL_VERSION
print "(Tcl/Tk %s libraries needed)" % version, print("(Tcl/Tk %s libraries needed)" % version)
print print()
all = 0 all = 0
if feature.zlib and unsafe_zlib: if feature.zlib and unsafe_zlib:
print print()
print "*** Warning: zlib", unsafe_zlib, print("*** Warning: zlib", unsafe_zlib)
print "may contain a security vulnerability." print("may contain a security vulnerability.")
print "*** Consider upgrading to zlib 1.2.3 or newer." print("*** Consider upgrading to zlib 1.2.3 or newer.")
print "*** See: http://www.kb.cert.org/vuls/id/238678" print("*** See: http://www.kb.cert.org/vuls/id/238678")
print " http://www.kb.cert.org/vuls/id/680620" print(" http://www.kb.cert.org/vuls/id/680620")
print " http://www.gzip.org/zlib/advisory-2002-03-11.txt" print(" http://www.gzip.org/zlib/advisory-2002-03-11.txt")
print print()
print "-" * 68 print("-" * 68)
if not all: if not all:
print "To add a missing option, make sure you have the required" print("To add a missing option, make sure you have the required")
print "library, and set the corresponding ROOT variable in the" print("library, and set the corresponding ROOT variable in the")
print "setup.py script." print("setup.py script.")
print print()
print "To check the build, run the selftest.py script." print("To check the build, run the selftest.py script.")
def check_zlib_version(self, include_dirs): def check_zlib_version(self, include_dirs):
# look for unsafe versions of zlib # look for unsafe versions of zlib
@ -450,10 +449,11 @@ setup(
long_description=( long_description=(
_read('README.rst') + _read('README.rst') +
_read('docs/INSTALL.txt') + _read('docs/INSTALL.txt') +
_read('docs/HISTORY.txt')), _read('docs/HISTORY.txt')).decode('utf-8'),
author='Alex Clark (fork author)', author='Alex Clark (fork author)',
author_email='aclark@aclark.net', author_email='aclark@aclark.net',
url='http://github.com/collective/Pillow', url='http://github.com/collective/Pillow',
use_2to3=True,
classifiers=[ classifiers=[
"Development Status :: 6 - Mature", "Development Status :: 6 - Mature",
"Topic :: Multimedia :: Graphics", "Topic :: Multimedia :: Graphics",

11
tox.ini
View File

@ -4,10 +4,19 @@
# and then run "tox" from this directory. # and then run "tox" from this directory.
[tox] [tox]
envlist = py25, py26, py27 envlist = py25, py26, py27, py32, pypy
[testenv] [testenv]
commands = commands =
{envpython} setup.py clean {envpython} setup.py clean
rm -rf build dist
{envpython} setup.py install {envpython} setup.py install
{envpython} selftest.py {envpython} selftest.py
[testenv:py32]
commands =
{envpython} setup.py clean
rm -rf build dist
{envpython} setup.py install
2to3 -w -n -o . --add-suffix=3 selftest.py
{envpython} selftest.py3