Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pybind11-stubgen generation expects netgen installed to sysroot #132

Open
StefanBruens opened this issue Aug 2, 2022 · 4 comments
Open

Comments

@StefanBruens
Copy link
Contributor

Most packaging schemes do not installed into the prefix directly, but into a staging area set by the DESTDIR env variable.

This is handled fine and transparently by CMake for almost all install(...) invocations.

Exception here of course are any attempts to e.g. import netgen or similar, as done here:

install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pybind11_stubgen --no-setup-py netgen)")
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../stubs/netgen-stubs/ DESTINATION ${NG_INSTALL_DIR_PYTHON}/netgen/ COMPONENT netgen)

For this to work, NG_INSTALL_DIR_PYTHON as expanded by cmakes DESTINATION must be part of the PYTHONPATH/sys.path, i.e. \${DESTDIR}/${NETGEN_PYTHON_DIR_ABSOLUTE}.

@ChrLackner
Copy link
Member

ChrLackner commented Aug 3, 2022

Yes, is there a clean way to set python environment from cmake install dirs? Not sure how it works cross platform so that also all shared libraries are found correctly...
Would of course be nice if installers/ python virtual envs could work with stubs as well

@StefanBruens
Copy link
Contributor Author

Something like this could work for COMMAND:

${PYTHON_EXECUTABLE} -c'import sys; import pybind11_stubgen; sys.path.append($_NG_PYTHON_INSTALL_DIR); pybind11_stubgen.main();'  --ignore-invalid defaultarg signature  --no-setup-py netgen

Maybe use sys.path.insert(0, xxx), so the install directory comes first, before any currently install netgen.
_NG_PYTHON_INSTALL_DIR should be set appropriately.

@StefanBruens
Copy link
Contributor Author

There is one more problem when using DESTDIR (e.g. DESTDIR=/tmp/netgen_staging).

_netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..',config.NETGEN_PYTHON_RPATH_BIN))
_netgen_lib_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..',config.NETGEN_PYTHON_RPATH))

gets expanded by stubgen to something like, when creating __init__.pyi:

_netgen_bin_dir = '/tmp/netgen_staging/usr/bin'
_netgen_lib_dir = '/tmp/netgen_staging/usr/lib64/netgen'

Preferably, these private attributes would be simply ignored/omitted by stubgen. See sizmailov/pybind11-stubgen#81

@StefanBruens
Copy link
Contributor Author

Still happens with 6.2.2404.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants