OILS / opy / pyi.sh View on Github | oilshell.org

66 lines, 38 significant
1#!/usr/bin/env bash
2#
3# See if mypy's pyi format is useful. It does extract members.
4#
5# Usage:
6# ./pyi.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12install() {
13 # needs
14 pip3 install mypy
15}
16
17oil-stubgen() {
18 local module=$1
19 local out=_tmp/pyi
20 PYTHONPATH=. _OVM_RESOURCE_ROOT=. ~/.local/bin/stubgen --py2 -o $out $module
21}
22
23demo() {
24 local out=_tmp/pyi
25 mkdir -p $out
26 # core/util.py respects that
27 oil-stubgen bin.oil
28 #oil-stubgen osh/cmd_parse
29}
30
31# Also used in test/wild.sh
32multi() { ~/hg/tree-tools/bin/multi "$@"; }
33
34manifest() {
35 # TODO: Should change build/dynamic_deps.py
36 local out=_tmp/mypy
37 mkdir -p $out
38 PYTHONPATH=. build/dynamic_deps.py py-manifest bin.oil | multi cp $out
39}
40
41stubgen-path() {
42 local py_path=$1
43 module=${py_path%'.py'} # strip suffix
44 module=${module//'/'/.} # turn / to .
45 echo "stubgen $module"
46
47 local out=_tmp/pyi
48
49 # Hm somehow this causes a syntax error.
50
51 #PYTHONPATH=_tmp/mypy _OVM_RESOURCE_ROOT=. ~/.local/bin/stubgen --py2 -o $out $module
52 PYTHONPATH=. _OVM_RESOURCE_ROOT=. ~/.local/bin/stubgen --py2 -o $out $module
53}
54
55stubgen-all() {
56 find _tmp/mypy -name '*.py' -a -printf '%P\n' \
57 | grep -v stat | xargs -n 1 -- $0 stubgen-path
58}
59
60show() {
61 # issue: you get 'log'
62 find _tmp/pyi -name '*.pyi' | xargs wc -l
63 find _tmp/pyi -name '*.pyi' | xargs head -n 10
64}
65
66"$@"