-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup.py
241 lines (191 loc) · 7.84 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
__author__ = 'sergey'
import os
import sys
import subprocess
from distutils.core import setup
from distutils.extension import Extension
CYTHON_BUILD = 0
if "--cython-build" in sys.argv:
# Support compiling with Cython
CYTHON_BUILD = 1
sys.argv.remove("--cython-build")
from Cython.Distutils import build_ext
from Cython.Build import cythonize
else:
from distutils.command.build_ext import build_ext
args = sys.argv[1:]
def scandir(dir, files=[]):
"""
scan the 'dvedit' directory for extension files, converting
them to extension names in dotted notation
@param dir:
@param files:
@return:
"""
d = os.path.dirname(dir)
if d == "tests":
return files
for file in os.listdir(dir):
path = os.path.join(dir, file)
if os.path.isfile(path) and path.endswith(".py") and path.find("__.py") == -1 and path.find('migrations') == -1:
files.append(path.replace(os.path.sep, ".")[:-3])
elif os.path.isdir(path):
scandir(path, files)
return files
# generate an Extension object from its dotted name
def makeExtension(extName):
extPath = extName.replace(".", os.path.sep)+".py"
return Extension(extName, [extPath])
def makeExtensionLib(extName):
extPath = extName.replace(".", os.path.sep)+".py"
extName = extName.replace('lib-dynload.', '')
return Extension(extName, [extPath])
def cleanAllExtension(extName):
if os.path.isfile(extName):
extDir = os.path.dirname(extName)
else:
extName = 'lib-dynload/' + extName
if os.path.isfile(extName):
extDir = os.path.dirname(extName)
else:
return
oldPath = os.getcwd()
os.chdir(extDir)
# Just in case the build directory was created by accident,
# note that shell=True should be OK here because the command is constant.
subprocess.Popen("rm -rvf __pycache__", shell=True, executable="/bin/sh")
subprocess.Popen("rm -rvf build", shell=True, executable="/bin/sh")
subprocess.Popen("rm -rvf *.c", shell=True, executable="/bin/sh")
subprocess.Popen("rm -rvf *.so", shell=True, executable="/bin/sh")
os.chdir(oldPath)
def cleanBuildExtension(extName):
if os.path.isfile(extName):
extDir = os.path.dirname(extName)
else:
extName = 'lib-dynload/' + extName
if os.path.isfile(extName):
extDir = os.path.dirname(extName)
else:
return
oldPath = os.getcwd()
os.chdir(extDir)
# Just in case the build directory was created by accident,
# note that shell=True should be OK here because the command is constant.
subprocess.Popen("rm -rvf __pycache__", shell=True, executable="/bin/sh")
subprocess.Popen("rm -rvf build", shell=True, executable="/bin/sh")
subprocess.Popen("rm -rvf *.c", shell=True, executable="/bin/sh")
os.chdir(oldPath)
def cleanPyExtension(extName):
if os.path.isfile(extName):
extDir = os.path.dirname(extName)
else:
extName = 'lib-dynload/' + extName
if os.path.isfile(extName):
extDir = os.path.dirname(extName)
else:
return
oldPath = os.getcwd()
os.chdir(extDir)
# Just in case the build directory was created by accident,
# note that shell=True should be OK here because the command is constant.
subprocess.Popen("rm -rvf __pycache__", shell=True, executable="/bin/sh")
subprocess.Popen("rm -rvf build", shell=True, executable="/bin/sh")
subprocess.Popen("rm -rvf *.c", shell=True, executable="/bin/sh")
os.chdir(oldPath)
if os.path.isfile(extName):
subprocess.Popen("rm -rvf '%s'" % extName, shell=True, executable="/bin/sh")
def stripExtension(extName):
if not os.path.isfile(extName):
extName = 'lib-dynload/' + extName
if not os.path.isfile(extName):
return
subprocess.Popen("strip -sv " + extName, shell=True, executable="/bin/sh")
# get the list of extensions
extNamesD = []
scandir("dedupsqlfs", extNamesD)
extNamesL = []
scandir("lib-dynload/_pymysql", extNamesL)
extNames = []
extNames.extend(extNamesD)
extNames.extend(extNamesL)
# Make a `cleanall` rule to get rid of intermediate and library files
if "cleanall" in args:
print("Deleting cython files...")
for n in extNames:
cleanAllExtension(n.replace(".", os.path.sep) + ".py")
subprocess.Popen("rm -rvf build _pymysql", shell=True, executable="/bin/sh")
subprocess.Popen("find lib-dynload/_pymysql -type f -iname '*.c' -exec rm -vf '{}' \;", shell=True, executable="/bin/sh")
subprocess.Popen("find lib-dynload/_pymysql -type f -iname '*.so' -exec rm -vf '{}' \;", shell=True, executable="/bin/sh")
sys.exit(0)
# Make a `cleanpy` rule to get rid of old raw python files
if "cleanpy" in args:
print("Deleting python files...")
for n in extNames:
cleanPyExtension(n.replace(".", os.path.sep) + ".py")
subprocess.Popen("rm -rvf build _pymysql", shell=True, executable="/bin/sh")
subprocess.Popen("find lib-dynload/_pymysql -type f -iname '*.c' -exec rm -vf '{}' \;", shell=True, executable="/bin/sh")
subprocess.Popen("find lib-dynload/_pymysql -type f -iname '*.py' -exec rm -vf '{}' \;", shell=True, executable="/bin/sh")
sys.exit(0)
# Make a `cleanbuild` rule to get rid of cython build artefacts
if "cleanbuild" in args:
print("Deleting cython build files...")
for n in extNames:
cleanBuildExtension(n.replace(".", os.path.sep) + ".py")
subprocess.Popen("rm -rvf build _pymysql", shell=True, executable="/bin/sh")
subprocess.Popen("find lib-dynload/_pymysql -type f -iname '*.c' -exec rm -vf '{}' \;", shell=True, executable="/bin/sh")
sys.exit(0)
# Make a `stripall` rule to get rid of old raw python files
if "stripall" in args:
print("Strip debug from cython files...")
for n in extNames:
stripExtension(n.replace(".", os.path.sep) + "*.so")
subprocess.Popen("find lib-dynload/_pymysql -type f -iname '*.so' -exec strip -vs '{}' \;", shell=True, executable="/bin/sh")
sys.exit(0)
# We want to always use build_ext --inplace
if args.count("build_ext") > 0 and args.count("--inplace") == 0:
sys.argv.insert(sys.argv.index("build_ext")+1, "--inplace")
classifiers=[
'License :: OSI Approved :: MIT License',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Development Status :: 4 - Beta',
'Operating System :: POSIX',
'Programming Language :: C',
'Programming Language :: C++',
'Programming Language :: Python',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
]
# and build up the set of Extension objects
if CYTHON_BUILD:
dynloaddir = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "lib-dynload"))
sys.path.insert(0, dynloaddir)
extensions = []
extensions.extend([makeExtension(name) for name in extNamesD])
extensions.extend([makeExtensionLib(name) for name in extNamesL])
setup(
ext_modules = cythonize(extensions, language_level=3),
name="dedupsqlfs",
version="1.2.953-dev",
packages=["dedupsqlfs",],
cmdclass = {'build_ext': build_ext}, requires=['llfuse'],
classifiers=classifiers
)
subprocess.Popen("cp -vfr _pymysql lib-dynload/", shell=True, executable="/bin/sh")
subprocess.Popen("rm -vfr _pymysql", shell=True, executable="/bin/sh")
else:
extensions = [makeExtension(name) for name in extNamesD]
setup(
ext_modules = extensions,
name="dedupsqlfs",
version="1.2.953-dev",
packages=["dedupsqlfs",],
cmdclass = {'build_ext': build_ext}, requires=['llfuse'],
classifiers=classifiers
)