-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmypy.sh
More file actions
executable file
·42 lines (35 loc) · 1.78 KB
/
Copy pathmypy.sh
File metadata and controls
executable file
·42 lines (35 loc) · 1.78 KB
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
#!/bin/bash -
# This is our internal mypy execution script.
# It prints the mypy command and the results of mypy.
# It always exits with an exit code 0, even if mypy fails.
# Argument $1: the folder to run it in
# Argument $2: the file(s) to scan
# We enforce strict error handling, i.e., fail on any unexpected error.
set -o pipefail # trace errors through pipes
set -o errtrace # trace errors through commands and functions
set -o nounset # exit if encountering an uninitialized variable
set -o errexit # exit if any statement returns a non-0 return value
# Check if mypy is installed. If yes, get its version. If no, install.
infos="$(python3 -m pip show mypy 2>/dev/null || true)"
if [ -z "$infos" ]; then
# mypy is not installed, so we install it now.
# We do this silently, without printing any information...
python3 -m pip install --require-virtualenv mypy 1>/dev/null 2>&1
infos="$(python3 -m pip show mypy 2>/dev/null)"
fi
# We now extract the version of mypy from the information string.
version="$(grep Version: <<< "$infos")"
version="$(sed -n 's/.*Version:\s*\([.0-9]*\)/\1/p' <<< "$version")"
# Construct the mypy command.
command="mypy $2 --no-strict-optional --check-untyped-defs"
echo "\$ $command" # We print the command line which will be executed.
cd "$1" # We enter the folder inside of which we should execute mypy.
# Switch of "exit-on-error", run mypy, and afterwards switch it back on.
set +o errexit # Turn off exit-on-error.
$command 2>&1
exitCode="$?" # Store exit code of program in variable exitCode.
set -o errexit # Turn exit-on-error back on.
# Convert exit code to success or failure string.
[ "$exitCode" -eq 0 ] && exitCodeStr="succeeded" || exitCodeStr="failed"
# Finally, we print the result string.
echo "# mypy $version $exitCodeStr with exit code $exitCode."