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 < (2,4):
14 cython_dir = os.path.join(get_python_lib(prefix=''), 'Cython')
15 compiler_dir = os.path.join(cython_dir, 'Compiler')
16 setup_args['data_files'] = [
17 (compiler_dir, ['Cython/Compiler/Lexicon.pickle']),
18 (cython_dir, ['Cython/Includes/*.pxd'])]
20 setup_args['package_data'] = {'Cython.Compiler' : ['Lexicon.pickle'],
21 'Cython' : ['Includes/*.pxd']}
23 if os.name == "posix":
24 scripts = ["bin/cython"]
26 scripts = ["cython.py"]
29 sys.argv.remove("--no-cython-compile")
32 from distutils.command.build_ext import build_ext as build_ext_orig
33 class build_ext(build_ext_orig):
34 def build_extension(self, ext, *args, **kargs):
36 build_ext_orig.build_extension(self, ext, *args, **kargs)
38 print("Compilation of '%s' failed" % ext.sources[0])
39 from Cython.Compiler.Main import compile
40 source_root = os.path.dirname(__file__)
41 compiled_modules = ["Cython.Plex.Scanners",
42 "Cython.Compiler.Scanning",
43 "Cython.Compiler.Parsing",
44 "Cython.Compiler.Visitor"]
46 for module in compiled_modules:
47 source_file = os.path.join(source_root, *module.split('.'))
48 print("Compiling module %s ..." % module)
49 result = compile(source_file + ".py")
52 Extension(module, sources = [result.c_file])
55 print("Compilation failed")
57 setup_args['ext_modules'] = extensions
58 setup_args['cmdclass'] = {"build_ext" : build_ext}
60 print("ERROR: %s" % sys.exc_info()[1])
61 print("Extension module compilation failed, using plain Python implementation")
67 url = 'http://www.cython.org',
68 author = 'Greg Ewing, Robert Bradshaw, Stefan Behnel, Dag Seljebotn, et al.',
69 author_email = 'cython-dev@codespeak.net',
70 description = "The Cython compiler for writing C extensions for the Python language.",
71 long_description = """\
72 The Cython language makes writing C extensions for the Python language as
73 easy as Python itself. Cython is a source code translator based on the
74 well-known Pyrex_, but supports more cutting edge functionality and
77 The Cython language is very close to the Python language (and most Python
78 code is also valid Cython code), but Cython additionally supports calling C
79 functions and declaring C types on variables and class attributes. This
80 allows the compiler to generate very efficient C code from Cython code.
82 This makes Cython the ideal language for writing glue code for external C
83 libraries, and for fast C modules that speed up the execution of Python
86 .. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
89 "Development Status :: 5 - Production/Stable",
90 "Intended Audience :: Developers",
91 "License :: OSI Approved :: Apache Software License",
92 "Operating System :: OS Independent",
93 "Programming Language :: Python",
94 "Programming Language :: C",
95 "Topic :: Software Development :: Code Generators",
96 "Topic :: Software Development :: Compilers",
97 "Topic :: Software Development :: Libraries :: Python Modules"
110 'Cython.Compiler.Tests',
114 py_modules = ["pyximport/__init__",
115 "pyximport/pyximport",
116 "pyximport/pyxbuild",