sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
238 stars 49 forks source link

Replacement for --no-setup-py in version 1.x #116

Closed HealsCodes closed 1 year ago

HealsCodes commented 1 year ago

As the release notes for 1.0 state "some command line options have been removed" - that's all nice and well but is there any equivalent to --no-setup-py from 0.16 or are there any plans to provide it?

My company is using stubgen in one of our projects and rely on the ability to run with that flag so currently need to pin to ~= 0.16.

sizmailov commented 1 year ago

The setup.py is not generated, therefore no option is needed.

sizmailov commented 1 year ago

The argparse rejects any unknown argument. There is no way 1.0+ would run with --no-setup-py. What errors do you get?

HealsCodes commented 1 year ago

The argparse rejects any unknown argument. There is no way 1.0+ would run with --no-setup-py. What errors do you get?

that was related to 0.16.2, which is why I deleted the comment.

In 1.0 and 1.1 I get errors about stubgen being unable to find / import modules that 0.16.2 would only throw at me if I didn't have '--no-setup-py' in the call.

Mainly errors like this:

(running pybind11-stubgen -o /tmp/build/pypi.tmp/stubs mymod.PyUI._PyUIManager)
pybind11_stubgen - [  ERROR] In mymod.PyUI._PyUIManager : Can't find/import 'Gf.Vec3d'
pybind11_stubgen - [  ERROR] In mymod.PyUI._PyUIManager : Can't find/import 'Gf.Vec2d'
pybind11_stubgen - [  ERROR] In mymod.PyUI._PyUIManager : Can't find/import 'Sdf.Path'
pybind11_stubgen - [  ERROR] In mymod.PyUI._PyUIManager : Can't find/import 'function'
pybind11_stubgen - [  ERROR] In mymod.PyUI._PyUIManager : Can't find/import 'Usd.Stage'
pybind11_stubgen - [  ERROR] In mymod.PyUI._PyUIManager : Can't find/import 'Gf.Vec2i'

The Gf and Usd types are provided by external modules installed in the same venv and referenced by the binary module I'm trying to generate stubs for.

sizmailov commented 1 year ago

Now pybind11-stubgen tries to infer missing imports from the annotations. Before inserting an import stubgen tries to import the corresponding name, so you see the errors above. You could either ignore the errors with --ignore-unresolved-names flag or make them available during stub generation.

HealsCodes commented 1 year ago

I think we can close this as the option I'm asking about is definitely NOT what caused the errors.

Adding the --ignore-unresolved-names regex for Gf/Sdf/Usd worked, even though I'm not sure how stubgen detects the names (all three of these are submodules of the Pixar-USD module and are referenced as pxr.Gf, pxr.Sdf etc. so trying to import pxr.Gf, pxr.Sdf and pxr.Usd works in this pyenv and is what the binary module does)

The one thing I'm not entirely sure why stubgen complains about is 'function', because that really is not a module used by anything in our codebase but I'm fine just ignoring it as "who knows?".

[EDIT: missing an important NOT]

sizmailov commented 1 year ago

The function warning probably comes from smth like:

def foo(): ...
def my_func(callback: type(foo)): ... # <--  type of `calllback` arg  is "function" 

This should be fixed in #119

Names are harvested from signatures (possibly restored from docstring) and actual values (e.g. module attributes). You could see all the names in output *.pyi files. A static analysis tool should complain about the same unknown names.

sizmailov commented 1 year ago

I'm going to close this one. If you find new "auto-import" feature don't do what you expect to, please open a new one.