[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

@@ -18,8 +18,8 @@ modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY ROBOTPY AND CONTRIBUTORS``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ROBOTPY OR CONTRIBUTORS BE LIABLE FOR
WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ROBOTPY OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
@@ -45,12 +45,11 @@ Code for WPILib was derived from code using the following license:
*
* THIS SOFTWARE IS PROVIDED BY FIRST AND CONTRIBUTORS``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR
* WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -24,7 +24,7 @@ classes:
ColorOrder:
inline_code: |
.def("setData", [](wpi::AddressableLED& self, const wpi::AddressableLEDBuffer& data) {
return self.SetData(data);
return self.SetData(data);
}, release_gil(), py::prepend());
wpi::AddressableLED::LEDData:
force_no_trampoline: true

View File

@@ -6,11 +6,11 @@
namespace wpi::impl {
void ResetSmartDashboardInstance();
void ResetMotorSafety();
} // namespace wpi::impl
} // namespace wpi::impl
namespace wpi::util::impl {
void ResetSendableRegistry();
} // namespace wpi::impl
} // namespace wpi::util::impl
void resetWpilibSimulationData() {
wpi::impl::ResetSmartDashboardInstance();

View File

@@ -1,4 +1,6 @@
#include "semiwrap_init.wpilib._wpilib.hpp"
SEMIWRAP_PYBIND11_MODULE(m) { initWrapper(m); }
SEMIWRAP_PYBIND11_MODULE(m) {
initWrapper(m);
}

View File

@@ -4,8 +4,8 @@
#include "rpy/AddressableLEDBuffer.h"
#include <stdexcept>
#include <span>
#include <stdexcept>
namespace wpi {
@@ -21,17 +21,22 @@ void AddressableLEDBuffer::SetLED(size_t index, const wpi::util::Color& color) {
m_buffer.at(index).SetLED(color);
}
void AddressableLEDBuffer::SetLED(size_t index, const wpi::util::Color8Bit& color) {
void AddressableLEDBuffer::SetLED(size_t index,
const wpi::util::Color8Bit& color) {
m_buffer.at(index).SetLED(color);
}
int AddressableLEDBuffer::GetRed(size_t index) const { return m_buffer.at(index).r; }
int AddressableLEDBuffer::GetRed(size_t index) const {
return m_buffer.at(index).r;
}
int AddressableLEDBuffer::GetGreen(size_t index) const {
return m_buffer.at(index).g;
}
int AddressableLEDBuffer::GetBlue(size_t index) const { return m_buffer.at(index).b; }
int AddressableLEDBuffer::GetBlue(size_t index) const {
return m_buffer.at(index).b;
}
wpi::util::Color AddressableLEDBuffer::GetLED(size_t index) const {
const auto& led = m_buffer.at(index);
@@ -64,7 +69,8 @@ void AddressableLEDBuffer::View::SetHSV(size_t index, int h, int s, int v) {
at(index).SetHSV(h, s, v);
}
void AddressableLEDBuffer::View::SetLED(size_t index, const wpi::util::Color& color) {
void AddressableLEDBuffer::View::SetLED(size_t index,
const wpi::util::Color& color) {
at(index).SetLED(color);
}
@@ -81,8 +87,7 @@ AddressableLED::LEDData& AddressableLEDBuffer::View::at(size_t index) {
return m_data[index];
}
AddressableLED::LEDData& AddressableLEDBuffer::View::operator[](
size_t index) {
AddressableLED::LEDData& AddressableLEDBuffer::View::operator[](size_t index) {
return at(index);
}
@@ -105,7 +110,8 @@ wpi::util::Color AddressableLEDBuffer::View::GetLED(size_t index) const {
return wpi::util::Color{led.r / 255.0, led.g / 255.0, led.b / 255.0};
}
wpi::util::Color8Bit AddressableLEDBuffer::View::GetLED8Bit(size_t index) const {
wpi::util::Color8Bit AddressableLEDBuffer::View::GetLED8Bit(
size_t index) const {
const auto& led = at(index);
return wpi::util::Color8Bit{led.r, led.g, led.b};
}

View File

@@ -7,6 +7,7 @@
#include <span>
#include <stdexcept>
#include <vector>
#include "pybind11/pytypes.h"
#include "wpi/hardware/led/AddressableLED.hpp"
#include "wpi/util/Color.hpp"
@@ -151,8 +152,9 @@ class AddressableLEDBuffer {
auto end() { return m_buffer.end(); }
/**
* A view of another addressable LED buffer. Views provide an easy way to split a large LED
* strip into smaller sections that can be animated individually.
* A view of another addressable LED buffer. Views provide an easy way to
* split a large LED strip into smaller sections that can be animated
* individually.
*/
class View {
public:
@@ -251,9 +253,7 @@ class AddressableLEDBuffer {
/**
* Implicit conversion to span of LED data
*/
operator std::span<wpi::AddressableLED::LEDData>() {
return m_data;
}
operator std::span<wpi::AddressableLED::LEDData>() { return m_data; }
/**
* Implicit conversion to span of const LED data
@@ -272,7 +272,8 @@ class AddressableLEDBuffer {
/**
* Creates a read/write view of this buffer.
*
* @param slice the desired slice of the buffer (e.g. 2:4), step must be unspecified or 1
* @param slice the desired slice of the buffer (e.g. 2:4), step must be
* unspecified or 1
* @return View object representing the view
* @throws std::out_of_range if the view would exceed buffer bounds
*/
@@ -282,4 +283,4 @@ class AddressableLEDBuffer {
std::vector<wpi::AddressableLED::LEDData> m_buffer;
};
} // namespace frc
} // namespace wpi

View File

@@ -1,6 +1,8 @@
#pragma once
#include <string>
#include "wpi/util/fs.hpp"
namespace robotpy::filesystem {
@@ -16,8 +18,8 @@ std::string GetOperatingDirectory();
/**
* Obtains the deploy directory of the program, which is the remote location
* the deploy directory is deployed to by default. On the robot, this is
* /home/systemcore/py/deploy. In simulation, it is where the simulation was launched
* from, in the subdirectory "deploy" (`dirname(robot.py)`/deploy).
* /home/systemcore/py/deploy. In simulation, it is where the simulation was
* launched from, in the subdirectory "deploy" (`dirname(robot.py)`/deploy).
*
* @return The result of the operating directory lookup
*/
@@ -28,6 +30,6 @@ fs::path GetOperatingDirectoryFs();
// intended to be used by C++ bindings, returns same as GetDeployDirectory
fs::path GetDeployDirectoryFs();
} // namespace robotpy::filesystem
} // namespace robotpy::filesystem
#include "Filesystem.inc"

View File

@@ -1,5 +1,9 @@
#pragma once
// TODO: this should be in a shared library, but robotpy-build does not support that
// TODO: this should be in a shared library, but robotpy-build does not support
// that
#include <string>
#include <pybind11/eval.h>
#include <semiwrap.h>
@@ -42,13 +46,17 @@ inline std::string GetOperatingDirectory() {
return GetOperatingDirectoryFs().string();
}
inline std::string GetDeployDirectory() { return GetDeployDirectoryFs().string(); }
inline std::string GetDeployDirectory() {
return GetDeployDirectoryFs().string();
}
inline fs::path GetOperatingDirectoryFs() {
static fs::path operatingPath = getMainPath();
return operatingPath;
}
inline fs::path GetDeployDirectoryFs() { return GetOperatingDirectoryFs() / "deploy"; }
inline fs::path GetDeployDirectoryFs() {
return GetOperatingDirectoryFs() / "deploy";
}
} // namespace robotpy::filesystem
} // namespace robotpy::filesystem

View File

@@ -40,7 +40,9 @@ void PyMotorControllerGroup::SetInverted(bool isInverted) {
m_isInverted = isInverted;
}
bool PyMotorControllerGroup::GetInverted() const { return m_isInverted; }
bool PyMotorControllerGroup::GetInverted() const {
return m_isInverted;
}
void PyMotorControllerGroup::Disable() {
for (auto motorController : m_motorControllers) {
@@ -51,6 +53,7 @@ void PyMotorControllerGroup::Disable() {
void PyMotorControllerGroup::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("Motor Controller");
builder.SetActuator(true);
builder.AddDoubleProperty("Value", [=, this]() { return GetThrottle(); },
[=, this](double value) { SetThrottle(value); });
builder.AddDoubleProperty(
"Value", [=, this]() { return GetThrottle(); },
[=, this](double value) { SetThrottle(value); });
}

View File

@@ -5,9 +5,8 @@
#pragma once
#include <functional>
#include <vector>
#include <memory>
#include <vector>
#include "wpi/hardware/motor/MotorController.hpp"
#include "wpi/util/sendable/Sendable.hpp"
@@ -15,12 +14,14 @@
namespace wpi {
class PyMotorControllerGroup : public wpi::util::Sendable,
public MotorController,
public wpi::util::SendableHelper<PyMotorControllerGroup> {
class PyMotorControllerGroup
: public wpi::util::Sendable,
public MotorController,
public wpi::util::SendableHelper<PyMotorControllerGroup> {
public:
PyMotorControllerGroup(std::vector<std::shared_ptr<wpi::MotorController>> &&args) :
m_motorControllers(args) {}
explicit PyMotorControllerGroup(
std::vector<std::shared_ptr<wpi::MotorController>>&& args)
: m_motorControllers(args) {}
~PyMotorControllerGroup() override = default;
PyMotorControllerGroup(PyMotorControllerGroup&&) = default;
@@ -42,4 +43,4 @@ class PyMotorControllerGroup : public wpi::util::Sendable,
std::vector<std::shared_ptr<wpi::MotorController>> m_motorControllers;
};
} // namespace rpy
} // namespace wpi

View File

@@ -6,15 +6,15 @@
#include <utility>
#include <gilsafe_object.h>
#include <pybind11/functional.h>
#include "wpi/hal/Notifier.hpp"
#include "wpi/hal/Threads.h"
#include "wpi/system/Errors.hpp"
#include "wpi/system/Timer.hpp"
#include "wpi/util/Synchronization.h"
#include <pybind11/functional.h>
#include <gilsafe_object.h>
using namespace wpi;
using namespace pybind11::literals;
@@ -100,14 +100,14 @@ PyNotifier::~PyNotifier() {
}
}
PyNotifier::PyNotifier(PyNotifier &&rhs)
PyNotifier::PyNotifier(PyNotifier&& rhs)
: m_thread(std::move(rhs.m_thread)),
m_notifier(rhs.m_notifier.load()),
m_handler(std::move(rhs.m_handler)) {
rhs.m_notifier = HAL_INVALID_HANDLE;
}
PyNotifier &PyNotifier::operator=(PyNotifier &&rhs) {
PyNotifier& PyNotifier::operator=(PyNotifier&& rhs) {
m_thread = std::move(rhs.m_thread);
m_notifier = rhs.m_notifier.load();
rhs.m_notifier = HAL_INVALID_HANDLE;

View File

@@ -13,12 +13,12 @@
#include <type_traits>
#include <utility>
#include <semiwrap.h>
#include "wpi/hal/Types.h"
#include "wpi/units/time.hpp"
#include "wpi/util/mutex.hpp"
#include <semiwrap.h>
namespace wpi {
class PyNotifier {
@@ -42,8 +42,8 @@ class PyNotifier {
*/
virtual ~PyNotifier();
PyNotifier(PyNotifier &&rhs);
PyNotifier &operator=(PyNotifier &&rhs);
PyNotifier(PyNotifier&& rhs);
PyNotifier& operator=(PyNotifier&& rhs);
/**
* Sets the name of the notifier. Used for debugging purposes only.
@@ -101,7 +101,7 @@ class PyNotifier {
*/
int32_t GetOverrun() const;
private:
private:
// The thread waiting on the HAL alarm
py::object m_thread;
@@ -115,4 +115,4 @@ private:
std::function<void()> m_handler;
};
} // namespace wpi
} // namespace wpi

View File

@@ -1,6 +1,8 @@
#include "SmartDashboardData.h"
#include <memory>
namespace rpy {
//
@@ -10,25 +12,26 @@ namespace rpy {
// All functions here must be called with the GIL held
//
static py::dict &getSmartDashboardData() {
static py::dict& getSmartDashboardData() {
static py::dict data;
return data;
}
void addSmartDashboardData(py::str &key, std::shared_ptr<wpi::util::Sendable> data) {
auto &sdData = getSmartDashboardData();
void addSmartDashboardData(py::str& key,
std::shared_ptr<wpi::util::Sendable> data) {
auto& sdData = getSmartDashboardData();
sdData[key] = py::cast(data);
}
void clearSmartDashboardData() {
auto &sdData = getSmartDashboardData();
auto& sdData = getSmartDashboardData();
if (sdData) {
sdData.clear();
}
}
void destroySmartDashboardData() {
auto &sdData = getSmartDashboardData();
auto& sdData = getSmartDashboardData();
if (sdData) {
sdData.clear();
// force the dictionary to be deleted otherwise it'll crash when libc++
@@ -40,4 +43,4 @@ void destroySmartDashboardData() {
}
}
} // namespace rpy
} // namespace rpy

View File

@@ -1,17 +1,21 @@
#pragma once
#include "wpi/util/sendable/Sendable.hpp"
#include <memory>
#include <semiwrap.h>
#include "wpi/util/sendable/Sendable.hpp"
namespace rpy {
//
// These functions must be called with the GIL held
//
void addSmartDashboardData(py::str &key, std::shared_ptr<wpi::util::Sendable> data);
void addSmartDashboardData(py::str& key,
std::shared_ptr<wpi::util::Sendable> data);
void clearSmartDashboardData();
void destroySmartDashboardData();
} // namespace rpy
} // namespace rpy