forked from trallnag/prometheus-fastapi-instrumentator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
125 lines (100 loc) · 2.75 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
#!/usr/bin/env bash
project_name="prometheus_fastapi_instrumentator"
# ==============================================================================
# Misc
function _docs {
echo "Create docs"
tmp_dir=/tmp/docs
rm -rf /tmp/docs
mkdir -p /tmp/docs
rm -rf docs/*
mkdir -p docs
poetry run pdoc --output-dir /tmp/docs --html ${project_name}
mv /tmp/docs/${project_name}/* docs/
rm -rf /tmp/docs
}
function _lint {
echo "Lint project"
poetry run flake8 --config .flake8 --statistics
poetry run mypy ${project_name} --allow-redefinition
}
function _requirements {
echo "Create requirements file"
rm -rf "requirements.txt"
poetry export \
--format "requirements.txt" \
--output "requirements.txt" \
--without-hashes
}
# ==============================================================================
# Format
function _format_style {
echo "Format style"
poetry run black .
}
function _format_imports {
echo "Format imports"
poetry run isort --profile black .
}
function _format {
_format_style
_format_imports
}
# ==============================================================================
# Test
function _test_not_slow {
echo "Run non-slow tests with Pytest"
poetry run pytest -m "not slow" --cov=./ --cov-report=xml
}
function _test_slow {
echo "Run slow tests with Pytest"
poetry run pytest -m "slow" --cov-append --cov=./ --cov-report=xml
}
function _test_multiproc {
mkdir -p /tmp/test_multiproc
export prometheus_multiproc_dir=/tmp/test_multiproc
poetry run pytest -k test_multiprocess --cov-append --cov=./ --cov-report=xml
rm -rf /tmp/test_multiproc
unset prometheus_multiproc_dir
}
function _test {
_test_not_slow
_test_slow
_test_multiproc
}
# ==============================================================================
function _help {
cat << EOF
Functions you can use like this 'bash run.sh <function name>':
docs
lint
requirements
format-style
format-imports
format
test-not-slow
test-slow
test-multiproc
test
EOF
}
if [[ $# -eq 0 ]]
then
_help
fi
for arg in "$@"
do
if [ $arg = "help" ] || [ $arg = "-help" ] || [ $arg = "--help" ]; then _help
elif [ $arg = "docs" ]; then _docs
elif [ $arg = "lint" ]; then _lint
elif [ $arg = "requirements" ]; then _requirements
elif [ $arg = "format-style" ]; then _format_style
elif [ $arg = "format-imports" ]; then _format_imports
elif [ $arg = "format" ]; then _format
elif [ $arg = "test-not-slow" ]; then _test_not_slow
elif [ $arg = "test-slow" ]; then _test_slow
elif [ $arg = "test-multiproc" ]; then _test_multiproc
elif [ $arg = "test" ]; then _test
else _help
fi
done