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