uyar / pygenstub

A utility for generating stub files from docstrings in Python source files.
GNU General Public License v3.0
9 stars 3 forks source link

Stubs for a module? #1

Closed hbmartin closed 5 years ago

hbmartin commented 5 years ago

Can this be used to generate stubs for a module?

uyar commented 5 years ago

Not at the moment but it shouldn't be too hard to implement. I'll look into it.

doblak commented 5 years ago

Another great feature would be an option to generate stubs for a package, like stubgen does it.

uyar commented 5 years ago

@doblak On a first glance, the parameters in the "Specifying what to stub" section on that stubgen page make sense for pygenstub too. I'll try to stick to that interface. Thanks.

uyar commented 5 years ago

I've implemented a first attempt at this. Example use:

pygenstub -m xml -o out

There are some rough edges that need fixing. It also needs testing and documentation. Multiple input files and directories are also supported now.

uyar commented 5 years ago

Sorry, a change about usage to make it more like stubgen. Usage examples are now:

pygenstub foo.py
pygenstub foo.py bar.py baz.py
pygenstub foodir
pygenstub -m string -o out
pygenstub -p xml -o out
pygenstub -p xml.dom -o out

And combinations of these.

tinder-haroldmartin commented 5 years ago

@uyar this is amazing, thank you!!! 👏 I noticed on some packages I am getting "cannot handle package" error, what does this mean? Again, so much appreciation!

uyar commented 5 years ago

@tinder-haroldmartin Thank you! About the error, it's a catch-all case if anything goes wrong. I don't know much about what could go wrong yet. But you can try running with --debug to see the exception. If it says that it cannot find __path__ maybe trying with -m instead of -p could help.

I've realized that implementing stubgen-like behavior (using Any where there's no signature information) could be within reach. I'm not sure whether it's worth it, though. It feels like reimplementing stubgen; and pygenstub was meant for processing signatures, not as a general template generator.

tinder-haroldmartin commented 5 years ago

@uyar I suppose my particular use case might be edge-y. I'm using the ide/app Pythonista to write Python code for iOS. It has some builtin libs for providing access to iOS calls and I've been writing interface stubs slowly by hand. I can't use stubgen because it requires a compiled C library (for reading the AST) and Pythonista can't install C libs.

I tried with -m instead, which runs successfully, but only produces a stub showing some top level imports.

uyar commented 5 years ago

@tinder-haroldmartin This is expected behavior at the moment. pygenstub will ignore the parts that don't have signatures in their docstrings. I'll see if I can add support for producing generic stubs.

uyar commented 5 years ago

@tinder-haroldmartin OK, I have some implementation of generic stub generation in the repo. It could be improved, I guess. Then again, it could be totally buggy and useless. To activate it, use --generic:

pygenstub -p urllib -o out --generic
hbmartin commented 5 years ago

This is brilliant! Exactly what I hoped for. My deepest thanks for your hard work!