scent   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 63
dl 0
loc 98
rs 10
c 0
b 0
f 0
wmc 15

6 Functions

Rating   Name   Duplication   Size   Complexity  
A html_files() 0 4 1
A call() 0 17 5
A show_coverage() 0 6 2
A run_targets() 0 21 3
A show_notification() 0 4 3
A python_files() 0 4 1
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 = ["gitman", "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'), 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 html_files(filename):
41
    return filename.split('.')[-1] in ['html', 'css', 'js']
42
43
44
@runnable
45
def run_targets(*args):
46
    """Run targets for Python."""
47
    Options.show_coverage = 'coverage' in args
48
49
    count = 0
50
    for count, (command, title, retry) in enumerate(Options.targets, start=1):
51
52
        success = call(command, title, retry)
53
        if not success:
54
            message = "✅ " * (count - 1) + "❌"
55
            show_notification(message, title)
56
57
            return False
58
59
    message = "✅ " * count
60
    title = "All Targets"
61
    show_notification(message, title)
62
    show_coverage()
63
64
    return True
65
66
67
def call(command, title, retry):
68
    """Run a command-line program and display the result."""
69
    if Options.rerun_args:
70
        command, title, retry = Options.rerun_args
71
        Options.rerun_args = None
72
        success = call(command, title, retry)
73
        if not success:
74
            return False
75
76
    print("")
77
    print("$ %s" % ' '.join(command))
78
    failure = subprocess.call(command)
79
80
    if failure and retry:
81
        Options.rerun_args = command, title, retry
82
83
    return not failure
84
85
86
def show_notification(message, title):
87
    """Show a user notification."""
88
    if notify and title:
89
        notify(message, title=title, group=Options.group)
90
91
92
def show_coverage():
93
    """Launch the coverage report."""
94
    if Options.show_coverage:
95
        subprocess.call(['make', 'read-coverage'])
96
97
    Options.show_coverage = False
98