-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py.old
executable file
·171 lines (124 loc) · 4.14 KB
/
setup.py.old
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
#!/usr/bin/env python3
from setuptools import find_packages, setup
from setuptools.extension import Extension
from Cython.Build import cythonize
import os, sys, time
import threading
import itertools
import shutil
def spin(msg, done):
write, flush = sys.stdout.write, sys.stdout.flush
for char in itertools.cycle('|/-\\'):
status = char + ' ' + msg
write(status)
flush()
write('\x08' * len(status))
if done.wait(.1):
break
write(' ' * len(status) + '\x08' * len(status))
class HiddenPrints:
def __enter__(self):
self._original_stdout = sys.stdout
sys.stdout = open(os.devnull, 'w')
def __exit__(self, exc_type, exc_val, exc_tb):
sys.stdout.close()
sys.stdout = self._original_stdout
if "setup" in sys.argv:
pass
else:
os.chdir("libs/")
i = 0
dir_name = "."
test = os.listdir(dir_name)
for item in test:
if item.endswith(".so"):
print(f"[{i}] Deleting{os.path.join(dir_name, item)}")
try:
os.remove(os.path.join(dir_name, item))
except:
print(f"[!] Failed to delete {os.path.join(dir_name, item)}")
i = i+1
for item in test:
if item.endswith(".dll"):
print(f"[{i}] Deleting {os.path.join(dir_name, item)}")
try:
os.remove(os.path.join(dir_name, item))
except:
print(f"[!] Failed to delete {os.path.join(dir_name, item)}")
i = i+1
cython = "*.py"
print("Going to compile:")
for item in test:
if item.endswith(".py"):
print(f"{os.path.join(dir_name, item)}")
print("../lemon/lemon.py")
done = threading.Event()
spinner = threading.Thread(target=spin,
args=('Compiling! This may take a couple of minutes.', done))
spinner.start()
with HiddenPrints():
setup(
ext_modules=cythonize(cython),
script_args = ['build_ext',"--inplace"],
)
test = os.listdir(dir_name)
for item in test:
if item.endswith(".c"):
print(f"[{i}] Deleting {os.path.join(dir_name, item)}")
try:
os.remove(os.path.join(dir_name, item))
except:
print(f"[!] Failed to delete {os.path.join(dir_name, item)}")
i = i+1
try:
shutil.rmtree("build")
except OSError as e:
print("[!] Failed to delete build directory")
try:
shutil.rmtree("__pycache__")
except OSError as e:
print("[!] Failed to delete __pycache__ directory")
os.chdir("../lemon/")
i = 0
dir_name = "."
test = os.listdir(dir_name)
for item in test:
if item.endswith(".so"):
print(f"[{i}] Deleting {os.path.join(dir_name, item)}")
try:
os.remove(os.path.join(dir_name, item))
except:
print(f"[!] Failed to delete {os.path.join(dir_name, item)}")
i = i+1
for item in test:
if item.endswith(".dll"):
print(f"[{i}] Deleting {os.path.join(dir_name, item)}")
try:
os.remove(os.path.join(dir_name, item))
except:
print(f"[!] Failed to delete {os.path.join(dir_name, item)}")
i = i+1
with HiddenPrints():
setup(
ext_modules=cythonize("lemon.py"),
script_args = ['build_ext',"--inplace"],
)
done.set()
spinner.join()
test = os.listdir(dir_name)
for item in test:
if item.endswith(".c"):
print(f"[{i}] Deleting{os.path.join(dir_name, item)}")
try:
os.remove(os.path.join(dir_name, item))
except:
print(f"[!] Failed to delete {os.path.join(dir_name, item)}")
i = i+1
try:
shutil.rmtree("build")
except OSError as e:
print("[!] Failed to delete build directory")
try:
shutil.rmtree("__pycache__")
except OSError as e:
print("[!] Failed to delete __pycache__ directory")