sizmailov / pybind11-stubgen

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

Failing to pass "-stubs" as root suffix #226

Closed alfonsoSR closed 4 weeks ago

alfonsoSR commented 4 weeks ago

I am building a python library with C++ extensions using pybind and I am trying to set up automatic stub generation as part of the build process. I am looking for a standard src structure with independent implementation and stub packages, as described here

pyproject.toml
CMakeLists.txt
src
|__package
|__package-stubs

In order to generate package-stubs, I included the following in my CMakeLists.txt

add_custom_command(
    TARGET package POST_BUILD
    COMMAND pybind11-stubgen package -o . --root-suffix "-stubs"
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src
)

which should generate src/package-stubs automatically, but instead throws an error because it mistakes "-stubs" for a flag. I have tried standard solutions for passing arguments starting with hyphen, such as --root-suffix \-stubs or --root-suffix -- -stubs, none of which work. I have also tried running the command directly from the shell with the same outcome.

Machine details

alfonsoSR commented 4 weeks ago

I've been reading argparse docs and passing --root-suffix=-stubs seems to work. There also seem to be ways to handle ambiguous arguments, which might be worth adding if it's not difficult or a significant amount of users also run into this issue.