mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[robotpy] Build examples (#8629)
This hooks up the bazel build to the robotpyExamples. It can use the (formly pyfrc or whatever) automatic unit tests for an example, as well as exposing the ability to run the example in simulation, with or without `halsim_gui` with a command such as `bazel run //robotpyExamples:AddressableLED-sim` This required building and using wheels instead of just a normal `py_library`, so that things like `ENTRY_POINTS` can be used. I took a bare bones approach to building and naming the wheels (for example the native ones don't have the OS info or python version in them, so they wouldn't be suitable publish to pypi, but that can always be updated later.
This commit is contained in:
44
robotpyExamples/define_examples.bzl
Normal file
44
robotpyExamples/define_examples.bzl
Normal file
@@ -0,0 +1,44 @@
|
||||
load("@allwpilib_pip_deps//:requirements.bzl", "requirement")
|
||||
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
|
||||
load("//robotpyExamples:example_projects.bzl", "PROJECTS")
|
||||
|
||||
def define_examples():
|
||||
for example_folder in PROJECTS:
|
||||
base_name = example_folder.replace("/", "_")
|
||||
common_kwargs = dict(
|
||||
srcs = [":robotpy_entry_point.py"],
|
||||
main = "robotpy_entry_point.py",
|
||||
data = native.glob([example_folder + "/**"]),
|
||||
imports = [example_folder],
|
||||
)
|
||||
common_deps = [
|
||||
":robotpy",
|
||||
"//apriltag:robotpy-apriltag",
|
||||
"//commandsv2:commandsv2-py",
|
||||
"//wpilibc:robotpy-wpilib",
|
||||
"//romiVendordep:robotpy-romi",
|
||||
"//xrpVendordep:robotpy-xrp",
|
||||
requirement("numpy"),
|
||||
]
|
||||
|
||||
py_test(
|
||||
name = base_name + "-test",
|
||||
args = ["--main", "$(location " + example_folder + "/robot.py)", "test", "--builtin"],
|
||||
deps = common_deps,
|
||||
size = "small",
|
||||
**common_kwargs
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = base_name + "-run",
|
||||
args = ["--main", "$(location " + example_folder + "/robot.py)", "run"],
|
||||
deps = common_deps,
|
||||
**common_kwargs
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = base_name + "-sim",
|
||||
args = ["--main", "$(location " + example_folder + "/robot.py)", "sim"],
|
||||
deps = common_deps + ["//simulation/halsim_gui:robotpy-halsim-gui"],
|
||||
**common_kwargs
|
||||
)
|
||||
Reference in New Issue
Block a user