Ship .pyi stubs in binary wheels#10
Open
Igralino wants to merge 1 commit into
Open
Conversation
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.<module>` 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.
Author
|
@senthurayyappan can you have a look please? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Was adding type hints to a project using
pyopensimand hit this from Pylance onmuscle_set: osim.simulation.SetMuscles:Hovering
osim.simulationshowed(variable) simulation: Anyinstead of a module. Code still ran fine.Debug
Go-to-definition in VS Code jumped to
__init__.pyline 74:That
= Noneassignment is what Pylance was picking up — which shouldn't happen if.pyistubs exist, since they'd override.py. So I checked the installed wheel:Checked all three platform wheels on PyPI — same story.
py.typedpresent,pyopensim-stubs/directory missing entirely. Only the sdist ships stubs.Root cause
The install rule reads stubs from
${CMAKE_CURRENT_BINARY_DIR}/stubs/pyopensim/, populated byscripts/python/generate_stubs.py. That script:sys.path.insert(0, str(package_path.parent))— which doesn't propagate to thepython -m mypy.stubgensubprocess it then spawns (noPYTHONPATHset either). So stubgen can't importpyopensimat build time.subprocess.run(..., check=False)and thensuccess_count += 1in the else branch — warnings count as success.install(DIRECTORY ... FILES_MATCHING PATTERN "*.pyi")against an empty dir silently installs nothing.CI stays green, wheel ships without stubs.
Fix
Install from
src/pyopensim/instead of the build dir. Committed stubs are already correct — just bypass the broken regeneration step so wheels actually ship them.Fixing
generate_stubs.pyproperly (env propagation, loud failures) is a separate concern.