forked from lemon24/reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·188 lines (140 loc) · 3.76 KB
/
run.sh
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
#!/bin/bash
#
# usage: ./run.sh command [argument ...]
#
# Commands used during development / CI.
# Also, executable documentation for project dev practices.
#
# See https://death.andgravity.com/run-sh
# for an explanation of how it works and why it's useful.
# First, set up the environment.
# (Check the notes at the end when changing this.)
set -o nounset
set -o pipefail
set -o errexit
# Change the current directory to the project root.
PROJECT_ROOT=${0%/*}
if [[ $0 != $PROJECT_ROOT && $PROJECT_ROOT != "" ]]; then
cd "$PROJECT_ROOT"
fi
readonly PROJECT_ROOT=$( pwd )
# Store the absolute path to this script (useful for recursion).
readonly SCRIPT="$PROJECT_ROOT/$( basename "$0" )"
# Commands follow.
function install-dev {
pip install -e '.[dev]' --upgrade --upgrade-strategy=eager
pre-commit install --install-hooks
}
function test {
pytest --runslow "$@"
}
function coverage-all {
clean-pyc
# TODO: do we need to --cov-context=test all the time?
coverage-run --cov-context=test "$@"
coverage-report --show-contexts
}
function coverage-run {
# TODO: is pytest-cov needed?
pytest --runslow --cov "$@"
}
function coverage-report {
coverage html "$@"
coverage report \
--include '*/reader/*' \
--omit "$(
echo "
*/reader/_vendor/*
*/reader/__main__.py
*/reader/_cli*
*/reader/_config*
*/reader/_app/*
*/reader/_plugins/*
tests/*
" | xargs echo | sed 's/ /,/g'
)" \
--skip-covered \
--show-missing \
--fail-under $( on-pypy && echo 99 || echo 100 )
}
function test-all {
tox -p
}
function typing {
if on-pypy; then
# mypy does not work on pypy as of January 2020
# https://github.com/python/typed_ast/issues/97#issuecomment-484335190
echo "mypy does not work on pypy, doing nothing"
return
fi
mypy --strict --show-error-codes src "$@"
mkdir -p build
local import_all=build/import_all.py
python scripts/generate_import_all.py > "$import_all" \
&& mypy --strict --show-error-codes "$import_all" "$@" \
&& rm "$import_all"
}
function docs {
make -C docs html SPHINXOPTS="-W" "$@"
}
function test-dev {
clean-pyc
entr-project-files -cdr pytest "$@"
}
function typing-dev {
entr-project-files -cdr "$SCRIPT" typing "$@"
}
function docs-dev {
make -C docs clean
entr-project-files -cdr "$SCRIPT" docs "$@"
}
function serve-dev {
export FLASK_DEBUG=1
export FLASK_TRAP_BAD_REQUEST_ERRORS=1
export FLASK_APP=src/reader/_app/wsgi.py
export READER_DB=db.sqlite
flask run -p 8000 "$@"
}
function release {
python scripts/release.py "$@"
}
function ls-project-files {
git ls-files "$@"
git ls-files --exclude-standard --others "$@"
}
function entr-project-files {
set +o errexit
while true; do
ls-project-files | entr "$@"
if [[ $? -eq 0 ]]; then
break
fi
done
}
function clean-pyc {
local IFS=$'\n'
find \
$( ls-project-files | grep / | cut -d/ -f1 | uniq ) \
-name '*.pyc' -or -name '*.pyo' \
-exec rm -rf {} +
}
function ci-install {
pip install -e '.[cli,app,tests,docs,unstable-plugins]'
}
function ci-run {
coverage-run -v && coverage-report && typing
}
function on-pypy {
[[ $( python -c 'import sys; print(sys.implementation.name)' ) == pypy ]]
}
# Commands end. Dispatch to command.
"$@"
# Some dev notes for this script.
#
# The commands *require*:
#
# * The current working directory is the project root.
# * The shell options and globals are set as they are.
#
# Inspired by http://www.oilshell.org/blog/2020/02/good-parts-sketch.html
#