-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathsetup.py
300 lines (288 loc) · 13.3 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
""" Usage:
python3 setup.py build
Created on May 30, 2013
@author: paulross
"""
import os
import pathlib
from setuptools import setup, Extension
import sysconfig
here = pathlib.Path(__file__).parent.resolve()
# Get the long description from the README file
long_description = (
(here / 'README.rst').read_text(encoding='utf-8')
+ '\n\n'
+ (here / 'INSTALL.rst').read_text(encoding='utf-8')
+ '\n\n'
+ (here / 'HISTORY.rst').read_text(encoding='utf-8')
)
licence = (here / 'LICENSE.txt').read_text(encoding='utf-8')
DEBUG = True
# Generally I write code so that if DEBUG is defined as 0 then all optimisations
# are off and asserts are enabled. Typically run times of these builds are x2 to x10
# release builds.
# If DEBUG > 0 then extra code paths are introduced such as checking the integrity of
# internal data structures. In this case the performance is by no means comparable
# with release builds.
DEBUG_LEVEL = 0
# Python stlib requirement:
LANGUAGE_STANDARD_C = "c99"
# Our level of C++
LANGUAGE_STANDARD_CPP = "c++11"
# Common flags for both release and debug builds.
# C
extra_compile_args_c = sysconfig.get_config_var('CFLAGS').split()
extra_compile_args_c += ["-std=%s" % LANGUAGE_STANDARD_C, "-Wall", "-Wextra"]
if DEBUG:
extra_compile_args_c += ["-g3", "-O0", "-DDEBUG=%s" % DEBUG_LEVEL, "-UNDEBUG"]
else:
extra_compile_args_c += ["-DNDEBUG", "-O3"]
# C++
extra_compile_args_cpp = sysconfig.get_config_var('CFLAGS').split()
extra_compile_args_cpp += ["-std=%s" % LANGUAGE_STANDARD_CPP, "-Wall", "-Wextra"]
if DEBUG:
extra_compile_args_cpp += ["-g3", "-O0", "-DDEBUG=%s" % DEBUG_LEVEL, "-UNDEBUG"]
else:
extra_compile_args_cpp += ["-DNDEBUG", "-O3"]
PYTHON_INCLUDE_DIRECTORIES = [
sysconfig.get_paths()['include'],
]
PACKAGE_NAME = 'cPyExtPatt'
# Make directory cPyExtPatt/ and sub-directories such as Capsules/
for dir_path in (os.path.join(os.path.dirname(__file__), 'cPyExtPatt'),
os.path.join(os.path.dirname(__file__), 'cPyExtPatt', 'Capsules'),
os.path.join(os.path.dirname(__file__), 'cPyExtPatt', 'cpp'),
os.path.join(os.path.dirname(__file__), 'cPyExtPatt', 'SimpleExample'),
os.path.join(os.path.dirname(__file__), 'cPyExtPatt', 'Iterators'),
os.path.join(os.path.dirname(__file__), 'cPyExtPatt', 'SubClass'),
os.path.join(os.path.dirname(__file__), 'cPyExtPatt', 'Threads'),
os.path.join(os.path.dirname(__file__), 'cPyExtPatt', 'Logging'),
):
if not os.path.exists(dir_path):
print(f'Making directory {dir_path}')
os.makedirs(dir_path)
pathlib.Path(os.path.join(dir_path, '__init__.py')).touch()
# For keywords see: https://setuptools.pypa.io/en/latest/references/keywords.html
setup(
name=PACKAGE_NAME,
version='0.2.1',
author='Paul Ross',
author_email='[email protected]',
maintainer='Paul Ross',
maintainer_email='[email protected]',
description='Python C Extension Patterns.',
long_description=long_description,
long_description_content_type='text/x-rst',
platforms=['Mac OSX', 'POSIX', ],
packages=[PACKAGE_NAME, ],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX :: Linux',
'Programming Language :: C',
'Programming Language :: C++',
'Programming Language :: Python',
'Topic :: Software Development',
'Topic :: Software Development :: Documentation',
'Topic :: Software Development :: Libraries :: Python Modules',
],
licence=licence,
# See: https://setuptools.pypa.io/en/latest/userguide/ext_modules.html
# language='c' or language='c++',
ext_modules=[
Extension(f"{PACKAGE_NAME}.cExceptions", sources=['src/cpy/cExceptions.c', ],
include_dirs=['/usr/local/include', ], # os.path.join(os.getcwd(), 'include'),],
library_dirs=[os.getcwd(), ], # path to .a or .so file(s)
extra_compile_args=extra_compile_args_c,
language='c',
),
Extension(f"{PACKAGE_NAME}.cModuleGlobals", sources=['src/cpy/cModuleGlobals.c', ],
include_dirs=['/usr/local/include', ], # os.path.join(os.getcwd(), 'include'),],
library_dirs=[os.getcwd(), ], # path to .a or .so file(s)
extra_compile_args=extra_compile_args_c,
language='c',
),
Extension(f"{PACKAGE_NAME}.cObject", sources=['src/cpy/cObject.c', ],
include_dirs=['/usr/local/include', ], # os.path.join(os.getcwd(), 'include'),],
library_dirs=[os.getcwd(), ], # path to .a or .so file(s)
extra_compile_args=extra_compile_args_c,
language='c',
),
Extension(f"{PACKAGE_NAME}.cParseArgs", sources=['src/cpy/cParseArgs.c', ],
include_dirs=['/usr/local/include', ], # os.path.join(os.getcwd(), 'include'),],
library_dirs=[os.getcwd(), ], # path to .a or .so file(s)
extra_compile_args=extra_compile_args_c,
language='c',
),
# Legacy code, see src/cpy/cParseArgsHelper.cpp for comments.
Extension(f"{PACKAGE_NAME}.cParseArgsHelper", sources=['src/cpy/cParseArgsHelper.cpp', ],
include_dirs=['/usr/local/include', ], # os.path.join(os.getcwd(), 'include'),],
library_dirs=[os.getcwd(), ], # path to .a or .so file(s)
extra_compile_args=extra_compile_args_cpp,
language='c++11',
),
Extension(f"{PACKAGE_NAME}.cPyRefs", sources=['src/cpy/cPyRefs.c', ],
include_dirs=['/usr/local/include', ], # os.path.join(os.getcwd(), 'include'),],
library_dirs=[os.getcwd(), ], # path to .a or .so file(s)
# libraries = ['jpeg',],
extra_compile_args=extra_compile_args_c,
language='c',
),
Extension(f"{PACKAGE_NAME}.cPickle", sources=['src/cpy/Pickle/cCustomPickle.c', ],
include_dirs=['/usr/local/include', ], # os.path.join(os.getcwd(), 'include'),],
library_dirs=[os.getcwd(), ], # path to .a or .so file(s)
extra_compile_args=extra_compile_args_c,
language='c',
),
Extension(f"{PACKAGE_NAME}.cFile", sources=[
'src/cpy/File/cFile.cpp',
'src/cpy/File/PythonFileWrapper.cpp',
],
include_dirs=['/usr/local/include', 'src/cpy/File', ], # os.path.join(os.getcwd(), 'include'),],
library_dirs=[os.getcwd(), ], # path to .a or .so file(s)
extra_compile_args=extra_compile_args_cpp,
language='c++11',
),
Extension(f"{PACKAGE_NAME}.Capsules.spam", sources=['src/cpy/Capsules/spam.c', ],
include_dirs=['/usr/local/include', ], # os.path.join(os.getcwd(), 'include'),],
library_dirs=[os.getcwd(), ], # path to .a or .so file(s)
extra_compile_args=extra_compile_args_c,
language='c',
),
Extension(f"{PACKAGE_NAME}.Capsules.spam_capsule", sources=['src/cpy/Capsules/spam_capsule.c', ],
include_dirs=['/usr/local/include', 'src/cpy/Capsules', ], # os.path.join(os.getcwd(), 'include'),],
library_dirs=[os.getcwd(), ], # path to .a or .so file(s)
extra_compile_args=extra_compile_args_c,
language='c',
),
Extension(f"{PACKAGE_NAME}.Capsules.spam_client", sources=['src/cpy/Capsules/spam_client.c', ],
include_dirs=['/usr/local/include', 'src/cpy/Capsules', ], # os.path.join(os.getcwd(), 'include'),],
library_dirs=[os.getcwd(), ], # path to .a or .so file(s)
extra_compile_args=extra_compile_args_c,
language='c',
),
Extension(f"{PACKAGE_NAME}.Capsules.datetimetz",
sources=[
'src/cpy/Capsules/datetimetz.c',
'src/cpy/Util/py_call_super.c',
],
include_dirs=[
'/usr/local/include',
'src/cpy/Capsules',
'src/cpy/Util',
],
library_dirs=[os.getcwd(), ],
extra_compile_args=extra_compile_args_c,
language='c',
),
Extension(f"{PACKAGE_NAME}.cpp.placement_new",
sources=['src/cpy/cpp/placement_new.cpp', ],
include_dirs=['/usr/local/include', 'src/cpy/cpp', ],
library_dirs=[os.getcwd(), ],
extra_compile_args=extra_compile_args_cpp,
language='c++11',
),
Extension(f"{PACKAGE_NAME}.cpp.cUnicode",
sources=['src/cpy/cpp/cUnicode.cpp', ],
include_dirs=['/usr/local/include', ],
library_dirs=[os.getcwd(), ],
extra_compile_args=extra_compile_args_cpp,
language='c++11',
# undef_macros=undef_macros,
),
Extension(f"{PACKAGE_NAME}.SimpleExample.cFibA",
sources=['src/cpy/SimpleExample/cFibA.c', ],
include_dirs=[],
library_dirs=[],
libraries=[],
# For best performance.
extra_compile_args=[
'-Wall', '-Wextra', '-Werror', '-Wfatal-errors', '-Wpedantic',
'-Wno-unused-function', '-Wno-unused-parameter',
'-Qunused-arguments', '-std=c99',
'-UDEBUG', '-DNDEBUG', '-Ofast', '-g',
],
language='c',
),
Extension(f"{PACKAGE_NAME}.SimpleExample.cFibB",
sources=['src/cpy/SimpleExample/cFibB.c', ],
include_dirs=[],
library_dirs=[],
libraries=[],
# For best performance.
extra_compile_args=[
'-Wall', '-Wextra', '-Werror', '-Wfatal-errors', '-Wpedantic',
'-Wno-unused-function', '-Wno-unused-parameter',
'-Qunused-arguments', '-std=c99',
'-UDEBUG', '-DNDEBUG', '-Ofast', '-g',
],
language='c',
),
# Extension(name=f"{PACKAGE_NAME}.Generators.gen_cpp",
# include_dirs=[],
# sources=["src/cpy/Generators/cGenerator.cpp", ],
# extra_compile_args=extra_compile_args_cpp,
# language='c++11',
# ),
Extension(name=f"{PACKAGE_NAME}.Iterators.cIterator",
include_dirs=[],
sources=["src/cpy/Iterators/cIterator.c", ],
extra_compile_args=extra_compile_args_c,
language='c',
),
Extension(name=f"{PACKAGE_NAME}.SubClass.sublist",
include_dirs=[
'/usr/local/include',
'src/cpy/Util',
],
sources=[
"src/cpy/SubClass/sublist.c",
'src/cpy/Util/py_call_super.c',
],
extra_compile_args=extra_compile_args_c,
language='c',
),
Extension(name=f"{PACKAGE_NAME}.Threads.csublist",
include_dirs=[
'/usr/local/include',
'src/cpy/Util',
"src/cpy/Threads",
],
sources=[
"src/cpy/Threads/csublist.c",
'src/cpy/Util/py_call_super.c',
],
extra_compile_args=extra_compile_args_c,
language='c',
),
Extension(name=f"{PACKAGE_NAME}.Threads.cppsublist",
include_dirs=[
'/usr/local/include',
'src/cpy/Util',
"src/cpy/Threads",
],
sources=[
"src/cpy/Threads/cppsublist.cpp",
'src/cpy/Util/py_call_super.c',
],
# TODO: Why does removing this work?
# extra_compile_args=extra_compile_args_cpp,
language='c++11',
),
Extension(name=f"{PACKAGE_NAME}.Logging.cLogging",
include_dirs=[],
sources=["src/cpy/Logging/cLogging.c", ],
extra_compile_args=extra_compile_args_c,
language='c',
),
Extension(f"{PACKAGE_NAME}.cRefCount",
include_dirs=['/usr/local/include', ],
sources=['src/cpy/RefCount/cRefCount.c', ],
extra_compile_args=extra_compile_args_c,
language='c',
),
]
)