Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 181 lines (159 sloc) 6.58 kB
911b803 compile Cython.Plex.Scanners module on install to speed up compilation
Stefan Behnel authored
1 from distutils.core import setup, Extension
c4fa206 @williamstein Initial version
williamstein authored
2 from distutils.sysconfig import get_python_lib
911b803 compile Cython.Plex.Scanners module on install to speed up compilation
Stefan Behnel authored
3 import os, os.path
7d717f7 @robertwb buildfile changes
robertwb authored
4 import sys
c4fa206 @williamstein Initial version
williamstein authored
5
6 compiler_dir = os.path.join(get_python_lib(prefix=''), 'Cython/Compiler')
7d717f7 @robertwb buildfile changes
robertwb authored
7 if sys.platform == "win32":
8 compiler_dir = compiler_dir[len(sys.prefix)+1:]
c4fa206 @williamstein Initial version
williamstein authored
9
594ba31 @robertwb Remove extra files in distribution tar.
robertwb authored
10 if sys.platform == "darwin":
11 # Don't create resource files on OS X tar.
12 os.environ['COPY_EXTENDED_ATTRIBUTES_DISABLE'] = 'true'
13 os.environ['COPYFILE_DISABLE'] = 'true'
14
655041e fix target directory for Lexicon.pickle (do it right this time)
Stefan Behnel authored
15 setup_args = {}
16
f89d8fe use lib2to3 to port to Py3 on installation
Stefan Behnel authored
17 if sys.version_info[0] >= 3:
18 import lib2to3.refactor
19 from distutils.command.build_py \
20 import build_py_2to3 as build_py
21 # need to convert sources to Py3 on installation
22 fixers = [ fix for fix in lib2to3.refactor.get_fixers_from_package("lib2to3.fixes")
23 if fix.split('fix_')[-1] not in ('next',)
24 ]
25 build_py.fixer_names = fixers
26 setup_args['cmdclass'] = {"build_py" : build_py}
27
28
655041e fix target directory for Lexicon.pickle (do it right this time)
Stefan Behnel authored
29 if sys.version_info < (2,4):
a28d90b fix inclusion of package data files
Stefan Behnel authored
30 import glob
4896ddf install Includes directory as Cython/Includes
Stefan Behnel authored
31 cython_dir = os.path.join(get_python_lib(prefix=''), 'Cython')
32 compiler_dir = os.path.join(cython_dir, 'Compiler')
655041e fix target directory for Lexicon.pickle (do it right this time)
Stefan Behnel authored
33 setup_args['data_files'] = [
38bc283 Py2.3 fix
Stefan Behnel authored
34 (compiler_dir, ['Cython/Compiler/Lexicon.pickle']),
a28d90b fix inclusion of package data files
Stefan Behnel authored
35 (cython_dir, [ f for pattern in
36 ['Cython/Includes/*.pxd',
37 'Cython/Plex/*.pxd',
38 'Cython/Compiler/*.pxd',
39 'Cython/Runtime/*.pyx']
40 for f in glob.glob(pattern) ])]
655041e fix target directory for Lexicon.pickle (do it right this time)
Stefan Behnel authored
41 else:
4896ddf install Includes directory as Cython/Includes
Stefan Behnel authored
42 setup_args['package_data'] = {'Cython.Compiler' : ['Lexicon.pickle'],
a28d90b fix inclusion of package data files
Stefan Behnel authored
43 'Cython' : ['Includes/*.pxd',
44 'Plex/*.pxd',
45 'Compiler/*.pxd',
46 'Runtime/*.pyx']}
c4fa206 @williamstein Initial version
williamstein authored
47
0855d80 @cournape Optional setuptools-based cython build
cournape authored
48 # This dict is used for passing extra arguments that are setuptools
49 # specific to setup
50 setuptools_extra_args = {}
51
52 if 'setuptools' in sys.modules:
53 setuptools_extra_args['zip_safe'] = False
54 setuptools_extra_args['entry_points'] = {
55 'console_scripts': [
56 'cython = Cython.Compiler.Main:setuptools_main',
57 ]
58 }
59 scripts = []
c4fa206 @williamstein Initial version
williamstein authored
60 else:
0855d80 @cournape Optional setuptools-based cython build
cournape authored
61 if os.name == "posix":
62 scripts = ["bin/cython"]
63 else:
64 scripts = ["cython.py"]
65
c4fa206 @williamstein Initial version
williamstein authored
66
911b803 compile Cython.Plex.Scanners module on install to speed up compilation
Stefan Behnel authored
67 try:
c12815a make sure we do not compile (for now) in Py3
Stefan Behnel authored
68 if sys.version_info[0] >= 3:
f89d8fe use lib2to3 to port to Py3 on installation
Stefan Behnel authored
69 raise ValueError
c8b7c2a fix setup option clash
Stefan Behnel authored
70 sys.argv.remove("--no-cython-compile")
911b803 compile Cython.Plex.Scanners module on install to speed up compilation
Stefan Behnel authored
71 except ValueError:
72 try:
5c6d28f @dalcinl add custom distutils build_ext command ignoring C compiler failues wh…
dalcinl authored
73 from distutils.command.build_ext import build_ext as build_ext_orig
74 class build_ext(build_ext_orig):
75 def build_extension(self, ext, *args, **kargs):
76 try:
77 build_ext_orig.build_extension(self, ext, *args, **kargs)
78 except StandardError:
79 print("Compilation of '%s' failed" % ext.sources[0])
911b803 compile Cython.Plex.Scanners module on install to speed up compilation
Stefan Behnel authored
80 from Cython.Compiler.Main import compile
b090065 only regenerate Cython's own C sources when the .py files were updated
Stefan Behnel authored
81 from Cython import Utils
911b803 compile Cython.Plex.Scanners module on install to speed up compilation
Stefan Behnel authored
82 source_root = os.path.dirname(__file__)
23c28ef compile Visitor.py, reduces lxml compile time by another ~20%
Stefan Behnel authored
83 compiled_modules = ["Cython.Plex.Scanners",
84 "Cython.Compiler.Scanning",
85 "Cython.Compiler.Parsing",
2dc08fb @dalcinl build and install "Cython.Runtime.refnanny", use it as a fallback if …
dalcinl authored
86 "Cython.Compiler.Visitor",
87 "Cython.Runtime.refnanny"]
911b803 compile Cython.Plex.Scanners module on install to speed up compilation
Stefan Behnel authored
88 extensions = []
89 for module in compiled_modules:
90 source_file = os.path.join(source_root, *module.split('.'))
2dc08fb @dalcinl build and install "Cython.Runtime.refnanny", use it as a fallback if …
dalcinl authored
91 if os.path.exists(source_file + ".py"):
b090065 only regenerate Cython's own C sources when the .py files were updated
Stefan Behnel authored
92 pyx_source_file = source_file + ".py"
2dc08fb @dalcinl build and install "Cython.Runtime.refnanny", use it as a fallback if …
dalcinl authored
93 else:
b090065 only regenerate Cython's own C sources when the .py files were updated
Stefan Behnel authored
94 pyx_source_file = source_file + ".pyx"
95 c_source_file = source_file + ".c"
96 if not os.path.exists(c_source_file) or \
97 Utils.file_newer_than(pyx_source_file,
98 Utils.modification_time(c_source_file)):
99 print("Compiling module %s ..." % module)
100 result = compile(pyx_source_file)
101 c_source_file = result.c_file
102 if c_source_file:
911b803 compile Cython.Plex.Scanners module on install to speed up compilation
Stefan Behnel authored
103 extensions.append(
b090065 only regenerate Cython's own C sources when the .py files were updated
Stefan Behnel authored
104 Extension(module, sources = [c_source_file])
911b803 compile Cython.Plex.Scanners module on install to speed up compilation
Stefan Behnel authored
105 )
106 else:
107 print("Compilation failed")
108 if extensions:
109 setup_args['ext_modules'] = extensions
5c6d28f @dalcinl add custom distutils build_ext command ignoring C compiler failues wh…
dalcinl authored
110 setup_args['cmdclass'] = {"build_ext" : build_ext}
911b803 compile Cython.Plex.Scanners module on install to speed up compilation
Stefan Behnel authored
111 except Exception:
112 print("ERROR: %s" % sys.exc_info()[1])
113 print("Extension module compilation failed, using plain Python implementation")
114
0855d80 @cournape Optional setuptools-based cython build
cournape authored
115 setup_args.update(setuptools_extra_args)
911b803 compile Cython.Plex.Scanners module on install to speed up compilation
Stefan Behnel authored
116
0fba6e9 import Cython as late as possible
Stefan Behnel authored
117 from Cython.Compiler.Version import version
118
c4fa206 @williamstein Initial version
williamstein authored
119 setup(
2dc08fb @dalcinl build and install "Cython.Runtime.refnanny", use it as a fallback if …
dalcinl authored
120 name = 'Cython',
c4fa206 @williamstein Initial version
williamstein authored
121 version = version,
122 url = 'http://www.cython.org',
859db27 @robertwb 0.10.1 - bump version, metadata
robertwb authored
123 author = 'Greg Ewing, Robert Bradshaw, Stefan Behnel, Dag Seljebotn, et al.',
124 author_email = 'cython-dev@codespeak.net',
79c376e added metadata for Cheeseshop
sbehnel@delle.100world.global authored
125 description = "The Cython compiler for writing C extensions for the Python language.",
126 long_description = """\
127 The Cython language makes writing C extensions for the Python language as
128 easy as Python itself. Cython is a source code translator based on the
129 well-known Pyrex_, but supports more cutting edge functionality and
130 optimizations.
131
132 The Cython language is very close to the Python language (and most Python
133 code is also valid Cython code), but Cython additionally supports calling C
134 functions and declaring C types on variables and class attributes. This
135 allows the compiler to generate very efficient C code from Cython code.
136
137 This makes Cython the ideal language for writing glue code for external C
138 libraries, and for fast C modules that speed up the execution of Python
139 code.
140
141 .. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
142 """,
143 classifiers = [
144 "Development Status :: 5 - Production/Stable",
145 "Intended Audience :: Developers",
e10b4da fixed license reference in setup.py
Stefan Behnel authored
146 "License :: OSI Approved :: Apache Software License",
79c376e added metadata for Cheeseshop
sbehnel@delle.100world.global authored
147 "Operating System :: OS Independent",
148 "Programming Language :: Python",
8ba61dc Cython is basically Py3 clean
Stefan Behnel authored
149 "Programming Language :: Python :: 2",
150 "Programming Language :: Python :: 3",
9cc67e6 @robertwb misc updates
robertwb authored
151 "Programming Language :: C",
bf0af31 @robertwb Add trove classifier "Programming Language :: Cython"
robertwb authored
152 "Programming Language :: Cython",
79c376e added metadata for Cheeseshop
sbehnel@delle.100world.global authored
153 "Topic :: Software Development :: Code Generators",
154 "Topic :: Software Development :: Compilers",
155 "Topic :: Software Development :: Libraries :: Python Modules"
156 ],
157
c4fa206 @williamstein Initial version
williamstein authored
158 scripts = scripts,
159 packages=[
160 'Cython',
161 'Cython.Compiler',
2dc08fb @dalcinl build and install "Cython.Runtime.refnanny", use it as a fallback if …
dalcinl authored
162 'Cython.Runtime',
c4fa206 @williamstein Initial version
williamstein authored
163 'Cython.Distutils',
164 'Cython.Mac',
3c71d2f @robertwb Cleanup MANIFEST
robertwb authored
165 'Cython.Unix',
166 'Cython.Plex',
167
168 'Cython.Tests',
169 'Cython.Compiler.Tests',
c4fa206 @williamstein Initial version
williamstein authored
170 ],
2dc08fb @dalcinl build and install "Cython.Runtime.refnanny", use it as a fallback if …
dalcinl authored
171
a91171e @robertwb Better setup.py pyximport installation
robertwb authored
172 # pyximport
a7b92ca @dalcinl [Cython] PATCH: fix pyximport installation as a package
dalcinl authored
173 py_modules = ["pyximport/__init__",
174 "pyximport/pyximport",
2dc08fb @dalcinl build and install "Cython.Runtime.refnanny", use it as a fallback if …
dalcinl authored
175 "pyximport/pyxbuild",
176
7c28345 @robertwb install cython.py for pure python mode use
robertwb authored
177 "cython"],
2dc08fb @dalcinl build and install "Cython.Runtime.refnanny", use it as a fallback if …
dalcinl authored
178
655041e fix target directory for Lexicon.pickle (do it right this time)
Stefan Behnel authored
179 **setup_args
c4fa206 @williamstein Initial version
williamstein authored
180 )
Something went wrong with that request. Please try again.