Debian Codegraph @

src/python/check-with-mypy

raw
1 #!/usr/bin/env bash
2 # ==========================================================================
3 # _ _ _ ____ ____ _____
4 # | | | (_) _ \ ___ _ __ / ___|___ _ _|_ _| __ __ _ ___ ___ _ __
5 # | |_| | | |_) / _ \ '__| | / _ \| '_ \| || '__/ _` |/ __/ _ \ '__|
6 # | _ | | __/ __/ | | |__| (_) | | | | || | | (_| | (_| __/ |
7 # |_| |_|_|_| \___|_| \____\___/|_| |_|_||_| \__,_|\___\___|_|
8 #
9 # --- High-Performance Connectivity Tracer (HiPerConTracer) ---
10 # https://www.nntb.no/~dreibh/hipercontracer/
11 # ==========================================================================
12 #
13 # High-Performance Connectivity Tracer (HiPerConTracer)
14 # Copyright (C) 2015-2026 by Thomas Dreibholz
15 #
16 # This program is free software: you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation, either version 3 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #
29 # Contact: [email protected]
30
31 set -eu
32
33 SCRIPTS="
34 ping-nosql-query-example
35 ping-sql-query-example
36 "
37
38
39 # ###### Helper function to show failure ####################################
40 exit-failed ()
41 {
42 echo
43 "${PRINT_UTF8}" -n -s "\e[1;31;5m█" "▀" "█\e[0m" ;
44 echo "CHECK FAILED!" | "${FIGLET}" -w "${COLUMNS}" | "${PRINT_UTF8}" -n -C "\e[1;31;5m█\e[25m" "\e[5m█\e[0m" ;
45 "${PRINT_UTF8}" -n -s "\e[1;31;5m█" "▄" "█\e[0m"
46 exit 1
47 }
48
49
50 # ###### Helper function to show success ####################################
51 exit-success ()
52 {
53 echo
54 "${PRINT_UTF8}" -n -s "\e[1;32m█" "▀" "█\e[0m" ;
55 echo "ALL CHECKS SUCCEEDED!" | "${FIGLET}" -w "${COLUMNS}" | "${PRINT_UTF8}" -n -C "\e[1;32m█\e[25m" "█\e[0m" ;
56 "${PRINT_UTF8}" -n -s "\e[1;32m█" "▄" "█\e[0m"
57 exit 0
58 }
59
60
61 # ###### Helper function to show script information #########################
62 show-script ()
63 {
64 local script="$1"
65
66 "${PRINT_UTF8}" -n -s "\e[1;36m█" "▀" "█\e[0m" ;
67 "${FIGLET}" -w "${COLUMNS}" "$(basename "${script}")" | "${PRINT_UTF8}" -n -C "\e[1;36m█\e[25m" "█\e[0m" ;
68 "${PRINT_UTF8}" -n -s "\e[1;36m█" "▄" "█\e[0m"
69 }
70
71
72
73 # ###### Main program #######################################################
74
75 # ====== Find locations of Python interpreter, MyPy, and tools ==============
76 PYTHON="$(which python 2>/dev/null || which python3 2>/dev/null || true)"
77 if [ ! -x "${PYTHON}" ] ; then
78 echo >&2 "ERROR: Unable to identify Python executable!"
79 exit 1
80 fi
81 echo "Python: ${PYTHON}"
82 # shellcheck disable=SC2001
83 MYPY="$(echo "${PYTHON}" | sed -e 's#/[^/]*$#/mypy#')"
84 if [ ! -x "${MYPY}" ] ; then
85 echo >&2 "ERROR: Unable to identify MyPy executable!"
86 echo >&2 "Try this (within the correct Python environment):"
87 echo >&2 "pip install mypy"
88 exit 1
89 fi
90 echo "MyPy: ${MYPY}"
91 PRINT_UTF8="$(which print-utf8 2>/dev/null || true)"
92 if [ ! -x "${PRINT_UTF8}" ] ; then
93 echo >&2 "ERROR: Print-UTF8 (from System-Tools) is not installed!"
94 echo >&2 "Try this:"
95 echo >&2 "* Ubuntu: sudo apt-add-repository -sy ppa:dreibh/ppa"
96 echo >&2 " sudo apt install -y td-system-tools"
97 echo >&2 "* Fedora: sudo dnf copr enable -y dreibh/ppa"
98 echo >&2 " sudo dnf install -y td-system-tools"
99 echo >&2 "* FreeBSD: sudo pkg install -y td-system-tools"
100 exit 1
101 fi
102 FIGLET="$(which figlet 2>/dev/null || true)"
103 if [ ! -x "${FIGLET}" ] ; then
104 echo >&2 "ERROR: Figlet is not installed!"
105 echo >&2 "* Ubuntu: sudo apt install -y figlet"
106 echo >&2 "* Fedora: sudo dnf install -y figlet"
107 echo >&2 "* FreeBSD: sudo pkg install -y figlet"
108 exit 1
109 fi
110
111
112 # ====== Run MyPy ===========================================================
113 for script in $SCRIPTS ; do
114 echo -e "\e[34mChecking ${script} ...\e[0m"
115 show-script "${script}"
116 "${MYPY}" --strict \
117 --install-types --non-interactive \
118 --ignore-missing-imports \
119 --show-traceback \
120 --python-executable "${PYTHON}" \
121 "${script}" || exit-failed
122 done
123 exit-success