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

125 lines, 72 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 local manifest
39
40 local m1=_build/NINJA/$py_module/deps.txt
41 local m2=_build/NINJA/$py_module/typecheck.txt
42
43 if test -f $m1; then
44 manifest=$m1
45 elif test -f $m2; then
46 manifest=$m2
47 else
48 die "Couldn't find manifest for $py_module ($m1 or $m2)"
49 fi
50
51 cat $manifest | xargs -- $0 typecheck-files --no-warn-unused-ignores
52}
53
54check-oils() {
55 check-binary 'bin.oils_for_unix'
56}
57
58# NOTE: Becoming obsolete as typecheck filters in build/dynamic-deps.sh are whittled down
59check-more() {
60 egrep -v "$COMMENT_RE" devtools/typecheck-more.txt \
61 | xargs -- $0 typecheck-files
62}
63
64mypy-check() {
65 local p=".:$MYPY_WEDGE:$PY3_LIBS_WEDGE"
66
67 # the path is fiddly
68 PYTHONPATH=$p MYPYPATH=$MYPY_WEDGE \
69 python3 -m mypy "$@"
70}
71
72check-mycpp() {
73 local -a files=(
74 mycpp/{pass_state,util,crash,format_strings,visitor,const_pass,control_flow_pass,mycpp_main,cppgen_pass,conversion_pass}.py
75 )
76 local -a flags=( --strict --no-strict-optional --follow-imports=silent )
77
78 mypy-check "${flags[@]}" "${files[@]}"
79}
80
81check-doctools() {
82 if false; then
83 local -a files=(
84 $(for x in doctools/*.py; do echo $x; done | grep -v '_test.py' )
85 )
86 else
87 #local -a files=( doctools/help_gen.py )
88 local -a files=( doctools/ul_table.py doctools/html_old.py doctools/oils_doc.py
89 doctools/help_gen.py data_lang/htm8.py data_lang/htm8_util.py )
90
91 fi
92
93 # 777 errors before pyann
94 # 583 afterward
95 local -a flags=( --py2 --no-strict-optional --strict --follow-imports=silent )
96 #local -a flags=( --py2 --no-strict-optional )
97
98 set -x
99 mypy-check "${flags[@]}" "${files[@]}"
100}
101
102check-all() {
103 ### Run this locally
104
105 check-oils
106
107 # Ad hoc list of additional files
108 check-more
109}
110
111soil-run() {
112 set -x
113 python3 -m mypy --version
114 set +x
115
116 # Generate oils-for-unix dependencies. Though this is overly aggressive
117 ./NINJA-config.sh
118
119 check-all
120}
121
122name=$(basename $0)
123if test "$name" = 'types.sh'; then
124 task-five "$@"
125fi