From 79173c79dbef06814cc50b248ac808d2a6271e40 Mon Sep 17 00:00:00 2001 From: Z Snow Date: Thu, 18 Jun 2015 04:03:18 +1000 Subject: [PATCH 1/3] First pass at Python3 support. --- setup.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index 6471f71..f2fea4b 100755 --- a/setup.py +++ b/setup.py @@ -1,29 +1,32 @@ import sys, os, shutil, glob - +sys.argv.append('build') # Some Angstrom images are missing the py_compile module; get it if not # present: import random python_lib_path = random.__file__.split('random')[0] if not os.path.exists(python_lib_path + 'py_compile.py'): - print "py_compile module missing; installing to %spy_compile.py" %\ - python_lib_path - import urllib2 + print("py_compile module missing; installing to %spy_compile.py" %\ + python_lib_path) + try: + import urllib.request as urllib2 + except ImportError: + import urllib2 url = "http://hg.python.org/cpython/raw-file/4ebe1ede981e/Lib/py_compile.py" py_compile = urllib2.urlopen(url) - with open(python_lib_path+'py_compile.py', 'w') as f: + with open(python_lib_path+'py_compile.py', 'wb') as f: f.write(py_compile.read()) - print "testing py_compile..." + print("testing py_compile...") try: import py_compile - print "py_compile installed successfully" - except Exception, e: - print "*py_compile install failed, could not import" - print "*Exception raised:" + print("py_compile installed successfully") + except Exception as e: + print("*py_compile install failed, could not import") + print("*Exception raised:") raise e -print "Installing PyBBIO..." +print("Installing PyBBIO...") from setuptools import setup, Extension, find_packages From 454af9ce8da64f1657e90ad22ec82d6b7b5325fc Mon Sep 17 00:00:00 2001 From: Z Snow Date: Thu, 18 Jun 2015 04:10:07 +1000 Subject: [PATCH 2/3] py_compile is in Python3. --- setup.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/setup.py b/setup.py index f2fea4b..a00ed53 100755 --- a/setup.py +++ b/setup.py @@ -13,18 +13,21 @@ import urllib.request as urllib2 except ImportError: import urllib2 - url = "http://hg.python.org/cpython/raw-file/4ebe1ede981e/Lib/py_compile.py" - py_compile = urllib2.urlopen(url) - with open(python_lib_path+'py_compile.py', 'wb') as f: - f.write(py_compile.read()) - print("testing py_compile...") try: import py_compile - print("py_compile installed successfully") - except Exception as e: - print("*py_compile install failed, could not import") - print("*Exception raised:") - raise e + except ImportError: + url = "http://hg.python.org/cpython/raw-file/4ebe1ede981e/Lib/py_compile.py" + py_compile = urllib2.urlopen(url) + with open(python_lib_path+'py_compile.py', 'wb') as f: + f.write(py_compile.read()) + print("testing py_compile...") + try: + import py_compile + print("py_compile installed successfully") + except Exception as e: + print("*py_compile install failed, could not import") + print("*Exception raised:") + raise e print("Installing PyBBIO...") From 82a80596f3161eb10c4de786921f497789947f81 Mon Sep 17 00:00:00 2001 From: Z Snow Date: Thu, 18 Jun 2015 04:29:51 +1000 Subject: [PATCH 3/3] We only need urllib if we need to install py_compile. --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index a00ed53..601dbda 100755 --- a/setup.py +++ b/setup.py @@ -9,13 +9,13 @@ if not os.path.exists(python_lib_path + 'py_compile.py'): print("py_compile module missing; installing to %spy_compile.py" %\ python_lib_path) - try: - import urllib.request as urllib2 - except ImportError: - import urllib2 try: import py_compile except ImportError: + try: + import urllib.request as urllib2 + except ImportError: + import urllib2 url = "http://hg.python.org/cpython/raw-file/4ebe1ede981e/Lib/py_compile.py" py_compile = urllib2.urlopen(url) with open(python_lib_path+'py_compile.py', 'wb') as f: