-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_compile_all_cython.py
87 lines (56 loc) · 2.39 KB
/
run_compile_all_cython.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 30/03/2019
@author: Maurizio Ferrari Dacrema
"""
import sys, glob, traceback, os
from CythonCompiler.run_compile_subprocess import run_compile_subprocess
if __name__ == '__main__':
# cython_file_list = glob.glob('**/*.pyx', recursive=True)
subfolder_to_compile_list = [
"Recommenders/MatrixFactorization",
"Recommenders/Similarity",
"Recommenders/SLIM",
"Recommenders/FeatureWeighting",
]
cython_file_list = []
for subfolder_to_compile in subfolder_to_compile_list:
cython_file_list.extend(glob.glob('{}/Cython/*.pyx'.format(subfolder_to_compile), recursive=True))
print("run_compile_all_cython: Found {} Cython files in {} folders...".format(len(cython_file_list), len(subfolder_to_compile_list)))
print("run_compile_all_cython: All files will be compiled using your current python environment: '{}'".format(sys.executable))
save_folder_path = "./result_experiments/"
log_file_path = save_folder_path + "run_compile_all_cython.txt"
# If directory does not exist, create
if not os.path.exists(save_folder_path):
os.makedirs(save_folder_path)
log_file = open(log_file_path, "w")
fail_count = 0
for file_index, file_path in enumerate(cython_file_list):
file_path = file_path.replace("\\", "/").split("/")
file_name = file_path[-1]
file_path = "/".join(file_path[:-1]) + "/"
log_string = "Compiling [{}/{}]: {}... ".format(file_index+1, len(cython_file_list), file_name)
print(log_string)
try:
run_compile_subprocess(file_path, [file_name])
log_string += "PASS\n"
print(log_string)
log_file.write(log_string)
log_file.flush()
except Exception as exc:
traceback.print_exc()
fail_count += 1
log_string += "FAIL: {}\n".format(str(exc))
print(log_string)
log_file.write(log_string)
log_file.flush()
log_string = "run_compile_all_cython: Compilation finished. "
if fail_count != 0:
log_string += "FAILS {}/{}.".format(fail_count, len(cython_file_list))
else:
log_string += "SUCCESS."
log_string += "\nCompilation log can be found here: '{}'".format(log_file_path)
print(log_string)
log_file.write(log_string)
log_file.close()