Further bootstrapping of Scanner
[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", "Cython.Compiler.Scanning"]
35         extensions = []
36         for module in compiled_modules:
37             source_file = os.path.join(source_root, *module.split('.'))
38             print("Compiling module %s ..." % module)
39             result = compile(source_file + ".py")
40             if result.c_file:
41                 extensions.append(
42                     Extension(module, sources = [result.c_file])
43                     )
44             else:
45                 print("Compilation failed")
46         if extensions:
47             setup_args['ext_modules'] = extensions
48     except Exception:
49         print("ERROR: %s" % sys.exc_info()[1])
50         print("Extension module compilation failed, using plain Python implementation")
51
52
53 setup(
54   name = 'Cython', 
55   version = version,
56   url = 'http://www.cython.org',
57   author = 'Greg Ewing, William Stein, Robert Bradshaw, Stefan Behnel, et al.',
58   author_email = 'wstein@gmail.com',
59   description = "The Cython compiler for writing C extensions for the Python language.",
60   long_description = """\
61   The Cython language makes writing C extensions for the Python language as
62   easy as Python itself.  Cython is a source code translator based on the
63   well-known Pyrex_, but supports more cutting edge functionality and
64   optimizations.
65
66   The Cython language is very close to the Python language (and most Python
67   code is also valid Cython code), but Cython additionally supports calling C
68   functions and declaring C types on variables and class attributes. This
69   allows the compiler to generate very efficient C code from Cython code.
70
71   This makes Cython the ideal language for writing glue code for external C
72   libraries, and for fast C modules that speed up the execution of Python
73   code.
74
75   .. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
76   """,
77   classifiers = [
78     "Development Status :: 5 - Production/Stable",
79     "Intended Audience :: Developers",
80     "License :: OSI Approved :: Python Software Foundation License",
81     "Operating System :: OS Independent",
82     "Programming Language :: Python",
83     "Programming Language :: C",
84     "Topic :: Software Development :: Code Generators",
85     "Topic :: Software Development :: Compilers",
86     "Topic :: Software Development :: Libraries :: Python Modules"
87   ],
88
89   scripts = scripts,
90   packages=[
91     'Cython',
92     'Cython.Compiler',
93     'Cython.Distutils',
94     'Cython.Mac',
95     'Cython.Unix',
96     'Cython.Plex',
97
98     'Cython.Tests',
99     'Cython.Compiler.Tests',
100     ],
101   
102   # pyximport
103   py_modules = ["pyximport/__init__",
104                 "pyximport/pyximport",
105                 "pyximport/pyxbuild"],
106   
107   **setup_args
108   )