Expand description
_python_modules submodule.
Port of _python_modules from Completion/Unix/Type/_python_modules.
Full upstream body (42 lines, abridged):
sh: 1 #autoload
sh: 3 _python_module_caching_policy () { newer=( "$1"(Nmw-1) ); return $#newer }
sh:10 _python_modules () {
sh:13 case $words[1] in (python*) python=$words[1];; (pydoc*) python=${words[1]/#pydoc/python};; (*) python="python";; esac
sh:18 local cache_id=${${python//[^[:alnum:]]/_}#_}_modules
sh:19 local array_name=_${cache_id}
sh:21 zstyle -s … cache-policy update_policy
sh:22 [[ -z $update_policy ]] && zstyle … cache-policy _python_module_caching_policy
sh:25 if ( [[ ${(P)+array_name} -eq 0 ]] || _cache_invalid $cache_id ) && ! _retrieve_cache $cache_id; then
sh:28 local script='import pkgutil\nfor …: print(name)'
sh:32 typeset -agU $array_name
sh:32 set -A $array_name $(_call_program modules $python -c ${(q)script} 2>/dev/null)
sh:36 _store_cache $cache_id $array_name
sh:37 fi
sh:39 _wanted modules expl module compadd "$@" -a -- $array_name
sh:40 }
sh:42 _python_modules "$@"sh:21-22 the cache-policy zstyle registration is a no-op here (the
caching-policy predicate is a shell fn); the cache read/write path
(_cache_invalid / _retrieve_cache / _store_cache) is preserved.
Functions§
- _python_
modules _python_modules— complete importable Python module names.