1 from distutils.core import setup, Extension
2 from distutils.sysconfig import get_python_lib
5 from Cython.Compiler.Version import version
7 compiler_dir = os.path.join(get_python_lib(prefix=''), 'Cython/Compiler')
8 if sys.platform == "win32":
9 compiler_dir = compiler_dir[len(sys.prefix)+1:]
13 if sys.version_info[0] >= 3:
14 import lib2to3.refactor
15 from distutils.command.build_py \
16 import build_py_2to3 as build_py
17 # need to convert sources to Py3 on installation
18 fixers = [ fix for fix in lib2to3.refactor.get_fixers_from_package("lib2to3.fixes")
19 if fix.split('fix_')[-1] not in ('next',)
21 build_py.fixer_names = fixers
22 setup_args['cmdclass'] = {"build_py" : build_py}
25 if sys.version_info < (2,4):
27 cython_dir = os.path.join(get_python_lib(prefix=''), 'Cython')
28 compiler_dir = os.path.join(cython_dir, 'Compiler')
29 setup_args['data_files'] = [
30 (compiler_dir, ['Cython/Compiler/Lexicon.pickle']),
31 (cython_dir, [ f for pattern in
32 ['Cython/Includes/*.pxd',
34 'Cython/Compiler/*.pxd',
35 'Cython/Runtime/*.pyx']
36 for f in glob.glob(pattern) ])]
38 setup_args['package_data'] = {'Cython.Compiler' : ['Lexicon.pickle'],
39 'Cython' : ['Includes/*.pxd',
44 if os.name == "posix":
45 scripts = ["bin/cython"]
47 scripts = ["cython.py"]
50 if sys.version_info[0] >= 3:
52 sys.argv.remove("--no-cython-compile")
55 from distutils.command.build_ext import build_ext as build_ext_orig
56 class build_ext(build_ext_orig):
57 def build_extension(self, ext, *args, **kargs):
59 build_ext_orig.build_extension(self, ext, *args, **kargs)
61 print("Compilation of '%s' failed" % ext.sources[0])
62 from Cython.Compiler.Main import compile
63 source_root = os.path.dirname(__file__)
64 compiled_modules = ["Cython.Plex.Scanners",
65 "Cython.Compiler.Scanning",
66 "Cython.Compiler.Parsing",
67 "Cython.Compiler.Visitor",
68 "Cython.Runtime.refnanny"]
70 for module in compiled_modules:
71 source_file = os.path.join(source_root, *module.split('.'))
72 if os.path.exists(source_file + ".py"):
73 source_file = source_file + ".py"
75 source_file = source_file + ".pyx"
76 print("Compiling module %s ..." % module)
77 result = compile(source_file)
80 Extension(module, sources = [result.c_file])
83 print("Compilation failed")
85 setup_args['ext_modules'] = extensions
86 setup_args['cmdclass'] = {"build_ext" : build_ext}
88 print("ERROR: %s" % sys.exc_info()[1])
89 print("Extension module compilation failed, using plain Python implementation")
95 url = 'http://www.cython.org',
96 author = 'Greg Ewing, Robert Bradshaw, Stefan Behnel, Dag Seljebotn, et al.',
97 author_email = 'cython-dev@codespeak.net',
98 description = "The Cython compiler for writing C extensions for the Python language.",
99 long_description = """\
100 The Cython language makes writing C extensions for the Python language as
101 easy as Python itself. Cython is a source code translator based on the
102 well-known Pyrex_, but supports more cutting edge functionality and
105 The Cython language is very close to the Python language (and most Python
106 code is also valid Cython code), but Cython additionally supports calling C
107 functions and declaring C types on variables and class attributes. This
108 allows the compiler to generate very efficient C code from Cython code.
110 This makes Cython the ideal language for writing glue code for external C
111 libraries, and for fast C modules that speed up the execution of Python
114 .. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
117 "Development Status :: 5 - Production/Stable",
118 "Intended Audience :: Developers",
119 "License :: OSI Approved :: Apache Software License",
120 "Operating System :: OS Independent",
121 "Programming Language :: Python",
122 "Programming Language :: C",
123 "Programming Language :: Cython",
124 "Topic :: Software Development :: Code Generators",
125 "Topic :: Software Development :: Compilers",
126 "Topic :: Software Development :: Libraries :: Python Modules"
140 'Cython.Compiler.Tests',
144 py_modules = ["pyximport/__init__",
145 "pyximport/pyximport",
146 "pyximport/pyxbuild",