OILS / devtools / types.sh View on Github | oils.pub

113 lines, 63 significant
1#!/usr/bin/env bash
2#
3# Usage:
4# devtools/types.sh <function name>
5
6: ${LIB_OSH=stdlib/osh}
7source $LIB_OSH/bash-strict.sh
8source $LIB_OSH/task-five.sh # run-task
9
10source build/dev-shell.sh # python3 in $PATH
11
12readonly MYPY_FLAGS='--strict --no-strict-optional'
13
14# Note: similar to egrep filename filters in build/dynamic-deps.sh
15readonly COMMENT_RE='^[ ]*#'
16
17typecheck-files() {
18 # The --follow-imports=silent option allows adding type annotations
19 # in smaller steps without worrying about triggering a bunch of
20 # errors from imports. In the end, we may want to remove it, since
21 # everything will be annotated anyway. (that would require
22 # re-adding assert-one-error and its associated cruft, though).
23
24 # NOTE: This got a lot slower once we started using the MyPy repo, instead of
25 # the optimized package from pip
26 # Consider installing the package again
27 echo "MYPY $@"
28 time MYPYPATH='.:pyext' python3 -m mypy --py2 --follow-imports=silent $MYPY_FLAGS "$@"
29 echo
30}
31
32check-binary() {
33 local py_module=${1:-}
34
35 # TODO: remove --no-warn-unused-ignores and type: ignore in
36 # osh/builtin_comp.py after help_.py import isn't conditional
37
38 cat _build/NINJA/$py_module/typecheck.txt \
39 | xargs -- $0 typecheck-files --no-warn-unused-ignores
40}
41
42check-oils() {
43 check-binary 'bin.oils_for_unix'
44}
45
46# NOTE: Becoming obsolete as typecheck filters in build/dynamic-deps.sh are whittled down
47check-more() {
48 egrep -v "$COMMENT_RE" devtools/typecheck-more.txt \
49 | xargs -- $0 typecheck-files
50}
51
52mypy-check() {
53 local p=".:$MYPY_WEDGE:$PY3_LIBS_WEDGE"
54
55 # the path is fiddly
56 PYTHONPATH=$p MYPYPATH=$MYPY_WEDGE \
57 python3 -m mypy "$@"
58}
59
60check-mycpp() {
61 local -a files=(
62 mycpp/{pass_state,util,crash,format_strings,visitor,const_pass,control_flow_pass,mycpp_main,cppgen_pass,conversion_pass}.py
63 )
64 local -a flags=( --strict --no-strict-optional --follow-imports=silent )
65
66 mypy-check "${flags[@]}" "${files[@]}"
67}
68
69check-doctools() {
70 if false; then
71 local -a files=(
72 $(for x in doctools/*.py; do echo $x; done | grep -v '_test.py' )
73 )
74 else
75 #local -a files=( doctools/help_gen.py )
76 local -a files=( doctools/ul_table.py doctools/html_old.py doctools/oils_doc.py
77 doctools/help_gen.py data_lang/htm8.py data_lang/htm8_util.py )
78
79 fi
80
81 # 777 errors before pyann
82 # 583 afterward
83 local -a flags=( --py2 --no-strict-optional --strict --follow-imports=silent )
84 #local -a flags=( --py2 --no-strict-optional )
85
86 set -x
87 mypy-check "${flags[@]}" "${files[@]}"
88}
89
90check-all() {
91 ### Run this locally
92
93 check-oils
94
95 # Ad hoc list of additional files
96 check-more
97}
98
99soil-run() {
100 set -x
101 python3 -m mypy --version
102 set +x
103
104 # Generate oils-for-unix dependencies. Though this is overly aggressive
105 ./NINJA-config.sh
106
107 check-all
108}
109
110name=$(basename $0)
111if test "$name" = 'types.sh'; then
112 task-five "$@"
113fi