1
|
|
|
"""Configuration file for sniffer.""" |
2
|
|
|
|
3
|
|
|
import time |
4
|
|
|
import subprocess |
5
|
|
|
|
6
|
|
|
from sniffer.api import select_runnable, file_validator, runnable |
7
|
|
|
|
8
|
|
|
try: |
9
|
|
|
from pync import Notifier |
10
|
|
|
except ImportError: |
11
|
|
|
notify = None |
12
|
|
|
else: |
13
|
|
|
notify = Notifier.notify |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
watch_paths = ["slackoff", "tests"] |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
class Options: |
20
|
|
|
group = int(time.time()) # unique per run |
21
|
|
|
show_coverage = False |
22
|
|
|
rerun_args = None |
23
|
|
|
|
24
|
|
|
targets = [ |
25
|
|
|
(("make", "test-unit", "DISABLE_COVERAGE=true"), "Unit Tests", True), |
26
|
|
|
(("make", "test-all"), "Integration Tests", False), |
27
|
|
|
(("make", "check"), "Static Analysis", True), |
28
|
|
|
(("make", "docs", "CI=true"), None, True), |
29
|
|
|
] |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
@select_runnable("run_targets") |
33
|
|
|
@file_validator |
34
|
|
|
def python_files(filename): |
35
|
|
|
return filename.endswith(".py") and ".py." not in filename |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
@select_runnable("run_targets") |
39
|
|
|
@file_validator |
40
|
|
|
def applescript_files(filename): |
41
|
|
|
return filename.endswith(".applescript") |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
@select_runnable("run_targets") |
45
|
|
|
@file_validator |
46
|
|
|
def html_files(filename): |
47
|
|
|
return filename.split(".")[-1] in ["html", "css", "js"] |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
@runnable |
51
|
|
|
def run_targets(*args): |
52
|
|
|
"""Run targets for Python.""" |
53
|
|
|
Options.show_coverage = "coverage" in args |
54
|
|
|
|
55
|
|
|
count = 0 |
56
|
|
|
for count, (command, title, retry) in enumerate(Options.targets, start=1): |
57
|
|
|
|
58
|
|
|
success = call(command, title, retry) |
59
|
|
|
if not success: |
60
|
|
|
message = "✅ " * (count - 1) + "❌" |
61
|
|
|
show_notification(message, title) |
62
|
|
|
|
63
|
|
|
return False |
64
|
|
|
|
65
|
|
|
message = "✅ " * count |
66
|
|
|
title = "All Targets" |
67
|
|
|
show_notification(message, title) |
68
|
|
|
show_coverage() |
69
|
|
|
|
70
|
|
|
return True |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
def call(command, title, retry): |
74
|
|
|
"""Run a command-line program and display the result.""" |
75
|
|
|
if Options.rerun_args: |
76
|
|
|
command, title, retry = Options.rerun_args |
77
|
|
|
Options.rerun_args = None |
78
|
|
|
success = call(command, title, retry) |
79
|
|
|
if not success: |
80
|
|
|
return False |
81
|
|
|
|
82
|
|
|
print("") |
83
|
|
|
print("$ %s" % " ".join(command)) |
84
|
|
|
failure = subprocess.call(command) |
85
|
|
|
|
86
|
|
|
if failure and retry: |
87
|
|
|
Options.rerun_args = command, title, retry |
88
|
|
|
|
89
|
|
|
return not failure |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
def show_notification(message, title): |
93
|
|
|
"""Show a user notification.""" |
94
|
|
|
if notify and title: |
95
|
|
|
notify(message, title=title, group=Options.group) |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
def show_coverage(): |
99
|
|
|
"""Launch the coverage report.""" |
100
|
|
|
if Options.show_coverage: |
101
|
|
|
subprocess.call(["make", "read-coverage"]) |
102
|
|
|
|
103
|
|
|
Options.show_coverage = False |
104
|
|
|
|