-
Notifications
You must be signed in to change notification settings - Fork 1
/
scent.py
96 lines (68 loc) · 2.27 KB
/
scent.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
"""Configuration file for sniffer."""
import time
import subprocess
from sniffer.api import select_runnable, file_validator, runnable
try:
from pync import Notifier
except ImportError:
notify = None
else:
notify = Notifier.notify
watch_paths = ["vicon_nexus_unity_stream_py", "tests"]
class Options:
group = int(time.time()) # unique per run
show_coverage = False
rerun_args = None
targets = [
(("make", "test-unit", "DISABLE_COVERAGE=true"), "Unit Tests", True),
(("make", "test-all"), "Integration Tests", False),
(("make", "check"), "Static Analysis", True),
(("make", "docs", "CI=true"), None, True),
]
@select_runnable("run_targets")
@file_validator
def python_files(filename):
return filename.endswith(".py") and ".py." not in filename
@select_runnable("run_targets")
@file_validator
def html_files(filename):
return filename.split(".")[-1] in ["html", "css", "js"]
@runnable
def run_targets(*args):
"""Run targets for Python."""
Options.show_coverage = "coverage" in args
count = 0
for count, (command, title, retry) in enumerate(Options.targets, start=1):
success = call(command, title, retry)
if not success:
message = "✅ " * (count - 1) + "❌"
show_notification(message, title)
return False
message = "✅ " * count
title = "All Targets"
show_notification(message, title)
show_coverage()
return True
def call(command, title, retry):
"""Run a command-line program and display the result."""
if Options.rerun_args:
command, title, retry = Options.rerun_args
Options.rerun_args = None
success = call(command, title, retry)
if not success:
return False
print("")
print("$ %s" % " ".join(command))
failure = subprocess.call(command)
if failure and retry:
Options.rerun_args = command, title, retry
return not failure
def show_notification(message, title):
"""Show a user notification."""
if notify and title:
notify(message, title=title, group=Options.group)
def show_coverage():
"""Launch the coverage report."""
if Options.show_coverage:
subprocess.call(["make", "read-coverage"])
Options.show_coverage = False