-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathrun-tests.sh
executable file
·112 lines (88 loc) · 2.42 KB
/
run-tests.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
# campare_versions(v1, v2)
# Compares two 3-part sematic versions, returning -1 if v1 is less than v2, 1 if v1 is greater than v2 or 0 if v1 and v2 are equal.
compare_versions() {
local v1=(${1//./ })
local v2=(${2//./ })
for i in {0..2}; do
if [[ ${v1[i]} -lt ${v2[i]} ]]; then
# Version $1 is less than $2
echo -1
return
elif [[ ${v1[i]} -gt ${v2[i]} ]]; then
# Version $1 is greater than $2"
echo 1
return
fi
done
# "Version $1 is equal to $2"
echo 0
}
# get_version_in_pipx(package_name)
# Gets the standard semantic version of a package installed in Pipx if installed.
get_version_in_pipx() {
local package_name=$1
local version
version=$(pipx list | grep -oP "$package_name"\\s+\\K\[0-9\]+\.\[0-9\]+\.\[0-9\]+)
echo "$version"
}
# capitalise(word)
# Capitalizes a word.
capitalize() {
local word=$1
echo "$(tr '[:lower:]' '[:upper:]' <<< "${word:0:1}")${word:1}"
}
# print_version(name, version, capitalize, width)
# Prints the version of the software with option to capitalize name and change left-aligned padding.
print_version() {
local name=$1
local version=$2
local capitalize=${3:-true}
local width=${4:-19}
name=$([[ $capitalize == 'true' ]] && capitalize "$name" || echo "$name")
printf "%-${width}s %s\n" "$name version:" "$version"
}
# install_package(package_name)
# Installs specified package with Pipx or displays the its version if it's already installed.
install_package() {
local package_name=$1
local capitalize=${2:-true}
local version
version=$(get_version_in_pipx "$package_name")
if [[ -n $version ]]; then
print_version "$package_name" "$version" "$capitalize"
else
pipx install "$package_name"
pipx ensurepath
fi
}
main() {
local python_version
python_version=$(python --version | awk '{print $2}')
print_version "Python" "$python_version"
local pipx_version
pipx_version=$(pipx --version)
if [[ -z "$pipx_version" ]]; then
echo "Please install Pipx before running this script."
exit 1
else
print_version "Pipx" "$pipx_version"
fi
install_package "poetry"
install_package "pre-commit" false
echo
if ! poetry install; then
poetry lock
poetry install
fi
echo
poetry run pylint functional
echo
poetry run ruff check functional
echo
poetry run black --diff --color --check functional
echo
poetry run mypy functional
echo
poetry run pytest
}
main "$@"