-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
151 lines (125 loc) · 2.88 KB
/
manage.py
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/sh
import sys
import subprocess
import argparse
def get_arguments():
parser = argparse.ArgumentParser()
parser.add_argument(
"-i",
"--install",
action="store_true",
help="Install all dependencies"
)
parser.add_argument(
"-c",
"--commitlint",
action="store_true",
help="Lint commit message"
)
parser.add_argument(
"-l",
"--lint",
action="store_true",
help="Lint Python files"
)
parser.add_argument(
"-d",
"--dockerlint",
action="store_true",
help="Lint Docker file"
)
parser.add_argument(
"-f",
"--format",
action="store_true",
help="Format Python files"
)
parser.add_argument(
"-t",
"--test",
action="store_true",
help="Run Python unit tests"
)
parser.add_argument(
"-p",
"--prettier",
action="store_true",
help="Run Prettier against JSON and MD files"
)
if not len(sys.argv) > 1:
argparse.error(
"[-] Please specify arguments, use --help for more info.")
return parser.parse_args()
class MissingDependiesError(Exception):
pass
def preinstall():
exit_code = subprocess.call(
"python3 --version && \
node --version && \
yarn --version && \
pip3 --version && \
docker --version",
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
shell=True
)
if exit_code != 0:
raise MissingDependiesError("Missing dependencies")
def install():
preinstall()
subprocess.call(
"pip3 install -r requirements.txt && \
docker pull hadolint/hadolint && \
yarn",
shell=True
)
def lint():
subprocess.call(
"find . -type f -name '*.py' | xargs pylint",
shell=True
)
def dockerlint():
subprocess.call(
"docker run --rm -i \
-v $PWD/hadolint.yaml:/root/.config/hadolint.yaml \
hadolint/hadolint < Dockerfile",
shell=True
)
def format_py():
subprocess.call(
"autopep8 --in-place --recursive .",
shell=True
)
def prettier():
subprocess.call(
"yarn prettier --write '**/*.{json,md}'",
shell=True
)
def commitlint():
subprocess.call(
"yarn commitlint --edit",
shell=True
)
def test():
subprocess.call(
"python3 -m unittest",
shell=True
)
def cli():
options = get_arguments()
if options.install:
install()
if options.lint:
lint()
if options.dockerlint:
dockerlint()
if options.format:
format_py()
if options.prettier:
prettier()
if options.commitlint:
commitlint()
if options.test:
test()
if __name__ == '__main__':
cli()