提交 3d989750 authored 作者: nouiz's avatar nouiz

Merge pull request #1021 from abalkin/master

Added Python 3 support to setup.py
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# * Add download_url # * Add download_url
import os import os
import sys
import subprocess import subprocess
from fnmatch import fnmatchcase from fnmatch import fnmatchcase
from distutils.util import convert_path from distutils.util import convert_path
...@@ -12,6 +13,14 @@ try: ...@@ -12,6 +13,14 @@ try:
from setuptools import setup from setuptools import setup
except ImportError: except ImportError:
from distutils.core import setup from distutils.core import setup
try:
from distutils.command.build_py import build_py_2to3 \
as build_py
from distutils.command.build_scripts import build_scripts_2to3 \
as build_scripts
except ImportError:
from distutils.command.build_py import build_py
from distutils.command.build_scripts import build_scripts
CLASSIFIERS = """\ CLASSIFIERS = """\
...@@ -102,6 +111,29 @@ def git_version(): ...@@ -102,6 +111,29 @@ def git_version():
git_revision = "unknown-git" git_revision = "unknown-git"
return git_revision return git_revision
# Python 2.4 compatibility: Python versions 2.6 and later support new
# exception syntax, but for now we have to resort to exec.
if sys.hexversion >= 0x2070000:
exec("""\
def write_text(filename, text):
with open(filename, 'w') as a:
try:
a.write(text)
except Exception as e:
print(e)
""")
else:
exec("""\
def write_text(filename, text):
a = open(filename, 'w')
try:
try:
a.write(text)
except Exception, e:
print e
finally:
a.close()
""")
def write_version_py(filename=os.path.join('theano', 'generated_version.py')): def write_version_py(filename=os.path.join('theano', 'generated_version.py')):
cnt = """ cnt = """
...@@ -126,19 +158,11 @@ if not release: ...@@ -126,19 +158,11 @@ if not release:
GIT_REVISION = "unknown-git" GIT_REVISION = "unknown-git"
FULL_VERSION += '.dev-' + GIT_REVISION FULL_VERSION += '.dev-' + GIT_REVISION
text = cnt % {'version': VERSION,
a = open(filename, 'w') 'full_version': FULL_VERSION,
try: 'git_revision': GIT_REVISION,
try: 'isrelease': str(ISRELEASED)}
a.write(cnt % {'version': VERSION, write_text(filename, text)
'full_version': FULL_VERSION,
'git_revision': GIT_REVISION,
'isrelease': str(ISRELEASED)})
except Exception, e:
print e
finally:
a.close()
def do_setup(): def do_setup():
write_version_py() write_version_py()
...@@ -163,7 +187,9 @@ def do_setup(): ...@@ -163,7 +187,9 @@ def do_setup():
keywords=' '.join([ keywords=' '.join([
'theano', 'math', 'numerical', 'symbolic', 'blas', 'theano', 'math', 'numerical', 'symbolic', 'blas',
'numpy', 'gpu', 'autodiff', 'differentiation' 'numpy', 'gpu', 'autodiff', 'differentiation'
]) ]),
cmdclass = {'build_py': build_py,
'build_scripts': build_scripts}
) )
if __name__ == "__main__": if __name__ == "__main__":
do_setup() do_setup()
...@@ -294,7 +294,10 @@ if sys.version_info[:2] < (2, 7): ...@@ -294,7 +294,10 @@ if sys.version_info[:2] < (2, 7):
return not self == other return not self == other
else: else:
from UserDict import DictMixin try:
from UserDict import DictMixin
except ImportError:
from collections import MutableMapping as DictMixin
OrderedDict = collections.OrderedDict OrderedDict = collections.OrderedDict
from collections import Callable from collections import Callable
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论