Debian Codegraph @

src/python/check-with-mypy

raw symbols SCIP
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 -euo pipefail
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 local columns
43 columns="$(print-utf8 -t 2>/dev/null || echo "80")"
44 columns="${columns/ */}"
45 columns=$((columns - 2))
46
47 echo
48 print-utf8 -n -s "\e[1;31;5m█" "▀" "█\e[0m" ;
49 echo "CHECK FAILED!" | figlet -w "${columns}" | print-utf8 -n -C "\e[1;31;5m█\e[25m" "\e[5m█\e[0m" ;
50 print-utf8 -n -s "\e[1;31;5m█" "▄" "█\e[0m"
51 exit 1
52 }
53
54
55 # ###### Helper function to show success ####################################
56 exit-success ()
57 {
58 local columns
59 columns="$(print-utf8 -t 2>/dev/null || echo "80")"
60 columns="${columns/ */}"
61 columns=$((columns - 2))
62
63 echo
64 print-utf8 -n -s "\e[1;32m█" "▀" "█\e[0m" ;
65 echo "ALL CHECKS SUCCEEDED!" | figlet -w "${columns}" | print-utf8 -n -C "\e[1;32m█\e[25m" "█\e[0m" ;
66 print-utf8 -n -s "\e[1;32m█" "▄" "█\e[0m"
67 exit 0
68 }
69
70
71 # ###### Helper function to show script information #########################
72 show-script ()
73 {
74 local script="$1"
75 local columns
76 columns="$(print-utf8 -t 2>/dev/null || echo "80")"
77 columns="${columns/ */}"
78 columns=$((columns - 2))
79
80 print-utf8 -n -s "\e[1;36m█" "▀" "█\e[0m" ;
81 figlet -w "${columns}" "$(basename "${script}")" | print-utf8 -n -C "\e[1;36m█\e[25m" "█\e[0m" ;
82 print-utf8 -n -s "\e[1;36m█" "▄" "█\e[0m"
83 }
84
85
86
87 # ###### Main program #######################################################
88
89 # ====== Find locations of Python interpreter, MyPy, and tools ==============
90 PYTHON="$(which python 2>/dev/null || which python3 2>/dev/null || true)"
91 if [ ! -x "${PYTHON}" ] ; then
92 echo >&2 "ERROR: Unable to identify Python executable!"
93 exit 1
94 fi
95 echo "Python: ${PYTHON}"
96 # shellcheck disable=SC2001
97 MYPY="$(echo "${PYTHON}" | sed -e 's#/[^/]*$#/mypy#')"
98 if [ ! -x "${MYPY}" ] ; then
99 echo >&2 "ERROR: Unable to identify MyPy executable!"
100 echo >&2 "Try this (within the correct Python environment):"
101 echo >&2 "pip install mypy"
102 exit 1
103 fi
104 echo "MyPy: ${MYPY}"
105 PRINT_UTF8="$(which print-utf8 2>/dev/null || true)"
106 if [ ! -x "${PRINT_UTF8}" ] ; then
107 echo >&2 "ERROR: Print-UTF8 (from System-Tools) is not installed!"
108 echo >&2 "Try this:"
109 echo >&2 "* Ubuntu: sudo apt-add-repository -sy ppa:dreibh/ppa"
110 echo >&2 " sudo apt install -y td-system-tools"
111 echo >&2 "* Fedora: sudo dnf copr enable -y dreibh/ppa"
112 echo >&2 " sudo dnf install -y td-system-tools"
113 echo >&2 "* FreeBSD: sudo pkg install -y td-system-tools"
114 exit 1
115 fi
116 FIGLET="$(which figlet 2>/dev/null || true)"
117 if [ ! -x "${FIGLET}" ] ; then
118 echo >&2 "ERROR: Figlet is not installed!"
119 echo >&2 "* Ubuntu: sudo apt install -y figlet"
120 echo >&2 "* Fedora: sudo dnf install -y figlet"
121 echo >&2 "* FreeBSD: sudo pkg install -y figlet"
122 exit 1
123 fi
124
125
126 # ====== Run MyPy ===========================================================
127 for script in $SCRIPTS ; do
128 echo -e "\e[34mChecking ${script} ...\e[0m"
129 show-script "${script}"
130 "${MYPY}" --strict \
131 --install-types --non-interactive \
132 --ignore-missing-imports \
133 --show-traceback \
134 --python-executable "${PYTHON}" \
135 "${script}" || exit-failed
136 done
137 exit-success