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