Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Improvement to python module list generation used for command completion
- X-seq: zsh-workers 35899
- From: Antony Lee <antony.lee@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Improvement to python module list generation used for command completion
- Date: Fri, 24 Jul 2015 20:37:28 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:message-id:subject:to:content-type; bh=mpM8mrPun5jlf3U1b9mpxriJEaZMt0KiJc4jxFvfil4=; b=QDeU9ikOnXQvE7JCctIJ5Mdg6zb79C5takM6nTy5hw0bDAO8jccGIK5Lf8YXKP2ixb j769O1UHv9T6fzUl4UbHw2kVXkxL5z4tLbhDiHympvnAUBUH+PQVMhPb9FxyXzu2i0sg tRYgMcxATCYWqYasvmYaqdkUFnVre71dbpaymRr+U+5KE2z5U8I9HkErqyCfI59JQM8m IEwGoRQIaCSdpFFvL+wZ5TtQ5JKUMjv9dm31Eb1JCPbTf/MQZ/OmrkVw8112QtATuvjU Bwn4/8nvujdOAgahsJrwQigdtTWtv6TXRn0S0T+G13nlmKeeJYveXHulU/zgAFuJOwkm 0sMA==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Sender: anntzer.lee@xxxxxxxxx
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