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