mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 20:13:32 +01:00
This commit adds support for static typechecking with mypy.
Notable additions:
- A new target "check" which does the type checking
- Py-mods.mk, meant to be included from a directory containing python modules
in subdirectories, but not being a python module itself. It makes the all
target depend on check only if PY_RUN_CHECK_AFTER_BUILD is defined and
true. That's because pypy is under heavy development, and the Ubuntu 18.04
version is too old to work for lots of the code.
Signed-off-by: Jan Lindemann <jan@janware.com>
81 lines
1.3 KiB
Bash
81 lines
1.3 KiB
Bash
#!/bin/bash
|
|
|
|
usage()
|
|
{
|
|
cat <<-EOT
|
|
|
|
usage $myname [-e sed-extract-command] [-m module] file.py ...
|
|
|
|
EOT
|
|
[ "$1" ] && exit $1
|
|
}
|
|
|
|
module_path()
|
|
{
|
|
if [ "$module" ]; then
|
|
echo $module.$1
|
|
return
|
|
fi
|
|
echo $1
|
|
}
|
|
|
|
cmd_create_init()
|
|
{
|
|
local import_submodules=0
|
|
local e f files base extracted module_path
|
|
local del="-------------------------- generated by $myname"
|
|
echo "# >> $del >>"
|
|
echo "from pkgutil import extend_path"
|
|
echo "from typing import Iterable"
|
|
echo "__path__ = extend_path(__path__, __name__) # type: Iterable[str]"
|
|
files="$*"
|
|
for f in $files; do
|
|
test -d $f && continue
|
|
base=${f##*/}
|
|
base=${base%.py}
|
|
if [ "$sed_extract_command" ]; then
|
|
#echo running $sed_extract_command on $f
|
|
extracted=`sed "$sed_extract_command" $f`
|
|
#extracted="$sed_extract_command"
|
|
for e in $extracted; do
|
|
echo "from `module_path $base` import $e"
|
|
done
|
|
fi
|
|
done
|
|
if [ "$import_submodules" = 1 ]; then
|
|
for f in $files; do
|
|
[ -f $f/__init__.py ] && echo "import `module_path $f` as $f"
|
|
done
|
|
fi
|
|
echo "# << $del <<"
|
|
}
|
|
|
|
# --------------------- here we go
|
|
|
|
myname=`basename $0`
|
|
|
|
eval set -- `getopt -o 'he:m:' "$@"`
|
|
while [ "$1" != -- ]; do
|
|
case $1 in
|
|
-e)
|
|
sed_extract_command="$2"
|
|
shift
|
|
;;
|
|
-m)
|
|
module=$2
|
|
shift
|
|
;;
|
|
-h)
|
|
usage 0;;
|
|
*)
|
|
echo unknown argument $1
|
|
usage 1;;
|
|
esac
|
|
shift
|
|
done
|
|
shift
|
|
|
|
cmd=cmd_${1//-/_}
|
|
shift
|
|
|
|
eval $cmd $*
|