-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscent.py
More file actions
120 lines (89 loc) · 2.88 KB
/
scent.py
File metadata and controls
120 lines (89 loc) · 2.88 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""Configuration file for sniffer."""
import time
import subprocess
import os
from sniffer.api import select_runnable, file_validator, runnable
try:
from pync import Notifier
except ImportError:
notify = None
else:
notify = Notifier.notify
# Watch all relevant directories including subdirectories
watch_paths = [
"instill",
"tests",
"instill/helpers",
"instill/helpers/commands",
"instill/clients",
"instill/resources",
"instill/utils"
]
class Options:
group = int(time.time()) # unique per run
show_coverage = False
rerun_args = (None, None, None)
targets = [
(("make", "test"), "Unit Tests", True),
(("make", "check"), "Static Analysis", True),
(("make", "docs", "CI=true"), None, True),
]
@select_runnable("run_targets")
@file_validator
def python_files(filename):
"""Check if file is a Python file and should trigger tests."""
# Ignore cache files and temporary files
if any(part in filename for part in ["__pycache__", ".pyc", ".pyo", ".pyd", ".py."]):
return False
# Only watch Python files in our project directories
if not filename.endswith(".py"):
return False
# Check if file is in one of our watched paths
for path in watch_paths:
if filename.startswith(path):
return True
return False
@select_runnable("run_targets")
@file_validator
def html_files(filename):
"""Check if file is an HTML/CSS/JS file for docs."""
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[0] is not None:
command, title, retry = Options.rerun_args
Options.rerun_args = (None, None, None)
success = call(command, title, retry)
if not success:
return False
print("")
print(f"$ {' '.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