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

11
tox.ini
View File

@ -4,10 +4,19 @@
# and then run "tox" from this directory.
[tox]
envlist = py25, py26, py27
envlist = py25, py26, py27, py32, pypy
[testenv]
commands =
{envpython} setup.py clean
rm -rf build dist
{envpython} setup.py install
{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