1 from distutils.core import setup, Extension
2 from distutils.sysconfig import get_python_lib
6 if 'sdist' in sys.argv:
7 # Record the current revision in .hgrev
8 import subprocess # os.popen is cleaner but depricated
9 changset = subprocess.Popen("hg log --rev tip | grep changeset",
11 stdout=subprocess.PIPE).stdout.read()
12 rev = changset.split(':')[-1].strip()
13 hgrev = open('.hgrev', 'w')
17 compiler_dir = os.path.join(get_python_lib(prefix=''), 'Cython/Compiler')
18 if sys.platform == "win32":
19 compiler_dir = compiler_dir[len(sys.prefix)+1:]
21 if sys.platform == "darwin":
22 # Don't create resource files on OS X tar.
23 os.environ['COPY_EXTENDED_ATTRIBUTES_DISABLE'] = 'true'
24 os.environ['COPYFILE_DISABLE'] = 'true'
28 if sys.version_info[0] >= 3:
29 import lib2to3.refactor
30 from distutils.command.build_py \
31 import build_py_2to3 as build_py
32 # need to convert sources to Py3 on installation
33 fixers = [ fix for fix in lib2to3.refactor.get_fixers_from_package("lib2to3.fixes")
34 if fix.split('fix_')[-1] not in ('next',)
36 build_py.fixer_names = fixers
37 setup_args['cmdclass'] = {"build_py" : build_py}
40 if sys.version_info < (2,4):
42 cython_dir = os.path.join(get_python_lib(prefix=''), 'Cython')
43 compiler_dir = os.path.join(cython_dir, 'Compiler')
44 setup_args['data_files'] = [
45 (compiler_dir, ['Cython/Compiler/Lexicon.pickle']),
46 (cython_dir, [ f for pattern in
47 ['Cython/Includes/*.pxd',
49 'Cython/Compiler/*.pxd',
50 'Cython/Runtime/*.pyx']
51 for f in glob.glob(pattern) ])]
53 setup_args['package_data'] = {'Cython.Compiler' : ['Lexicon.pickle'],
54 'Cython' : ['Includes/*.pxd',
59 # This dict is used for passing extra arguments that are setuptools
61 setuptools_extra_args = {}
63 if 'setuptools' in sys.modules:
64 setuptools_extra_args['zip_safe'] = False
65 setuptools_extra_args['entry_points'] = {
67 'cython = Cython.Compiler.Main:setuptools_main',
72 if os.name == "posix":
73 scripts = ["bin/cython"]
75 scripts = ["cython.py"]
79 if sys.version_info[0] >= 3:
81 sys.argv.remove("--no-cython-compile")
84 from distutils.command.build_ext import build_ext as build_ext_orig
85 class build_ext(build_ext_orig):
86 def build_extension(self, ext, *args, **kargs):
88 build_ext_orig.build_extension(self, ext, *args, **kargs)
90 print("Compilation of '%s' failed" % ext.sources[0])
91 from Cython.Compiler.Main import compile
92 from Cython import Utils
93 source_root = os.path.dirname(__file__)
94 compiled_modules = ["Cython.Plex.Scanners",
95 "Cython.Compiler.Scanning",
96 "Cython.Compiler.Parsing",
97 "Cython.Compiler.Visitor",
98 "Cython.Runtime.refnanny"]
100 for module in compiled_modules:
101 source_file = os.path.join(source_root, *module.split('.'))
102 if os.path.exists(source_file + ".py"):
103 pyx_source_file = source_file + ".py"
105 pyx_source_file = source_file + ".pyx"
106 c_source_file = source_file + ".c"
107 if not os.path.exists(c_source_file) or \
108 Utils.file_newer_than(pyx_source_file,
109 Utils.modification_time(c_source_file)):
110 print("Compiling module %s ..." % module)
111 result = compile(pyx_source_file)
112 c_source_file = result.c_file
115 Extension(module, sources = [c_source_file])
118 print("Compilation failed")
120 setup_args['ext_modules'] = extensions
121 setup_args['cmdclass'] = {"build_ext" : build_ext}
123 print("ERROR: %s" % sys.exc_info()[1])
124 print("Extension module compilation failed, using plain Python implementation")
126 setup_args.update(setuptools_extra_args)
128 from Cython.Compiler.Version import version
133 url = 'http://www.cython.org',
134 author = 'Greg Ewing, Robert Bradshaw, Stefan Behnel, Dag Seljebotn, et al.',
135 author_email = 'cython-dev@codespeak.net',
136 description = "The Cython compiler for writing C extensions for the Python language.",
137 long_description = """\
138 The Cython language makes writing C extensions for the Python language as
139 easy as Python itself. Cython is a source code translator based on the
140 well-known Pyrex_, but supports more cutting edge functionality and
143 The Cython language is very close to the Python language (and most Python
144 code is also valid Cython code), but Cython additionally supports calling C
145 functions and declaring C types on variables and class attributes. This
146 allows the compiler to generate very efficient C code from Cython code.
148 This makes Cython the ideal language for writing glue code for external C
149 libraries, and for fast C modules that speed up the execution of Python
152 .. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
155 "Development Status :: 5 - Production/Stable",
156 "Intended Audience :: Developers",
157 "License :: OSI Approved :: Apache Software License",
158 "Operating System :: OS Independent",
159 "Programming Language :: Python",
160 "Programming Language :: Python :: 2",
161 "Programming Language :: Python :: 3",
162 "Programming Language :: C",
163 "Programming Language :: Cython",
164 "Topic :: Software Development :: Code Generators",
165 "Topic :: Software Development :: Compilers",
166 "Topic :: Software Development :: Libraries :: Python Modules"
178 'Cython.Compiler.Tests',
182 py_modules = ["pyximport/__init__",
183 "pyximport/pyximport",
184 "pyximport/pyxbuild",