NGSolve / netgen

https://ngsolve.org
GNU Lesser General Public License v2.1
298 stars 131 forks source link

pybind11-stubgen generation expects netgen installed to sysroot #132

Open StefanBruens opened 2 years ago

StefanBruens commented 2 years ago

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-L36

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 commented 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

StefanBruens commented 2 years ago

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 commented 2 years ago

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

https://github.com/NGSolve/netgen/blob/ec0fc05fd671e5ee49d70da01bf6d5539a4e680b/python/__init__.py#L5-L6

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