e6cb7b4fe20e281fea80cca777321a42ed487d11
[cython.git] / setup.py
1 from distutils.core import setup, Extension
2 from distutils.sysconfig import get_python_lib
3 import os, os.path
4 import sys
5 from Cython.Compiler.Version import version
6
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:]
10
11 setup_args = {}
12
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'])]
19 else:
20     setup_args['package_data'] = {'Cython.Compiler' : ['Lexicon.pickle'],
21                                   'Cython' : ['Includes/*.pxd']}
22
23 if os.name == "posix":
24     scripts = ["bin/cython"]
25 else:
26     scripts = ["cython.py"]
27
28 try:
29     sys.argv.remove("--no-cython-compile")
30 except ValueError:
31     try:
32         from Cython.Compiler.Main import compile
33         source_root = os.path.dirname(__file__)
34         compiled_modules = ["Cython.Plex.Scanners",
35                             "Cython.Compiler.Scanning",
36                             "Cython.Compiler.Parsing",
37                             "Cython.Compiler.Visitor"]
38         extensions = []
39         for module in compiled_modules:
40             source_file = os.path.join(source_root, *module.split('.'))
41             print("Compiling module %s ..." % module)
42             result = compile(source_file + ".py")
43             if result.c_file:
44                 extensions.append(
45                     Extension(module, sources = [result.c_file])
46                     )
47             else:
48                 print("Compilation failed")
49         if extensions:
50             setup_args['ext_modules'] = extensions
51     except Exception:
52         print("ERROR: %s" % sys.exc_info()[1])
53         print("Extension module compilation failed, using plain Python implementation")
54
55
56 setup(
57   name = 'Cython', 
58   version = version,
59   url = 'http://www.cython.org',
60   author = 'Greg Ewing, Robert Bradshaw, Stefan Behnel, Dag Seljebotn, et al.',
61   author_email = 'cython-dev@codespeak.net',
62   description = "The Cython compiler for writing C extensions for the Python language.",
63   long_description = """\
64   The Cython language makes writing C extensions for the Python language as
65   easy as Python itself.  Cython is a source code translator based on the
66   well-known Pyrex_, but supports more cutting edge functionality and
67   optimizations.
68
69   The Cython language is very close to the Python language (and most Python
70   code is also valid Cython code), but Cython additionally supports calling C
71   functions and declaring C types on variables and class attributes. This
72   allows the compiler to generate very efficient C code from Cython code.
73
74   This makes Cython the ideal language for writing glue code for external C
75   libraries, and for fast C modules that speed up the execution of Python
76   code.
77
78   .. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
79   """,
80   classifiers = [
81     "Development Status :: 5 - Production/Stable",
82     "Intended Audience :: Developers",
83     "License :: OSI Approved :: Python Software Foundation License",
84     "Operating System :: OS Independent",
85     "Programming Language :: Python",
86     "Programming Language :: C",
87     "Topic :: Software Development :: Code Generators",
88     "Topic :: Software Development :: Compilers",
89     "Topic :: Software Development :: Libraries :: Python Modules"
90   ],
91
92   scripts = scripts,
93   packages=[
94     'Cython',
95     'Cython.Compiler',
96     'Cython.Distutils',
97     'Cython.Mac',
98     'Cython.Unix',
99     'Cython.Plex',
100
101     'Cython.Tests',
102     'Cython.Compiler.Tests',
103     ],
104   
105   # pyximport
106   py_modules = ["pyximport/__init__",
107                 "pyximport/pyximport",
108                 "pyximport/pyxbuild"],
109   
110   **setup_args
111   )