1 from distutils.core import setup, Extension
2 from distutils.sysconfig import get_python_lib
6 compiler_dir = os.path.join(get_python_lib(prefix=''), 'Cython/Compiler')
7 if sys.platform == "win32":
8 compiler_dir = compiler_dir[len(sys.prefix)+1:]
12 if sys.version_info[0] >= 3:
13 import lib2to3.refactor
14 from distutils.command.build_py \
15 import build_py_2to3 as build_py
16 # need to convert sources to Py3 on installation
17 fixers = [ fix for fix in lib2to3.refactor.get_fixers_from_package("lib2to3.fixes")
18 if fix.split('fix_')[-1] not in ('next',)
20 build_py.fixer_names = fixers
21 setup_args['cmdclass'] = {"build_py" : build_py}
24 if sys.version_info < (2,4):
26 cython_dir = os.path.join(get_python_lib(prefix=''), 'Cython')
27 compiler_dir = os.path.join(cython_dir, 'Compiler')
28 setup_args['data_files'] = [
29 (compiler_dir, ['Cython/Compiler/Lexicon.pickle']),
30 (cython_dir, [ f for pattern in
31 ['Cython/Includes/*.pxd',
33 'Cython/Compiler/*.pxd',
34 'Cython/Runtime/*.pyx']
35 for f in glob.glob(pattern) ])]
37 setup_args['package_data'] = {'Cython.Compiler' : ['Lexicon.pickle'],
38 'Cython' : ['Includes/*.pxd',
43 if os.name == "posix":
44 scripts = ["bin/cython"]
46 scripts = ["cython.py"]
49 if sys.version_info[0] >= 3:
51 sys.argv.remove("--no-cython-compile")
54 from distutils.command.build_ext import build_ext as build_ext_orig
55 class build_ext(build_ext_orig):
56 def build_extension(self, ext, *args, **kargs):
58 build_ext_orig.build_extension(self, ext, *args, **kargs)
60 print("Compilation of '%s' failed" % ext.sources[0])
61 from Cython.Compiler.Main import compile
62 from Cython import Utils
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 pyx_source_file = source_file + ".py"
75 pyx_source_file = source_file + ".pyx"
76 c_source_file = source_file + ".c"
77 if not os.path.exists(c_source_file) or \
78 Utils.file_newer_than(pyx_source_file,
79 Utils.modification_time(c_source_file)):
80 print("Compiling module %s ..." % module)
81 result = compile(pyx_source_file)
82 c_source_file = result.c_file
85 Extension(module, sources = [c_source_file])
88 print("Compilation failed")
90 setup_args['ext_modules'] = extensions
91 setup_args['cmdclass'] = {"build_ext" : build_ext}
93 print("ERROR: %s" % sys.exc_info()[1])
94 print("Extension module compilation failed, using plain Python implementation")
97 from Cython.Compiler.Version import version
102 url = 'http://www.cython.org',
103 author = 'Greg Ewing, Robert Bradshaw, Stefan Behnel, Dag Seljebotn, et al.',
104 author_email = 'cython-dev@codespeak.net',
105 description = "The Cython compiler for writing C extensions for the Python language.",
106 long_description = """\
107 The Cython language makes writing C extensions for the Python language as
108 easy as Python itself. Cython is a source code translator based on the
109 well-known Pyrex_, but supports more cutting edge functionality and
112 The Cython language is very close to the Python language (and most Python
113 code is also valid Cython code), but Cython additionally supports calling C
114 functions and declaring C types on variables and class attributes. This
115 allows the compiler to generate very efficient C code from Cython code.
117 This makes Cython the ideal language for writing glue code for external C
118 libraries, and for fast C modules that speed up the execution of Python
121 .. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
124 "Development Status :: 5 - Production/Stable",
125 "Intended Audience :: Developers",
126 "License :: OSI Approved :: Apache Software License",
127 "Operating System :: OS Independent",
128 "Programming Language :: Python",
129 "Programming Language :: C",
130 "Programming Language :: Cython",
131 "Topic :: Software Development :: Code Generators",
132 "Topic :: Software Development :: Compilers",
133 "Topic :: Software Development :: Libraries :: Python Modules"
147 'Cython.Compiler.Tests',
151 py_modules = ["pyximport/__init__",
152 "pyximport/pyximport",
153 "pyximport/pyxbuild",