Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Improvement to python module list generation used for command completion



Currently, both the completion for python -m and for pydoc require a list
of available python modules, generated in _python_modules.  This uses
pydoc's ModuleScanner, which is unbearably slow on systems with just a few
big packages installed because it also searches for submodules, and thus
has to import all packages(!) available on the path.

Instead, pkgutil.iter_modules (available at least since python 2.6) only
returns toplevel modules, so replacing

    local script='import sys, pydoc
def f(p,m,d):
    if m.find(".") < 0: sys.stdout.write(m+"\n")
pydoc.ModuleScanner().run(f)'

by

    local script='import pkgutil
for importer, name, ispkg in pkgutil.iter_modules(): print(name)'

in _python_modules yields a big improvement in speed.

Best,

Antony


Messages sorted by: Reverse Date, Date, Thread, Author