Skip to content

[bazel][robotpy] Generate Python type stubs - #9356

Draft
virtuald wants to merge 1 commit into
wpilibsuite:mainfrom
virtuald:pyi
Draft

[bazel][robotpy] Generate Python type stubs#9356
virtuald wants to merge 1 commit into
wpilibsuite:mainfrom
virtuald:pyi

Conversation

@virtuald

Copy link
Copy Markdown
Member

No description provided.

@github-actions github-actions Bot added os: simulation component: ntcore NetworkTables library component: wpiutil Utility library component: wpilibc WPILib C++ component: hal Hardware Abstraction Layer component: wpimath Math library type: testing Related to testing. build Monorepo organization, Gradle/CMake/Bazel, upstream_utils, etc component: wpinet Networking library component: apriltag AprilTag library robotpy Issues that affect RobotPy (Python) support component: xrp XRP vendordep component: romi Romi vendordep component: drivers labels Aug 27, 2026

def robotpy_host_only_select(values):
return select({
"//shared/bazel/rules/robotpy:host_platform": values,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be equivalent, and much simpler?

Suggested change
"//shared/bazel/rules/robotpy:host_platform": values,
"@platforms//host": values,

})

def robotpy_host_compatibility():
return HOST_CONSTRAINTS + robotpy_compatibility_select()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I suspect we actually want this stuff to be effective when exec == target, rather than host == target. When host != exec this would still break.

@virtuald

Copy link
Copy Markdown
Member Author

I told the 🤖 to only build artifacts once, and this is the design it proposed to implement. I don't have any idea if it actually did this:

Recommended design

  1. Load Bazel’s generated HOST_CONSTRAINTS from @platforms//host:constraints.bzl.
  2. Define a host-matching config_setting.
  3. Keep extension modules and the stubgen runner in the target configuration.
  4. Include .pyi targets in libraries and wheels only through a host-platform select():
    • Target matches host: generate/package stubs; extension compiles once.
    • Target differs from host: omit stub generation and .pyi files; wheel continues
      building.
  5. Mark direct *.make_pyi targets host-compatible only, so explicitly requesting one
    during a cross-build reports it as incompatible rather than failing while importing
    the foreign extension.

@virtuald

Copy link
Copy Markdown
Member Author

TODO: also add semiwrap update-init

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Monorepo organization, Gradle/CMake/Bazel, upstream_utils, etc component: apriltag AprilTag library component: drivers component: hal Hardware Abstraction Layer component: ntcore NetworkTables library component: romi Romi vendordep component: wpilibc WPILib C++ component: wpimath Math library component: wpinet Networking library component: wpiutil Utility library component: xrp XRP vendordep os: simulation robotpy Issues that affect RobotPy (Python) support type: testing Related to testing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants