From f89d8fe576e5547c5bd14eb4f826582e95d36c43 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 24 Apr 2009 13:34:02 +0200 Subject: [PATCH] use lib2to3 to port to Py3 on installation --- setup.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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: -- 2.26.2