-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·240 lines (197 loc) · 5.5 KB
/
run
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/env bash
set -o errexit
set -o pipefail
DC="${DC:-exec}"
# If we're running in CI we need to disable TTY allocation for docker compose
# commands that enable it by default, such as exec and run.
TTY=""
if [[ ! -t 1 ]]; then
TTY="-T"
fi
# -----------------------------------------------------------------------------
# Helper functions start with _ and aren't listed in this script's help menu.
# -----------------------------------------------------------------------------
function _dc {
docker compose "${DC}" ${TTY} "${@}"
}
function _build_run_down {
docker compose build
docker compose run ${TTY} "${@}"
docker compose down
}
# -----------------------------------------------------------------------------
function build:dev {
# Build & run container with dev/testing dependencies
docker compose build --build-arg "ENV=DEV" && docker compose up
}
function build:prod {
# Build & run container with no dev/testing dependencies
docker compose build --build-arg "ENV=PROD" && docker compose up
}
function cmd {
# Run any command you want in the web container
_dc web "${@}"
}
function cov:test {
# Run pytest
# cmd coverage run -m pytest "${@}"
coverage run -m pytest "${@}"
}
function cov:test-slow {
# Run pytest & show 10 slowest tests
# cmd coverage run -m pytest "${@}" --durations 10
coverage run -m pytest "${@}" --durations 10
}
function cov:report {
# Generate coverage report to terminal
# cmd coverage report "${@}"
coverage report "${@}"
}
function cov:html {
# Output coverage report to ./htmlcov
# cmd coverage html "${@}"
# cmd coverage html "${@}"
coverage html "${@}"
}
function down {
# Shut down container
docker compose down
}
function manage {
# Run any manage.py commands
# We need to collectstatic before we run our tests.
if [ "${1-''}" == "test" ]; then
# cmd python3 manage.py collectstatic --no-input
python3 manage.py collectstatic --no-input
fi
# cmd python3 manage.py "${@}"
python3 manage.py "${@}"
}
function nox:cov {
# Check code for test coverage
# cmd nox -s coverage-3.12 "${@}"
nox -s coverage-3.12 "${@}"
}
function nox:docs {
# Create Sphinx documentation in ./docs/_build directory
# cmd nox -s docs-3.12 "${@}"
nox -s docs-3.12 "${@}"
}
function nox:lint {
# Run a number of ruff linting tests
# cmd nox -s lint-3.12 "${@}"
nox -s lint-3.12 "${@}"
}
function nox:pyright {
# Run pyright typing checks
# cmd nox -s pyright-3.12 "${@}"
nox -s pyright-3.12 "${@}"
}
function nox:safety {
# Check code/packages for vulnerabilites against Safety db
# cmd nox -s safety-3.12 "${@}"
nox -s safety-3.12 "${@}"
}
function nox:test {
# Run several pytest and coverage checks
# cmd nox -s tests-3.12 "${@}"
nox -s tests-3.12 "${@}"
}
function nox:all {
# Perform all nox code quality tests together
# cmd nox -s lint-3.12 "${@}"
# cmd nox -s coverage-3.12 "${@}"
# cmd nox -s pyright-3.12 "${@}"
# cmd nox -s safety-3.12 "${@}"
# cmd nox -s tests-3.12 "${@}"
# nox -s lint-3.12 "${@}"
# nox -s coverage-3.12 "${@}"
# nox -s pyright-3.12 "${@}"
# nox -s safety-3.12 "${@}"
# nox -s tests-3.12 "${@}"
nox
}
function nox:re-all {
# Perform all nox code quality tests together
# cmd nox -rs lint-3.12 "${@}"
# cmd nox -rs coverage-3.12 "${@}"
# cmd nox -rs pyright-3.12 "${@}"
# cmd nox -rs safety-3.12 "${@}"
# cmd nox -rs tests-3.12 "${@}"
# nox -rs lint-3.12 "${@}"
# nox -rs coverage-3.12 "${@}"
# nox -rs pyright-3.12 "${@}"
# nox -rs safety-3.12 "${@}"
# nox -rs tests-3.12 "${@}"
nox -rs
}
function poe:old {
# List any installed packages that are outdated
poetry show -ol
# The following command runs twice as fast; but, requires the container
# to be running:
# cmd poetry show -ol
}
function poe:up {
# Update any outdated packages
poetry update
}
function reqs:dev {
# Export all package requirements
poetry export --with=dev --output requirements-dev.txt
}
function reqs:prod {
# Export production package requirements
poetry export --output requirements.txt
}
function reqs:all {
# Export production package requirements
poetry export --output requirements.txt
poetry export --with=dev --output requirements-dev.txt
}
function ruff:check {
# check for linting errors. Do not fix.
ruff check .
}
function ruff:fix {
# check for linting errors and apply fixes.
ruff check --fix .
}
function secret {
# Generate a random secret that can be used for your SECRET_KEY and more
# cmd python3 -c 'import secrets; print(secrets.token_urlsafe(38))'
python3 -c 'import secrets; print(secrets.token_urlsafe(38))'
}
function sh {
# Start a shell session in the web container
# cmd bash "${@}"
python manage.py shell
}
function sh+ {
# Start a shell_plus IPython session in the web container
# auto-import all models, and the datetime module
# cmd python manage.py shell_plus "${@}"
python manage.py shell_plus
}
function start {
# Start development web server
# cmd bash "${@}"
python manage.py runserver
}
function start+ {
# Start development web server with HTTPS
# cmd bash "${@}"
python manage.py runserver_plus --cert-file cert.crt
}
function up {
# Start docker container
docker compose up
}
function help {
printf "%s <task> [args]\n\nTasks:\n" "${0}"
compgen -A function | grep -v "^_" | cat -n
printf "\nExtended help:\n Each task has comments for general usage\n"
}
# This idea is heavily inspired by: https://github.com/adriancooney/Taskfile
TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"