zsh-workers
 help / color / mirror / code / Atom feed
* Improvement to python module list generation used for command completion
@ 2015-07-25  3:37 Antony Lee
  2015-07-25 18:18 ` Jun T.
  0 siblings, 1 reply; 4+ messages in thread
From: Antony Lee @ 2015-07-25  3:37 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 762 bytes --]

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Improvement to python module list generation used for command completion
  2015-07-25  3:37 Improvement to python module list generation used for command completion Antony Lee
@ 2015-07-25 18:18 ` Jun T.
  2015-07-25 21:33   ` Antony Lee
  0 siblings, 1 reply; 4+ messages in thread
From: Jun T. @ 2015-07-25 18:18 UTC (permalink / raw)
  To: zsh-workers


2015/07/25 12:37, Antony Lee <antony.lee@berkeley.edu> wrote:
> 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.

Thanks. It is indeed *much* faster.

Do you think using 'print(name)' is sufficiently portable?
It seems it works with Python 2.x, because it is interpreted
as a print statement with a single-element tuple '(name)'.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Improvement to python module list generation used for command completion
  2015-07-25 18:18 ` Jun T.
@ 2015-07-25 21:33   ` Antony Lee
  2015-07-26  1:03     ` Jun T.
  0 siblings, 1 reply; 4+ messages in thread
From: Antony Lee @ 2015-07-25 21:33 UTC (permalink / raw)
  To: Jun T.; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 881 bytes --]

Actually on Python2 "(name)" is not interpreted as a single element tuple
but as a parenthesized string, which is the same as the string itself, so
it works the same.
Antony

2015-07-25 11:18 GMT-07:00 Jun T. <takimoto-j@kba.biglobe.ne.jp>:

>
> 2015/07/25 12:37, Antony Lee <antony.lee@berkeley.edu> wrote:
> > 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.
>
> Thanks. It is indeed *much* faster.
>
> Do you think using 'print(name)' is sufficiently portable?
> It seems it works with Python 2.x, because it is interpreted
> as a print statement with a single-element tuple '(name)'.
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Improvement to python module list generation used for command completion
  2015-07-25 21:33   ` Antony Lee
@ 2015-07-26  1:03     ` Jun T.
  0 siblings, 0 replies; 4+ messages in thread
From: Jun T. @ 2015-07-26  1:03 UTC (permalink / raw)
  To: zsh-workers

2015/07/26 06:33, Antony Lee <antony.lee@berkeley.edu> wrote:
> Actually on Python2 "(name)" is ... a parenthesized string

Oops, yes, thanks again. I've pushed your patch.

Jun


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-07-26  1:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-25  3:37 Improvement to python module list generation used for command completion Antony Lee
2015-07-25 18:18 ` Jun T.
2015-07-25 21:33   ` Antony Lee
2015-07-26  1:03     ` Jun T.

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).