File: mypy

package info (click to toggle)
python-beartype 0.20.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,280 kB
  • sloc: python: 76,306; sh: 299; makefile: 30
file content (80 lines) | stat: -rwxr-xr-x 3,455 bytes parent folder | download
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
#!/usr/bin/env bash
# --------------------( LICENSE                            )--------------------
# Copyright (c) 2014-2025 Beartype authors.
# See "LICENSE" for further details.
#
# --------------------( SYNOPSIS                           )--------------------
# Bash shell script statically type-checking this project with mypy, passing
# sane default options suitable for interactive terminal testing and otherwise
# passing all passed arguments as is to the "tox" command.
#
# This script is defined as a Bash rather than Bourne script purely for the
# canonical ${BASH_SOURCE} string global, reliably providing the absolute
# pathnames of this script and hence this script's directory.
#
# --------------------( CAVEATS                            )--------------------
# *THIS SCRIPT ONLY STATICALLY TYPE-CHECKS THIS PROJECT'S MAIN CODEBASE.*
# Namely, this script avoids statically type-checking this project's test suite
# as well. Why? Because we only statically type-check this project's codebase
# for PEP 561-compliance and downstream consumers themselves statically
# type-checking codebases dependent on this project. No such concerns apply to
# this test suite, which is clearly *NEVER* intended for external reuse.
#
# This test suite also conditionally statically type-checks this project's
# codebase as a functional test when the "mypy" package is importable. While
# useful as a sanity check, this script is typically preferable from the
# human-readable persective as its output is significantly more readable than
# that captured by that functional test.

# ....................{ PREAMBLE                           }....................
# Enable strictness for sanity.
set -e

# ....................{ FUNCTIONS                          }....................
# str canonicalize_path(str pathname)
#
# Canonicalize the passed pathname.
function canonicalize_path() {
    # Validate and localize all passed arguments.
    (( $# == 1 )) || {
        echo 'Expected exactly one argument.' 1>&2
        return 1
    }
    local pathname="${1}"

    # The "readlink" command's GNU-specific "-f" option would be preferable but
    # is unsupported by macOS's NetBSD-specific version of "readlink". Instead,
    # just defer to Python for portability.
    command python3 -c "
import os, sys
print(os.path.realpath(os.path.expanduser(sys.argv[1])))" "${pathname}"
}

# ....................{ PATHS                              }....................
# Absolute or relative filename of this script.
script_filename="$(canonicalize_path "${BASH_SOURCE[0]}")"

# Absolute or relative dirname of the directory directly containing this
# script, equivalent to the top-level directory for this project.
script_dirname="$(dirname "${script_filename}")"

# ....................{ MAIN                               }....................
# Temporarily change the current working directory to that of this project.
pushd "${script_dirname}" >/dev/null

# Statically type-check this project's codebase with all passed arguments.
# command python3 -m mypy "${@}"
# command python3.9 -m mypy "${@}"
# command python3.10 -m mypy "${@}"
# command python3.11 -m mypy "${@}"
# command python3.12 -m mypy "${@}"
command python3.13 -m mypy "${@}"

# 0-based exit code reported by the prior command.
exit_code=$?

# Revert the current working directory to the prior such directory.
popd >/dev/null

# Report the same exit code from this script.
exit ${exit_code}