Permalink
Browse files

python: Support completing dotted module hierarchies

The dot needs to be manually entered at least for now, as walking the
entire package hierarchy with walk_packages() is much slower than just
the top level ones with iter_modules().
  • Loading branch information...
scop committed Dec 17, 2017
1 parent e0a4385 commit db9f81be1673d432afeb85fce8a35e93d9e48643
Showing with 14 additions and 3 deletions.
  1. +2 −2 completions/python
  2. +9 −1 helpers/python
  3. +3 −0 test/lib/completions/python.exp
View
@@ -3,8 +3,8 @@
_python_modules()
{
COMPREPLY+=( $( compgen -W \
"$( ${1:-python} ${BASH_SOURCE[0]%/*}/../helpers/python 2>/dev/null )" \
-- "$cur" ) )
"$( ${1:-python} ${BASH_SOURCE[0]%/*}/../helpers/python $cur \
2>/dev/null )" -- "$cur" ) )
}
_python()
View
@@ -1,6 +1,14 @@
# -*- python -*-
import pkgutil
import sys
for mod in pkgutil.iter_modules():
# walk_packages() is much slower than iter_modules(), use it only when
# completing something with a dot in it.
if len(sys.argv) > 1 and "." in sys.argv[1]:
walker = pkgutil.walk_packages
else:
walker = pkgutil.iter_modules
for mod in walker():
print(mod[1])
@@ -35,6 +35,9 @@ sync_after_int
assert_complete_any "python -m sy"
sync_after_int
assert_complete_any "python -m json."
sync_after_int
assert_complete_any "python -W "
sync_after_int

0 comments on commit db9f81b

Please sign in to comment.