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):
15 cython_dir = os.path.join(get_python_lib(prefix=''), 'Cython')
16 compiler_dir = os.path.join(cython_dir, 'Compiler')
17 setup_args['data_files'] = [
18 (compiler_dir, ['Cython/Compiler/Lexicon.pickle']),
19 (cython_dir, [ f for pattern in
20 ['Cython/Includes/*.pxd',
22 'Cython/Compiler/*.pxd',
23 'Cython/Runtime/*.pyx']
24 for f in glob.glob(pattern) ])]
26 setup_args['package_data'] = {'Cython.Compiler' : ['Lexicon.pickle'],
27 'Cython' : ['Includes/*.pxd',
32 if os.name == "posix":
33 scripts = ["bin/cython"]
35 scripts = ["cython.py"]
38 sys.argv.remove("--no-cython-compile")
41 from distutils.command.build_ext import build_ext as build_ext_orig
42 class build_ext(build_ext_orig):
43 def build_extension(self, ext, *args, **kargs):
45 build_ext_orig.build_extension(self, ext, *args, **kargs)
47 print("Compilation of '%s' failed" % ext.sources[0])
48 from Cython.Compiler.Main import compile
49 source_root = os.path.dirname(__file__)
50 compiled_modules = ["Cython.Plex.Scanners",
51 "Cython.Compiler.Scanning",
52 "Cython.Compiler.Parsing",
53 "Cython.Compiler.Visitor",
54 "Cython.Runtime.refnanny"]
56 for module in compiled_modules:
57 source_file = os.path.join(source_root, *module.split('.'))
58 if os.path.exists(source_file + ".py"):
59 source_file = source_file + ".py"
61 source_file = source_file + ".pyx"
62 print("Compiling module %s ..." % module)
63 result = compile(source_file)
66 Extension(module, sources = [result.c_file])
69 print("Compilation failed")
71 setup_args['ext_modules'] = extensions
72 setup_args['cmdclass'] = {"build_ext" : build_ext}
74 print("ERROR: %s" % sys.exc_info()[1])
75 print("Extension module compilation failed, using plain Python implementation")
81 url = 'http://www.cython.org',
82 author = 'Greg Ewing, Robert Bradshaw, Stefan Behnel, Dag Seljebotn, et al.',
83 author_email = 'cython-dev@codespeak.net',
84 description = "The Cython compiler for writing C extensions for the Python language.",
85 long_description = """\
86 The Cython language makes writing C extensions for the Python language as
87 easy as Python itself. Cython is a source code translator based on the
88 well-known Pyrex_, but supports more cutting edge functionality and
91 The Cython language is very close to the Python language (and most Python
92 code is also valid Cython code), but Cython additionally supports calling C
93 functions and declaring C types on variables and class attributes. This
94 allows the compiler to generate very efficient C code from Cython code.
96 This makes Cython the ideal language for writing glue code for external C
97 libraries, and for fast C modules that speed up the execution of Python
100 .. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
103 "Development Status :: 5 - Production/Stable",
104 "Intended Audience :: Developers",
105 "License :: OSI Approved :: Apache Software License",
106 "Operating System :: OS Independent",
107 "Programming Language :: Python",
108 "Programming Language :: C",
109 "Programming Language :: Cython",
110 "Topic :: Software Development :: Code Generators",
111 "Topic :: Software Development :: Compilers",
112 "Topic :: Software Development :: Libraries :: Python Modules"
126 'Cython.Compiler.Tests',
130 py_modules = ["pyximport/__init__",
131 "pyximport/pyximport",
132 "pyximport/pyxbuild",