[robotpy] Run wpiformat on non-python robotpy files (#8362)

This turns the styleguide on for the non-python robotpy files.

The overwhelming amount of changes were
related to whitespace, followed by some IWYU for standard library
headers.
This commit is contained in:
PJ Reiniger
2026-06-21 22:36:03 -04:00
committed by GitHub
parent 6bc7051e23
commit 4a2cd3e5d0
71 changed files with 877 additions and 739 deletions

View File

@@ -1,21 +1,21 @@
#include <semiwrap_init.hal.simulation._simulation.hpp>
#include <pybind11/functional.h>
#include "semiwrap_init.hal.simulation._simulation.hpp"
#include "sim_cb.h"
#include "sim_value_cb.h"
void HALSIM_ResetGlobalHandles();
SEMIWRAP_PYBIND11_MODULE(m) {
py::class_<SimCB> cls_SimCB(m, "SimCB");
cls_SimCB.doc() = "Simulation callback handle";
cls_SimCB.def("cancel", &SimCB::Cancel, py::doc("Cancel the callback"));
py::class_<SimValueCB> cls_SimValueCB(m, "SimValueCB");
cls_SimValueCB.doc() = "Simulation callback handle";
cls_SimValueCB.def("cancel", &SimValueCB::Cancel, py::doc("Cancel the callback"));
cls_SimValueCB.def("cancel", &SimValueCB::Cancel,
py::doc("Cancel the callback"));
initWrapper(m);

View File

@@ -4,12 +4,11 @@
#include "wpi/hal/simulation/NotifierData.h"
void HALSIM_ResetGlobalHandles() {
// if we just reset the handles, notifiers might hang forever,
// so we just enumerate and cancel them all
auto sz = HALSIM_GetNotifierInfo(nullptr, 0);
if (sz > 0) {
struct HALSIM_NotifierInfo *info = new struct HALSIM_NotifierInfo[sz];
struct HALSIM_NotifierInfo* info = new struct HALSIM_NotifierInfo[sz];
HALSIM_GetNotifierInfo(info, sz);
for (int i = 0; i < sz; i++) {

View File

@@ -1,33 +1,29 @@
#pragma once
#include <cstdint>
#include <functional>
class SimCB {
public:
public:
SimCB(std::function<void(void)> fn, std::function<void(int32_t)> cancel)
: m_fn(fn), m_cancel(cancel) {}
SimCB(std::function<void(void)> fn, std::function<void(int32_t)> cancel) :
m_fn(fn),
m_cancel(cancel)
{}
void SetUID(int32_t uid) { m_uid = uid; }
void SetUID(int32_t uid) {
m_uid = uid;
~SimCB() { Cancel(); }
void Cancel() {
if (m_valid) {
m_cancel(m_uid);
m_valid = false;
}
}
~SimCB() {
Cancel();
}
std::function<void(void)> m_fn;
void Cancel() {
if (m_valid) {
m_cancel(m_uid);
m_valid = false;
}
}
std::function<void(void)> m_fn;
private:
bool m_valid = true;
int32_t m_uid;
std::function<void(int32_t)> m_cancel;
};
private:
bool m_valid = true;
int32_t m_uid;
std::function<void(int32_t)> m_cancel;
};

View File

@@ -1,37 +1,33 @@
#pragma once
#include <functional>
#include "wpi/hal/SimDevice.h"
class SimValueCB {
public:
public:
using FnType = std::function<void(const char*, HAL_SimValueHandle,
HAL_SimValueDirection, HAL_Value)>;
using FnType = std::function<void(const char *, HAL_SimValueHandle, HAL_SimValueDirection, HAL_Value)>;
SimValueCB(FnType fn, std::function<void(int32_t)> cancel)
: m_fn(fn), m_cancel(cancel) {}
SimValueCB(FnType fn, std::function<void(int32_t)> cancel) :
m_fn(fn),
m_cancel(cancel)
{}
void SetUID(int32_t uid) { m_uid = uid; }
void SetUID(int32_t uid) {
m_uid = uid;
~SimValueCB() { Cancel(); }
void Cancel() {
if (m_valid) {
m_cancel(m_uid);
m_valid = false;
}
}
~SimValueCB() {
Cancel();
}
FnType m_fn;
void Cancel() {
if (m_valid) {
m_cancel(m_uid);
m_valid = false;
}
}
FnType m_fn;
private:
bool m_valid = true;
int32_t m_uid;
std::function<void(int32_t)> m_cancel;
};
private:
bool m_valid = true;
int32_t m_uid;
std::function<void(int32_t)> m_cancel;
};

View File

@@ -1,5 +1,7 @@
#pragma once
#include <string>
#include <pybind11/pybind11.h>
#include "wpi/hal/DriverStationTypes.h"
@@ -8,23 +10,23 @@ namespace pybind11 {
template <>
struct format_descriptor<HAL_JoystickPOV> {
static constexpr const char c = 'B';
static constexpr const char value[2] = {c, '\0'};
static std::string format() { return std::string(1, c); }
static constexpr const char c = 'B';
static constexpr const char value[2] = {c, '\0'};
static std::string format() { return std::string(1, c); }
};
template <>
struct format_descriptor<HAL_JoystickTouchpad> {
static constexpr const char c = 'B';
static constexpr const char value[2] = {c, '\0'};
static std::string format() { return std::string(1, c); }
static constexpr const char c = 'B';
static constexpr const char value[2] = {c, '\0'};
static std::string format() { return std::string(1, c); }
};
template <>
struct format_descriptor<HAL_JoystickTouchpadFinger> {
static constexpr const char c = 'B';
static constexpr const char value[2] = {c, '\0'};
static std::string format() { return std::string(1, c); }
static constexpr const char c = 'B';
static constexpr const char value[2] = {c, '\0'};
static std::string format() { return std::string(1, c); }
};
}
} // namespace pybind11

View File

@@ -1,25 +1,26 @@
#include "wpi/hal/HAL.h"
#include "semiwrap_init.hal._wpiHal.hpp"
#include "wpi/hal/DriverStation.hpp"
#include "wpi/hal/Value.h"
#include <semiwrap_init.hal._wpiHal.hpp>
using namespace pybind11::literals;
static py::module_ sys_module;
SEMIWRAP_PYBIND11_MODULE(m) {
// Add this manually so it can be used from SimValue
py::enum_<HAL_Type>(m, "Type")
.value("UNASSIGNED", HAL_Type::HAL_UNASSIGNED)
.value("BOOLEAN", HAL_Type::HAL_BOOLEAN)
.value("DOUBLE", HAL_Type::HAL_DOUBLE)
.value("ENUM", HAL_Type::HAL_ENUM)
.value("INT", HAL_Type::HAL_INT)
.value("LONG", HAL_Type::HAL_LONG);
.value("UNASSIGNED", HAL_Type::HAL_UNASSIGNED)
.value("BOOLEAN", HAL_Type::HAL_BOOLEAN)
.value("DOUBLE", HAL_Type::HAL_DOUBLE)
.value("ENUM", HAL_Type::HAL_ENUM)
.value("INT", HAL_Type::HAL_INT)
.value("LONG", HAL_Type::HAL_LONG);
// clang-format off
// Add this manually because it would be annoying to do otherwise
py::class_<HAL_Value>(m, "Value")
.def_readonly("type", &HAL_Value::type)
@@ -57,6 +58,7 @@ SEMIWRAP_PYBIND11_MODULE(m) {
return "<Value type=invalid>";
}
});
// clang-format on
initWrapper(m);
@@ -67,15 +69,18 @@ SEMIWRAP_PYBIND11_MODULE(m) {
m.attr("__halplatform__") = "sim";
m.attr("__hal_simulation__") = true;
// clang-format off
m.def("__test_senderr", []() {
wpi::hal::SendError(1, 2, "\xfa" "badmessage", "location", "callstack", 1);
}, release_gil());
// clang-format on
#endif
// Redirect stderr to python stderr
sys_module = py::module_::import("sys");
// clang-format off
HAL_SetPrintErrorImpl([](const struct WPI_String* line) {
if (line == nullptr || line->str == nullptr || line->len == 0) {
return;
@@ -90,7 +95,9 @@ SEMIWRAP_PYBIND11_MODULE(m) {
py::print(py::reinterpret_steal<py::str>(o), "file"_a=sys_module.attr("stderr"));
}
});
// clang-format on
// clang-format off
// Do cleanup on module unload
static int unused; // the capsule needs something to reference
py::capsule cleanup(&unused, [](void *) {
@@ -106,5 +113,6 @@ SEMIWRAP_PYBIND11_MODULE(m) {
HAL_Shutdown();
}
});
// clang-format on
m.add_object("_cleanup", cleanup);
}

View File

@@ -60,4 +60,4 @@ name = "wpihal"
includedir = "src/native/wpihal/include"
libdir = "src/native/wpihal/lib"
shared_libraries = ["wpiHal"]
requires = ["robotpy-native-wpiutil", "robotpy-native-ntcore", "robotpy-native-mrclib"]
requires = ["robotpy-native-wpiutil", "robotpy-native-ntcore", "robotpy-native-mrclib"]

View File

@@ -10,4 +10,3 @@ strip_prefixes:
enums:
HAL_SimValueDirection: