From 0ea1325c93a251c8ece6eacb979f9446e9e08fbc Mon Sep 17 00:00:00 2001 From: Igor Iunash Date: Fri, 17 Apr 2026 12:54:04 +0200 Subject: [PATCH] fix: ship .pyi stubs in binary wheels The install rule copied stubs from `${CMAKE_CURRENT_BINARY_DIR}/stubs/pyopensim/`, which is populated by `scripts/python/generate_stubs.py`. That script shells out to `python -m mypy.stubgen -m pyopensim.` as a subprocess, but the `sys.path.insert(...)` used to make the package importable only affects the parent process and never propagates to the subprocess. As a result stubgen can't find `pyopensim` at build time and exits with a warning. Combined with `check=False` and the "count warnings as success" logic, the failure is silently swallowed, leaving an empty `${STUB_FILES_DIR}` and a wheel that has `py.typed` but no `.pyi` files. All three 4.5.2.0 platform wheels on PyPI are affected; only the sdist ships stubs. Install the committed source stubs from `src/pyopensim/*.pyi` instead, so wheels ship working type information regardless of whether the optional regeneration step runs. Fixing `generate_stubs.py` itself (env propagation, loud failures, import-dependency ordering) is out of scope for this change. --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b48198..59b0895 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -910,7 +910,10 @@ if(PYOPENSIM_BUILD_WITH_OPENSIM) endif() endif() -# Install stub files for IDE support -install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/stubs/pyopensim/" +# Install stub files for IDE support. +# Install from the committed source stubs so wheels always ship them, even +# when the optional regeneration step in generate_stubs.py is skipped or +# fails (e.g. because the freshly built module cannot be imported yet). +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/pyopensim/" DESTINATION "${CMAKE_INSTALL_PREFIX}/pyopensim-stubs" FILES_MATCHING PATTERN "*.pyi") \ No newline at end of file