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 (cython_dir, [ f for pattern in
46 ['Cython/Includes/*.pxd',
48 'Cython/Compiler/*.pxd',
49 'Cython/Runtime/*.pyx']
50 for f in glob.glob(pattern) ])]
52 setup_args['package_data'] = {'Cython' : ['Includes/*.pxd',
57 # This dict is used for passing extra arguments that are setuptools
59 setuptools_extra_args = {}
61 if 'setuptools' in sys.modules:
62 setuptools_extra_args['zip_safe'] = False
63 setuptools_extra_args['entry_points'] = {
65 'cython = Cython.Compiler.Main:setuptools_main',
70 if os.name == "posix":
71 scripts = ["bin/cython"]
73 scripts = ["cython.py"]
77 if sys.version_info[0] >= 3:
79 sys.argv.remove("--no-cython-compile")
82 from distutils.command.build_ext import build_ext as build_ext_orig
83 class build_ext(build_ext_orig):
84 def build_extension(self, ext, *args, **kargs):
86 build_ext_orig.build_extension(self, ext, *args, **kargs)
88 print("Compilation of '%s' failed" % ext.sources[0])
89 from Cython.Compiler.Main import compile
90 from Cython import Utils
91 source_root = os.path.dirname(__file__)
92 compiled_modules = ["Cython.Plex.Scanners",
93 "Cython.Compiler.Scanning",
94 "Cython.Compiler.Parsing",
95 "Cython.Compiler.Visitor",
96 "Cython.Runtime.refnanny"]
98 for module in compiled_modules:
99 source_file = os.path.join(source_root, *module.split('.'))
100 if os.path.exists(source_file + ".py"):
101 pyx_source_file = source_file + ".py"
103 pyx_source_file = source_file + ".pyx"
104 c_source_file = source_file + ".c"
105 if not os.path.exists(c_source_file) or \
106 Utils.file_newer_than(pyx_source_file,
107 Utils.modification_time(c_source_file)):
108 print("Compiling module %s ..." % module)
109 result = compile(pyx_source_file)
110 c_source_file = result.c_file
113 Extension(module, sources = [c_source_file])
116 print("Compilation failed")
118 setup_args['ext_modules'] = extensions
119 setup_args['cmdclass'] = {"build_ext" : build_ext}
121 print("ERROR: %s" % sys.exc_info()[1])
122 print("Extension module compilation failed, using plain Python implementation")
124 setup_args.update(setuptools_extra_args)
126 from Cython.Compiler.Version import version
131 url = 'http://www.cython.org',
132 author = 'Greg Ewing, Robert Bradshaw, Stefan Behnel, Dag Seljebotn, et al.',
133 author_email = 'cython-dev@codespeak.net',
134 description = "The Cython compiler for writing C extensions for the Python language.",
135 long_description = """\
136 The Cython language makes writing C extensions for the Python language as
137 easy as Python itself. Cython is a source code translator based on the
138 well-known Pyrex_, but supports more cutting edge functionality and
141 The Cython language is very close to the Python language (and most Python
142 code is also valid Cython code), but Cython additionally supports calling C
143 functions and declaring C types on variables and class attributes. This
144 allows the compiler to generate very efficient C code from Cython code.
146 This makes Cython the ideal language for writing glue code for external C
147 libraries, and for fast C modules that speed up the execution of Python
150 .. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
153 "Development Status :: 5 - Production/Stable",
154 "Intended Audience :: Developers",
155 "License :: OSI Approved :: Apache Software License",
156 "Operating System :: OS Independent",
157 "Programming Language :: Python",
158 "Programming Language :: Python :: 2",
159 "Programming Language :: Python :: 3",
160 "Programming Language :: C",
161 "Programming Language :: Cython",
162 "Topic :: Software Development :: Code Generators",
163 "Topic :: Software Development :: Compilers",
164 "Topic :: Software Development :: Libraries :: Python Modules"
176 'Cython.Compiler.Tests',
180 py_modules = ["pyximport/__init__",
181 "pyximport/pyximport",
182 "pyximport/pyxbuild",