-
Notifications
You must be signed in to change notification settings - Fork 109
/
check_build.py
69 lines (52 loc) · 2.27 KB
/
check_build.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
"""ML-ENSEMBLE
:author: Sebastian Flennerhag
:copyright: 2017-2018
:license: MIT
Testing suite for ML-Ensemble build.
"""
if __name__ == '__main__':
import subprocess, os, sys, sysconfig
# Check that nosetests exists
print("Setting up tests...", end=" ", flush=True)
has_nosetests = subprocess.run(["which", "nosetests"],
stdout=open(os.devnull, "wb"),
stderr=open(os.devnull, "wb"))
# If not, try to install
if has_nosetests.returncode:
print("Could not find nosetests. Installing...", end=" ", flush=True)
installation = subprocess.run(["pip", "install", "nose-exclude"],
stdout=open(os.devnull, "wb"),
stderr=open(os.devnull, "wb"))
if installation.returncode:
print("Installation successful.", end=" ", flush=True)
else:
print("Installation failed. Aborting test. "
"Ensure a valid version of "
"nosetests is installed (i.e. pip install "
"nose-exclude).")
exit()
print("Ready.", flush=True)
# Run tests
print("Checking build...", end=" ", flush=True)
nosetests = subprocess.run(["nosetests", "-s", "-v", "--with-coverage"],
stdout=open(os.devnull, "wb"),
stderr=subprocess.PIPE)
if nosetests.returncode == 0:
print("Build ok.")
else:
print("Build failed.")
print("Error log written to 'check_build_log.txt'.")
with open("check_build_log.txt", "wb") as f:
header = "-" * 22 + " Error log for testing mlens build " + "-" * 22
build_start = "-" * 34 + " Build log " + "-" * 34
python_version = "Python build: " + sys.version
os_version = "OS platform: " + sysconfig.get_platform()
try:
import mlens
mlens_version = "mlens version: " + mlens.__version__
except Exception as e:
mlens_version = "Cannot import mlens. Details:\n%r" % e
for m in [header, python_version, os_version, mlens_version,
build_start]:
f.write(bytes(m + "\n\n", "utf-8"))
f.write(nosetests.stderr)