Skip to content

Commit 031dcd6

Browse files
committed
Clean up run.sh.
1 parent 4676dc4 commit 031dcd6

File tree

1 file changed

+49
-70
lines changed

1 file changed

+49
-70
lines changed

run.sh

Lines changed: 49 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,28 @@
22
#
33
# usage: ./run.sh command [argument ...]
44
#
5-
# Commands used during development / CI.
6-
# Also, executable documentation for project dev practices.
5+
# Executable documentation for the development workflow.
76
#
8-
# See https://death.andgravity.com/run-sh
9-
# for an explanation of how it works and why it's useful.
7+
# See https://death.andgravity.com/run-sh for how this works.
108

119

12-
# First, set up the environment.
13-
# (Check the notes at the end when changing this.)
10+
# preamble
1411

1512
set -o nounset
1613
set -o pipefail
1714
set -o errexit
1815

19-
# Change the current directory to the project root.
2016
PROJECT_ROOT=${0%/*}
2117
if [[ $0 != $PROJECT_ROOT && $PROJECT_ROOT != "" ]]; then
2218
cd "$PROJECT_ROOT"
2319
fi
2420
readonly PROJECT_ROOT=$( pwd )
25-
26-
# Store the absolute path to this script (useful for recursion).
2721
readonly SCRIPT="$PROJECT_ROOT/$( basename "$0" )"
2822

2923

24+
# main development workflow
3025

31-
# Commands follow.
32-
33-
34-
function install-dev {
26+
function install {
3527
pip install -e '.[all]' --group dev --upgrade --upgrade-strategy eager
3628
pre-commit install --install-hooks
3729
}
@@ -40,56 +32,38 @@ function test {
4032
pytest --runslow "$@"
4133
}
4234

35+
function test-all {
36+
tox p "$@"
37+
}
38+
4339
function coverage {
4440
unset -f coverage
4541
coverage run -m pytest --runslow "$@"
4642
coverage html
4743
coverage-report
4844
}
4945

50-
function coverage-report {
51-
# library only "coverage report --fail-under 100"
52-
unset -f coverage
53-
coverage report \
54-
--omit "$(
55-
echo "
56-
*/reader/_vendor/*
57-
*/reader/__main__.py
58-
*/reader/_cli*
59-
*/reader/_config*
60-
*/reader/_app/*
61-
*/reader/_plugins/*
62-
tests/*
63-
" | xargs echo | sed 's/ /,/g'
64-
)" \
65-
--skip-covered \
66-
--show-missing \
67-
--fail-under $( on-pypy && echo 99 || echo 100 )
68-
}
69-
70-
71-
function test-all {
72-
tox p "$@"
73-
}
74-
75-
7646
function typing {
7747
mypy "$@"
7848
}
7949

80-
8150
function docs {
8251
sphinx-build -E -W docs docs/_build/html "$@"
8352
}
8453

54+
function release {
55+
python scripts/release.py "$@"
56+
}
57+
58+
59+
# "watch" versions of the main commands
8560

8661
function test-dev {
87-
clean-pyc
88-
entr-project-files -cdr pytest "$@"
62+
watch pytest "$@"
8963
}
9064

9165
function typing-dev {
92-
entr-project-files -cdr "$SCRIPT" typing "$@"
66+
watch typing "$@"
9367
}
9468

9569
function docs-dev {
@@ -98,22 +72,42 @@ function docs-dev {
9872
}
9973

10074
function serve-dev {
101-
export FLASK_DEBUG=1
102-
export FLASK_TRAP_BAD_REQUEST_ERRORS=1
103-
export FLASK_APP=src/reader/_app/wsgi.py
10475
export READER_DB=db.sqlite
105-
flask run -p 8000 "$@"
76+
flask -A reader._app.wsgi --debug run "$@"
10677
}
10778

10879

109-
function release {
110-
python scripts/release.py "$@"
80+
# low level commands
81+
82+
function coverage-report {
83+
# --fail-under only for the library, not the CLI or the web app
84+
unset -f coverage
85+
coverage report \
86+
--omit "$(
87+
echo "
88+
*/reader/_vendor/*
89+
*/reader/__main__.py
90+
*/reader/_cli*
91+
*/reader/_config*
92+
*/reader/_app/*
93+
*/reader/_plugins/*
94+
tests/*
95+
" | xargs echo | sed 's/ /,/g'
96+
)" \
97+
--skip-covered \
98+
--show-missing \
99+
--fail-under $( on-pypy && echo 99 || echo 100 )
111100
}
112101

113102

114-
function ls-project-files {
115-
git ls-files "$@"
116-
git ls-files --exclude-standard --others "$@"
103+
# utilities
104+
105+
function on-pypy {
106+
[[ $( python -c 'import sys; print(sys.implementation.name)' ) == pypy ]]
107+
}
108+
109+
function watch {
110+
entr-project-files -cdr "$SCRIPT" "$@"
117111
}
118112

119113
function entr-project-files {
@@ -126,25 +120,10 @@ function entr-project-files {
126120
done
127121
}
128122

129-
130-
function on-pypy {
131-
[[ $( python -c 'import sys; print(sys.implementation.name)' ) == pypy ]]
123+
function ls-project-files {
124+
git ls-files "$@"
125+
git ls-files --exclude-standard --others "$@"
132126
}
133127

134128

135-
136-
# Commands end. Dispatch to command.
137-
138129
"$@"
139-
140-
141-
142-
# Some dev notes for this script.
143-
#
144-
# The commands *require*:
145-
#
146-
# * The current working directory is the project root.
147-
# * The shell options and globals are set as they are.
148-
#
149-
# Inspired by http://www.oilshell.org/blog/2020/02/good-parts-sketch.html
150-
#

0 commit comments

Comments
 (0)