-
Notifications
You must be signed in to change notification settings - Fork 8
/
devtool
executable file
·107 lines (90 loc) · 3.08 KB
/
devtool
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
#!/usr/bin/env bash
# Note: If developing on windows, you might need to run this command to get rid of /r in this script file:
# sed -i 's/\r$//' devtool
# Or make sure your git has autocrlf off: https://stackoverflow.com/questions/29045140/env-bash-r-no-such-file-or-directory
set -euo pipefail
set -x
bootstrap() {
install_poetry
poetry install
local_plugin_add
}
lint() {
# pre-commit
echo "== Pre-commit hooks =="
pre-commit run -v -a
echo ""
# flake8
echo "== Flake8 =="
flake8 . --config=setup.cfg
echo ""
# mypy
echo "== Mypy =="
# --namespace-packages for https://stackoverflow.com/questions/64905873/sibling-package-import-and-mypy-has-no-attribute-error
echo y | mypy --install-types --namespace-packages --config-file setup.cfg src/ || mypy --install-types --namespace-packages --config-file setup.cfg src/
}
all() {
lint
echo ""
test
echo "All builds and tests passed! :)"
}
test() {
PY_VERSION=$(python -c 'import sys; print(str(sys.version_info[0]) + "." + str(sys.version_info[1]))')
# Walkthrough tests
if [[ $PY_VERSION =~ ^3\.(9|10|11)$ ]]; then
echo "== Python >= 3.9 Walkthrough Tests =="
cd test && pytest --pspec test_walkthrough.py ; cd -
elif [[ $PY_VERSION == "3.8" ]]; then
echo "== Python 3.8 Walkthrough Tests =="
cd test && pytest --cov-fail-under 78 --pspec py38/test_walkthrough_py38.py ; cd -
elif [[ $PY_VERSION == "3.7" ]]; then
echo "== Python 3.7 Walkthrough Tests =="
cd test && pytest --cov-fail-under 78 --pspec py37/test_walkthrough_py37.py ; cd -
else
echo "Unsupported python version: "$PY_VERSION
echo "test() FAILED"
exit 1
fi
}
# Delete old wheel files first!
local_plugin_add() {
poetry build -f wheel
# Calls `poetry plugin add` using the wheel file under dist/poeblix*.whl for local testing
poetry self add $PWD/dist/poeblix*.whl
}
install_poetry() {
if [[ $OSTYPE == 'cygwin'* ]]; then
$((Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -)
elif [[ $OSTYPE == 'linux-gnu'* ]] || [[ $OSTYPE == 'darwin'* ]]; then
curl -sSL https://install.python-poetry.org | python3 -
else
echo "Cannot (yet) install poetry for OS "$OSTYPE
exit 1
fi
# Update to latest preview version to catch errors before release candidates
poetry self update --preview
}
uninstall_poetry() {
# Clear pypi cache
echo yes | poetry cache clear --all pypi || true
echo yes | poetry cache clear --all PyPi || true
echo yes | poetry cache clear --all _default_cache || true
# Delete poetry global config to reset
rm -rf ~/.config/pypoetry
if [[ $OSTYPE == 'cygwin'* ]]; then
$((Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python - --uninstall)
elif [[ $OSTYPE == 'linux-gnu'* ]] || [[ $OSTYPE == 'darwin'* ]]; then
curl -sSL https://install.python-poetry.org | python3 - --uninstall
else
echo "Cannot (yet) install poetry for OS "$OSTYPE
exit 1
fi
}
reinstall_poetry() {
uninstall_poetry
install_poetry
}
# Comment set +x out to show commands run
set +x
$@