2
2
#
3
3
# usage: ./run.sh command [argument ...]
4
4
#
5
- # Commands used during development / CI.
6
- # Also, executable documentation for project dev practices.
5
+ # Executable documentation for the development workflow.
7
6
#
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.
10
8
11
9
12
- # First, set up the environment.
13
- # (Check the notes at the end when changing this.)
10
+ # preamble
14
11
15
12
set -o nounset
16
13
set -o pipefail
17
14
set -o errexit
18
15
19
- # Change the current directory to the project root.
20
16
PROJECT_ROOT=${0%/* }
21
17
if [[ $0 != $PROJECT_ROOT && $PROJECT_ROOT != " " ]]; then
22
18
cd " $PROJECT_ROOT "
23
19
fi
24
20
readonly PROJECT_ROOT=$( pwd )
25
-
26
- # Store the absolute path to this script (useful for recursion).
27
21
readonly SCRIPT=" $PROJECT_ROOT /$( basename " $0 " ) "
28
22
29
23
24
+ # main development workflow
30
25
31
- # Commands follow.
32
-
33
-
34
- function install-dev {
26
+ function install {
35
27
pip install -e ' .[all]' --group dev --upgrade --upgrade-strategy eager
36
28
pre-commit install --install-hooks
37
29
}
@@ -40,56 +32,38 @@ function test {
40
32
pytest --runslow " $@ "
41
33
}
42
34
35
+ function test-all {
36
+ tox p " $@ "
37
+ }
38
+
43
39
function coverage {
44
40
unset -f coverage
45
41
coverage run -m pytest --runslow " $@ "
46
42
coverage html
47
43
coverage-report
48
44
}
49
45
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
-
76
46
function typing {
77
47
mypy " $@ "
78
48
}
79
49
80
-
81
50
function docs {
82
51
sphinx-build -E -W docs docs/_build/html " $@ "
83
52
}
84
53
54
+ function release {
55
+ python scripts/release.py " $@ "
56
+ }
57
+
58
+
59
+ # "watch" versions of the main commands
85
60
86
61
function test-dev {
87
- clean-pyc
88
- entr-project-files -cdr pytest " $@ "
62
+ watch pytest " $@ "
89
63
}
90
64
91
65
function typing-dev {
92
- entr-project-files -cdr " $SCRIPT " typing " $@ "
66
+ watch typing " $@ "
93
67
}
94
68
95
69
function docs-dev {
@@ -98,22 +72,42 @@ function docs-dev {
98
72
}
99
73
100
74
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
104
75
export READER_DB=db.sqlite
105
- flask run -p 8000 " $@ "
76
+ flask -A reader._app.wsgi --debug run " $@ "
106
77
}
107
78
108
79
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 )
111
100
}
112
101
113
102
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 " " $@ "
117
111
}
118
112
119
113
function entr-project-files {
@@ -126,25 +120,10 @@ function entr-project-files {
126
120
done
127
121
}
128
122
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 " $@ "
132
126
}
133
127
134
128
135
-
136
- # Commands end. Dispatch to command.
137
-
138
129
" $@ "
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