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

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