[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

@@ -1,7 +1,11 @@
load("@allwpilib_pip_deps//:requirements.bzl", "requirement")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("@rules_python//python:defs.bzl", "py_library")
load("//shared/bazel/rules:cc_rules.bzl", "wpilib_cc_library", "wpilib_cc_shared_library", "wpilib_cc_static_library")
load("//shared/bazel/rules:packaging.bzl", "package_default_cc_project")
load("//shared/bazel/rules:publishing.bzl", "host_architectures")
load("//shared/bazel/rules/robotpy:pybind_rules.bzl", "copy_native_file")
load("//shared/bazel/rules/robotpy:pytest_util.bzl", "robotpy_py_test")
cc_library(
name = "headers",
@@ -92,3 +96,31 @@ package_default_cc_project(
maven_artifact_name = "halsim_ds_socket",
maven_group_id = "org.wpilib.halsim",
)
copy_native_file(
name = "halsim_ds_socket",
base_path = "src/main/python/halsim_ds_socket/",
library = "shared/halsim_ds_socket",
)
py_library(
name = "robotpy-halsim-ds-socket",
srcs = glob(["src/main/python/**/*.py"]),
data = [
":halsim_ds_socket.copy_lib",
],
imports = ["src/main/python"],
deps = [
"//hal:robotpy-native-wpihal",
"//wpinet:robotpy-native-wpinet",
],
)
robotpy_py_test(
"python_tests",
srcs = glob(["src/test/python/**/*.py"]),
deps = [
":robotpy-halsim-ds-socket",
requirement("pytest"),
],
)

View File

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

View File

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

View File

@@ -0,0 +1,23 @@
import logging
import os
from os.path import abspath, dirname, join
logger = logging.getLogger("halsim_ds_socket")
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 DS Socket Extension %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)

View File

@@ -0,0 +1,40 @@
[build-system]
build-backend = "hatchling.build"
requires = [
"hatchling",
"hatch-robotpy~=0.2.1",
]
[project]
name = "robotpy-halsim-ds-socket"
version = "0.0.0"
description = "WPILib simulator DS Socket Extension"
authors = [
{name = "RobotPy Development Team", email = "robotpy@googlegroups.com"},
]
license = "BSD-3-Clause"
dependencies = [
"robotpy-native-wpihal==0.0.0",
"robotpy-native-wpinet==0.0.0",
]
[project.entry-points."robotpy_sim.2027"]
ds-socket = "halsim_ds_socket"
[tool.hatch.build.hooks.robotpy]
version_file = "halsim_ds_socket/version.py"
[[tool.hatch.build.hooks.robotpy.maven_lib_download]]
artifact_id = "halsim_ds_socket"
group_id = "org.wpilib.halsim"
repo_url = ""
version = "0.0.0"
use_headers = false
extract_to = "halsim_ds_socket"
libs = ["halsim_ds_socket"]
[tool.hatch.build.targets.wheel]
packages = ["halsim_ds_socket"]

View File

@@ -0,0 +1,18 @@
import ctypes
import pathlib
def test_halsim_ds_socket():
# dependencies
import native.wpihal._init_robotpy_native_wpihal
import native.wpinet._init_robotpy_native_wpinet
import halsim_ds_socket as base
loaded = 0
for fname in (pathlib.Path(base.__file__).parent / "lib").iterdir():
if fname.is_file() and fname.suffix in (".dll", ".dylib", ".so"):
ctypes.CDLL(str(fname))
loaded += 1
assert loaded

View File

@@ -1,7 +1,10 @@
load("@allwpilib_pip_deps//:requirements.bzl", "requirement")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")
load("//shared/bazel/rules:cc_rules.bzl", "wpilib_cc_library", "wpilib_cc_shared_library", "wpilib_cc_static_library")
load("//shared/bazel/rules:packaging.bzl", "package_default_cc_project")
load("//shared/bazel/rules:publishing.bzl", "host_architectures")
load("//shared/bazel/rules/robotpy:pytest_util.bzl", "robotpy_py_test")
load("//simulation/halsim_gui:robotpy_pybind_build_info.bzl", "define_pybind_library", "halsim_gui_ext_extension")
wpilib_cc_library(
name = "halsim_gui",
@@ -148,3 +151,36 @@ package_default_cc_project(
maven_artifact_name = "halsim_gui",
maven_group_id = "org.wpilib.halsim",
)
PKG_CONFIG_DEPS = [
"//datalog:native/datalog/robotpy-native-datalog.pc",
"//datalog:robotpy-wpilog.generated_pkgcfg_files",
"//hal:native/wpihal/robotpy-native-wpihal.pc",
"//hal:robotpy-hal.generated_pkgcfg_files",
"//ntcore:native/ntcore/robotpy-native-ntcore.pc",
"//ntcore:pyntcore.generated_pkgcfg_files",
"//wpimath:native/wpimath/robotpy-native-wpimath.pc",
"//wpimath:robotpy-wpimath.generated_pkgcfg_files",
"//wpinet:native/wpinet/robotpy-native-wpinet.pc",
"//wpinet:robotpy-wpinet.generated_pkgcfg_files",
"//wpiutil:native/wpiutil/robotpy-native-wpiutil.pc",
"//wpiutil:robotpy-wpiutil.generated_pkgcfg_files",
]
halsim_gui_ext_extension(
srcs = glob(["src/main/python/halsim_gui/_ext/**/*.cpp"]),
)
define_pybind_library(
name = "robotpy-halsim-gui",
pkgcfgs = PKG_CONFIG_DEPS,
)
robotpy_py_test(
"python_tests",
srcs = glob(["src/test/python/**/*.py"]),
deps = [
":robotpy-halsim-gui",
requirement("pytest"),
],
)

View File

@@ -0,0 +1,152 @@
# THIS FILE IS AUTO GENERATED
load("//shared/bazel/rules/gen:gen-version-file.bzl", "generate_version_file")
load("//shared/bazel/rules/robotpy:pybind_rules.bzl", "copy_native_file", "create_pybind_library", "robotpy_library")
load("//shared/bazel/rules/robotpy:semiwrap_helpers.bzl", "gen_libinit", "gen_modinit_hpp", "gen_pkgconf", "resolve_casters", "run_header_gen")
def halsim_gui_ext_extension(srcs = [], header_to_dat_deps = [], extra_hdrs = [], includes = [], extra_pyi_deps = []):
HALSIM_GUI_EXT_HEADER_GEN = [
]
resolve_casters(
name = "halsim_gui_ext.resolve_casters",
caster_deps = ["//wpimath:src/main/python/wpimath/wpimath-casters.pybind11.json", "//wpiutil:src/main/python/wpiutil/wpiutil-casters.pybind11.json"],
casters_pkl_file = "halsim_gui_ext.casters.pkl",
dep_file = "halsim_gui_ext.casters.d",
)
gen_libinit(
name = "halsim_gui_ext.gen_lib_init",
output_file = "src/main/python/halsim_gui/_ext/_init__halsim_gui_ext.py",
modules = ["hal._init__wpiHal", "wpimath._init__wpimath", "ntcore._init__ntcore"],
)
gen_pkgconf(
name = "halsim_gui_ext.gen_pkgconf",
libinit_py = "halsim_gui._ext._init__halsim_gui_ext",
module_pkg_name = "halsim_gui._ext._halsim_gui_ext",
output_file = "halsim_gui_ext.pc",
pkg_name = "halsim_gui_ext",
install_path = "src/main/python/halsim_gui/_ext",
project_file = "src/main/python/pyproject.toml",
package_root = "src/main/python/halsim_gui/_ext/__init__.py",
)
gen_modinit_hpp(
name = "halsim_gui_ext.gen_modinit_hpp",
input_dats = [x.class_name for x in HALSIM_GUI_EXT_HEADER_GEN],
libname = "_halsim_gui_ext",
output_file = "semiwrap_init.halsim_gui._ext._halsim_gui_ext.hpp",
)
run_header_gen(
name = "halsim_gui_ext",
casters_pickle = "halsim_gui_ext.casters.pkl",
header_gen_config = HALSIM_GUI_EXT_HEADER_GEN,
trampoline_subpath = "src/main/python/halsim_gui/_ext",
deps = header_to_dat_deps,
local_native_libraries = [
],
)
create_pybind_library(
name = "halsim_gui_ext",
install_path = "src/main/python/halsim_gui/_ext/",
extension_name = "_halsim_gui_ext",
generated_srcs = [],
semiwrap_header = [":halsim_gui_ext.gen_modinit_hpp"],
deps = [
":halsim_gui_ext.tmpl_hdrs",
":halsim_gui_ext.trampoline_hdrs",
"//hal:wpiHal",
"//hal:wpihal_pybind_library",
"//ntcore:ntcore",
"//ntcore:ntcore_pybind_library",
"//simulation/halsim_gui:halsim_gui",
"//wpimath:wpimath",
"//wpimath:wpimath_pybind_library",
],
dynamic_deps = [
"//hal:shared/wpiHal",
"//simulation/halsim_gui:shared/halsim_gui",
"//ntcore:shared/ntcore",
"//wpimath:shared/wpimath",
],
extra_hdrs = extra_hdrs,
extra_srcs = srcs,
includes = includes,
)
native.filegroup(
name = "halsim_gui_ext.generated_files",
srcs = [
"halsim_gui_ext.gen_modinit_hpp.gen",
"halsim_gui_ext.header_gen_files",
"halsim_gui_ext.gen_pkgconf",
"halsim_gui_ext.gen_lib_init",
],
tags = ["manual", "robotpy"],
)
def define_pybind_library(name, pkgcfgs = []):
# Helper used to generate all files with one target.
native.filegroup(
name = "{}.generated_files".format(name),
srcs = [
"halsim_gui_ext.generated_files",
],
tags = ["manual", "robotpy"],
visibility = ["//visibility:public"],
)
# Files that will be included in the wheel as data deps
native.filegroup(
name = "{}.generated_pkgcfg_files".format(name),
srcs = [
"src/main/python/halsim_gui/_ext/halsim_gui_ext.pc",
],
tags = ["manual", "robotpy"],
visibility = ["//visibility:public"],
)
# Contains all of the non-python files that need to be included in the wheel
native.filegroup(
name = "{}.extra_files".format(name),
srcs = native.glob(["src/main/python/halsim_gui/**"], exclude = ["src/main/python/halsim_gui/**/*.py"], allow_empty = True),
tags = ["manual", "robotpy"],
)
generate_version_file(
name = "{}.generate_version".format(name),
output_file = "src/main/python/halsim_gui/version.py",
template = "//shared/bazel/rules/robotpy:version_template.in",
)
copy_native_file(
name = "halsim_gui",
library = ":shared/halsim_gui",
base_path = "src/main/python/halsim_gui/",
)
robotpy_library(
name = name,
srcs = native.glob(["src/main/python/halsim_gui/**/*.py"]) + [
"src/main/python/halsim_gui/_ext/_init__halsim_gui_ext.py",
"{}.generate_version".format(name),
],
data = [
"{}.generated_pkgcfg_files".format(name),
"{}.extra_files".format(name),
":src/main/python/halsim_gui/_ext/_halsim_gui_ext",
":halsim_gui_ext.trampoline_hdr_files",
":halsim_gui.copy_lib",
],
imports = ["src/main/python"],
deps = [
"//hal:robotpy-hal",
"//ntcore:pyntcore",
"//wpimath:robotpy-wpimath",
"//wpiutil:robotpy-wpiutil",
],
visibility = ["//visibility:public"],
)

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"]

View File

@@ -0,0 +1,20 @@
import ctypes
import pathlib
def test_halsim_gui():
# dependencies
import wpinet
import hal
import wpimath
import ntcore
import halsim_gui as base
loaded = 0
for fname in (pathlib.Path(base.__file__).parent / "lib").iterdir():
if fname.is_file() and fname.suffix in (".dll", ".dylib", ".so"):
ctypes.CDLL(str(fname))
loaded += 1
assert loaded

View File

@@ -1,6 +1,10 @@
load("@allwpilib_pip_deps//:requirements.bzl", "requirement")
load("@rules_python//python:defs.bzl", "py_library")
load("//shared/bazel/rules:cc_rules.bzl", "wpilib_cc_library", "wpilib_cc_shared_library", "wpilib_cc_static_library")
load("//shared/bazel/rules:packaging.bzl", "package_default_cc_project")
load("//shared/bazel/rules:publishing.bzl", "host_architectures")
load("//shared/bazel/rules/robotpy:pybind_rules.bzl", "copy_native_file")
load("//shared/bazel/rules/robotpy:pytest_util.bzl", "robotpy_py_test")
wpilib_cc_library(
name = "halsim_ws_core",
@@ -54,3 +58,39 @@ package_default_cc_project(
maven_artifact_name = "halsim_ws_core",
maven_group_id = "org.wpilib.halsim",
)
copy_native_file(
name = "halsim_ws_client",
base_path = "src/main/python/halsim_ws/client/",
library = "//simulation/halsim_ws_client:shared/halsim_ws_client",
)
copy_native_file(
name = "halsim_ws_server",
base_path = "src/main/python/halsim_ws/server/",
library = "//simulation/halsim_ws_server:shared/halsim_ws_server",
)
py_library(
name = "robotpy-halsim-ws",
srcs = glob(["src/main/python/**/*.py"]),
data = [
":halsim_ws_client.copy_lib",
":halsim_ws_server.copy_lib",
],
imports = ["src/main/python"],
visibility = ["//visibility:public"],
deps = [
"//hal:robotpy-native-wpihal",
"//wpinet:robotpy-native-wpinet",
],
)
robotpy_py_test(
"python_tests",
srcs = glob(["src/test/python/**/*.py"]),
deps = [
":robotpy-halsim-ws",
requirement("pytest"),
],
)

View File

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

View File

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

View File

@@ -0,0 +1,23 @@
import logging
import os
from os.path import abspath, dirname, join
logger = logging.getLogger("halsim_ws.client")
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 websim client %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)

View File

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

View File

@@ -0,0 +1,23 @@
import logging
import os
from os.path import abspath, dirname, join
logger = logging.getLogger("halsim_ws.server")
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 websim server %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)

View File

@@ -0,0 +1,55 @@
[build-system]
build-backend = "hatchling.build"
requires = [
"hatchling",
"hatch-robotpy~=0.2.1",
]
[project]
name = "robotpy-halsim-ws"
version = "0.0.0"
description = "WPILib simulator websim Extensions"
authors = [
{name = "RobotPy Development Team", email = "robotpy@googlegroups.com"},
]
license = "BSD-3-Clause"
dependencies = [
"robotpy-native-wpihal==0.0.0",
"robotpy-native-wpinet==0.0.0",
]
[project.entry-points."robotpy_sim.2027"]
ws-server = "halsim_ws.server"
ws-client = "halsim_ws.client"
[project.urls]
"Source code" = "https://github.com/robotpy/mostrobotpy"
[tool.hatch.build.hooks.robotpy]
version_file = "halsim_ws/version.py"
[[tool.hatch.build.hooks.robotpy.maven_lib_download]]
artifact_id = "halsim_ws_server"
group_id = "org.wpilib.halsim"
repo_url = ""
version = "0.0.0"
use_headers = false
extract_to = "halsim_ws/server"
libs = ["halsim_ws_server"]
[[tool.hatch.build.hooks.robotpy.maven_lib_download]]
artifact_id = "halsim_ws_client"
group_id = "org.wpilib.halsim"
repo_url = ""
version = "0.0.0"
use_headers = false
extract_to = "halsim_ws/client"
libs = ["halsim_ws_client"]
[tool.hatch.build.targets.wheel]
packages = ["halsim_ws"]

View File

@@ -0,0 +1,18 @@
import ctypes
import pathlib
def test_halsim_ws_client():
# dependencies
import native.wpihal._init_robotpy_native_wpihal
import native.wpinet._init_robotpy_native_wpinet
import halsim_ws.client as base
loaded = 0
for fname in (pathlib.Path(base.__file__).parent / "lib").iterdir():
if fname.is_file() and fname.suffix in (".dll", ".dylib", ".so"):
ctypes.CDLL(str(fname))
loaded += 1
assert loaded

View File

@@ -0,0 +1,18 @@
import ctypes
import pathlib
def test_halsim_ws_server():
# dependencies
import native.wpihal._init_robotpy_native_wpihal
import native.wpinet._init_robotpy_native_wpinet
import halsim_ws.server as base
loaded = 0
for fname in (pathlib.Path(base.__file__).parent / "lib").iterdir():
if fname.is_file() and fname.suffix in (".dll", ".dylib", ".so"):
ctypes.CDLL(str(fname))
loaded += 1
assert loaded