[copybara] mostrobotpy to allwpilib (#8545)

Project import generated by Copybara.
GitOrigin-RevId: f10284b37498bb6a088891ca41f160793ec7fd90
This commit is contained in:
PJ Reiniger
2026-01-12 22:11:02 -05:00
committed by GitHub
parent 7e1260b003
commit 762d1e8b93
64 changed files with 2665 additions and 66 deletions

View File

@@ -0,0 +1,18 @@
robotpy-halsim-gui
==================
Installing this package will allow you to utilize the 2020+ WPILib GUI
simulation from a RobotPy program.
Usage
-----
First, install pyfrc. Then run your robot with the 'sim' argument:
# Windows
py -3 -m robotpy sim
# Linux/OSX
python3 -m robotpy sim
WPILib's documentation for using the simulator can be found at http://docs.wpilib.org/en/latest/docs/software/wpilib-tools/robot-simulation/simulation-gui.html

View File

@@ -0,0 +1 @@
from .main import loadExtension

View File

@@ -0,0 +1 @@
from . import _init__halsim_gui_ext

View File

@@ -0,0 +1,44 @@
#include <semiwrap_init.halsim_gui._ext._halsim_gui_ext.hpp>
#include <functional>
#include <wpi/halsim/gui/HALSimGuiExt.hpp>
#include <wpi/hal/Extensions.h>
std::function<void()> g_gui_exit;
SEMIWRAP_PYBIND11_MODULE(m) {
initWrapper(m);
m.def("_kill_on_signal", []() {
HAL_RegisterExtensionListener(
nullptr, [](void *, const char *name, void *data) {
std::string_view name_view{name};
if (name_view == HALSIMGUI_EXT_GUIEXIT) {
g_gui_exit = (halsimgui::GuiExitFn)data;
} else if (name_view == HALSIMGUI_EXT_ADDGUILATEEXECUTE) {
auto AddGuiLateExecute = (halsimgui::AddGuiLateExecuteFn)data;
AddGuiLateExecute([] {
py::gil_scoped_acquire gil;
if (PyErr_CheckSignals() == -1) {
// If a python signal has been triggered, the GUI needs to exit. It's
// not safe to throw an exception here on all platforms so we just
// assume that the only eventual caller of this function is HAL_RunMain,
// and our wrapper around that function will check if a python error is
// set and throw from there.
//
// Reference: https://github.com/wpilibsuite/allwpilib/issues/8528
if (g_gui_exit) {
g_gui_exit();
} else {
throw py::error_already_set();
}
}
});
}
});
});
}

View File

@@ -0,0 +1,27 @@
import logging
import os
from os.path import abspath, dirname, join
logger = logging.getLogger("halsim_gui")
def loadExtension():
try:
import hal
except ImportError as e:
# really, should never happen...
raise ImportError("you must install robotpy-hal!") from e
from .version import version
logger.info("WPILib HAL Simulation %s", version)
root = join(abspath(dirname(__file__)), "lib")
ext = join(root, os.listdir(root)[0])
retval = hal.loadOneExtension(ext)
if retval != 0:
logger.warn("loading extension may have failed (error=%d)", retval)
from ._ext._halsim_gui_ext import _kill_on_signal
_kill_on_signal()

View File

@@ -0,0 +1,57 @@
[build-system]
build-backend = "hatchling.build"
requires = [
"semiwrap~=0.2.1",
"hatch-meson~=0.1.0",
"hatch-robotpy~=0.2.1",
"hatchling",
"robotpy-wpiutil==0.0.0",
"robotpy-wpimath==0.0.0",
"robotpy-hal==0.0.0",
"pyntcore==0.0.0",
]
[project]
name = "robotpy-halsim-gui"
version = "0.0.0"
description = "WPILib simulation GUI"
authors = [
{name = "RobotPy Development Team", email = "robotpy@googlegroups.com"},
]
license = "BSD-3-Clause"
dependencies = [
"robotpy-wpiutil==0.0.0",
"robotpy-wpimath==0.0.0",
"robotpy-hal==0.0.0",
"pyntcore==0.0.0",
]
[project.urls]
"Source code" = "https://github.com/robotpy/mostrobotpy"
[tool.hatch.build.hooks.robotpy]
version_file = "halsim_gui/version.py"
[[tool.hatch.build.hooks.robotpy.maven_lib_download]]
artifact_id = "halsim_gui"
group_id = "org.wpilib.halsim"
repo_url = ""
version = "0.0.0"
use_headers = true
libs = ["halsim_gui"]
extract_to = "halsim_gui"
[tool.hatch.build.hooks.semiwrap]
[tool.hatch.build.hooks.meson]
[tool.hatch.build.targets.wheel]
packages = ["halsim_gui"]
[tool.semiwrap]
[tool.semiwrap.extension_modules."halsim_gui._ext._halsim_gui_ext"]
name = "halsim_gui_ext"
depends = ["wpihal", "wpimath", "ntcore"]