Open StefanBruens opened 2 years ago
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
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.
There is one more problem when using DESTDIR (e.g. DESTDIR=/tmp/netgen_staging
).
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 https://github.com/sizmailov/pybind11-stubgen/issues/81
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: https://github.com/NGSolve/netgen/blob/354898498f512ac56733a848e3ab3fb54916753c/python/CMakeLists.txt#L35-L36For this to work,
NG_INSTALL_DIR_PYTHON
as expanded by cmakesDESTINATION
must be part of thePYTHONPATH
/sys.path
, i.e.\${DESTDIR}/${NETGEN_PYTHON_DIR_ABSOLUTE}
.