From: Stefan Behnel Date: Fri, 24 Apr 2009 11:34:02 +0000 (+0200) Subject: use lib2to3 to port to Py3 on installation X-Git-Tag: 0.12.alpha0~312 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f89d8fe576e5547c5bd14eb4f826582e95d36c43;p=cython.git use lib2to3 to port to Py3 on installation --- diff --git a/setup.py b/setup.py index 042ed9fb..93aa07eb 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,10 @@ from distutils.core import setup, Extension from distutils.sysconfig import get_python_lib import os, os.path import sys -from Cython.Compiler.Version import version +try: + from Cython.Compiler.Version import version +except ImportError: + version = None compiler_dir = os.path.join(get_python_lib(prefix=''), 'Cython/Compiler') if sys.platform == "win32": @@ -10,6 +13,18 @@ if sys.platform == "win32": setup_args = {} +if sys.version_info[0] >= 3: + import lib2to3.refactor + from distutils.command.build_py \ + import build_py_2to3 as build_py + # need to convert sources to Py3 on installation + fixers = [ fix for fix in lib2to3.refactor.get_fixers_from_package("lib2to3.fixes") + if fix.split('fix_')[-1] not in ('next',) + ] + build_py.fixer_names = fixers + setup_args['cmdclass'] = {"build_py" : build_py} + + if sys.version_info < (2,4): import glob cython_dir = os.path.join(get_python_lib(prefix=''), 'Cython') @@ -35,6 +50,8 @@ else: scripts = ["cython.py"] try: + if version is None: + raise ValueError sys.argv.remove("--no-cython-compile") except ValueError: try: