-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscripts.py
More file actions
executable file
·76 lines (63 loc) · 1.89 KB
/
scripts.py
File metadata and controls
executable file
·76 lines (63 loc) · 1.89 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
#!/usr/bin/env python3
"""
Simple functions to run black, pytest, etc.
"""
import os
import subprocess
import click
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
COMMANDS = ["test", "black", "black:fix", "all"]
@click.group(help="Utility scripts for conservator-cli")
@click.pass_context
def cli(ctx):
"""
Entrypoint function
"""
ctx.ensure_object(dict)
@cli.command("test", help="Run conservator-cli unit tests")
def test() -> None:
"""
Run unit tests only
"""
test_result = subprocess.call(["pytest", os.path.join(BASE_DIR, "test", "unit")])
if test_result == 0:
click.secho("Unit tests passed", fg="green", bold=True)
else:
click.secho("Unit tests failed", fg="red", bold=True)
return test_result
@cli.command("black", help="Run black check")
def black() -> None:
"""
Run Black (check only)
"""
black_result = subprocess.call(["black", "--check", BASE_DIR])
if black_result == 0:
click.secho("Black check passed", fg="green", bold=True)
else:
click.secho("Black check failed", fg="red", bold=True)
return black_result
@cli.command("black:fix", help="Run black and fix any formatting issues")
def black_fix() -> None:
"""
Run Black and fix any issues
"""
black_fix_result = subprocess.call(["black", BASE_DIR])
if black_fix_result == 0:
click.secho("Black:fix succeeded", fg="green", bold=True)
else:
click.secho("Black:fix failed", fg="red", bold=True)
return black_fix_result
@cli.command("all", help="Check formatting and run unit tests")
@click.pass_context
def run_all(ctx) -> None:
"""
Run Black (check only) and unit tests
"""
black_result = ctx.invoke(black)
if black_result > 0:
ctx.exit(black_result)
test_result = ctx.invoke(test)
if test_result > 0:
ctx.exit(test_result)
if __name__ == "__main__":
cli()