sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
232 stars 47 forks source link

how to use the setup.py generated file #78

Closed vincentberenz closed 2 years ago

vincentberenz commented 2 years ago

This question may be a bit out of the scope of pybind11-stubgen, but maybe an answer may be useful to others as well.

pybind11 allowed me to generate a file mypackage.cpython-310-x86_64-linux-gnu.so .

Applying pybind11-subgen with argument "mypackage" leads to the creations of a stubs folder with a init.pyi and a setup.py file.

I cannot find how to use the setup.py file to install the stubs. When directly calling pip install ., I get the error error: package directory 'mypackage-stubs' does not exist. When reorganizing the folders and file so that such directory exists and contains init.pyi, then I get the error ERROR: Could not find a version that satisfies the requirement mypackage (which is indeed a requirement in the setup.py file).

mypackage is properly installed, i.e. calling "import mypackage" in a python module works.

(I realize this may be more a packaging question than a pybind11-stubgen question)

sizmailov commented 2 years ago

I didn't put a lot of thought into the generation of setup.py, therefore it is more like a template/example rather than a ready-to-use snippet. But I think I've tested the installation process at the moment of writing, so that should work.

To the issue you faced. The generated setup.py contains a requirement line:

    install_requires=['{package_name}'],

which prevents installation of mypackage-stubs package in absence of mypackage. You can check the list of installed packages via pip list command. Note that having a mypackage.so in a filesystem doesn't count as a proper installation of a mypackage package. To fix that you can properly install mypackage or remove the requirement line.