Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
./rdev.sh ci check-tag

- name: Install wpiformat
run: python -m pip install wpiformat==2026.64
run: python -m pip install wpiformat==2026.71

- name: Run wpiformat
run: wpiformat
Expand Down
10 changes: 10 additions & 0 deletions .wpiformat
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
cHeaderFileInclude {
_c\.h$
}

cppHeaderFileInclude {
(?<!_c)\.h$
\.inc$
\.inl$
}

generatedFileExclude {
.*/type_casters/
.*\.py$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ActionValue : public pybind11::object {
public:
using pybind11::object::object;

ActionValue(pybind11::object&& value)
explicit ActionValue(pybind11::object&& value)
: pybind11::object{std::move(value)} {}
};

Expand All @@ -34,8 +34,7 @@ void InitializeMockBackendValueTypes(pybind11::module_& module);
pybind11::object GetMockBackendValueType(MockBackendValueType type);

std::optional<ActionValue> GetLastValue(
const wpi::telemetry::MockTelemetryBackend& backend,
std::string_view path);
const wpi::telemetry::MockTelemetryBackend& backend, std::string_view path);

std::optional<ObjectDict> GetSchema(
const wpi::telemetry::MockTelemetryBackend& backend,
Expand All @@ -47,8 +46,7 @@ namespace pybind11::detail {

template <>
struct handle_type_name<wpi::telemetry::python::ActionValue> {
static constexpr auto name =
const_name("telemetry.mock_backend.ActionValue");
static constexpr auto name = const_name("telemetry.mock_backend.ActionValue");
};

} // namespace pybind11::detail
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
namespace pybind11::detail {

template <>
struct type_caster<
wpi::telemetry::MockTelemetryBackend::KeepDuplicatesValue> {
struct type_caster<wpi::telemetry::MockTelemetryBackend::KeepDuplicatesValue> {
using Type = wpi::telemetry::MockTelemetryBackend::KeepDuplicatesValue;

PYBIND11_TYPE_CASTER(
Type,
const_name("telemetry.mock_backend.KeepDuplicatesValue"));
Type, const_name("telemetry.mock_backend.KeepDuplicatesValue"));

bool load(handle src, bool) {
if (!src) {
Expand Down Expand Up @@ -53,8 +51,8 @@ template <>
struct type_caster<wpi::telemetry::MockTelemetryBackend::SetPropertyValue> {
using Type = wpi::telemetry::MockTelemetryBackend::SetPropertyValue;

PYBIND11_TYPE_CASTER(
Type, const_name("telemetry.mock_backend.SetPropertyValue"));
PYBIND11_TYPE_CASTER(Type,
const_name("telemetry.mock_backend.SetPropertyValue"));

bool load(handle src, bool) {
if (!src) {
Expand Down Expand Up @@ -91,8 +89,8 @@ template <>
struct type_caster<wpi::telemetry::MockTelemetryBackend::LogStringValue> {
using Type = wpi::telemetry::MockTelemetryBackend::LogStringValue;

PYBIND11_TYPE_CASTER(
Type, const_name("telemetry.mock_backend.LogStringValue"));
PYBIND11_TYPE_CASTER(Type,
const_name("telemetry.mock_backend.LogStringValue"));

bool load(handle src, bool) {
if (!src) {
Expand Down Expand Up @@ -126,13 +124,11 @@ struct type_caster<wpi::telemetry::MockTelemetryBackend::LogStringValue> {
};

template <>
struct type_caster<
wpi::telemetry::MockTelemetryBackend::LogBooleanArrayValue> {
struct type_caster<wpi::telemetry::MockTelemetryBackend::LogBooleanArrayValue> {
using Type = wpi::telemetry::MockTelemetryBackend::LogBooleanArrayValue;

PYBIND11_TYPE_CASTER(
Type,
const_name("telemetry.mock_backend.LogBooleanArrayValue"));
Type, const_name("telemetry.mock_backend.LogBooleanArrayValue"));

bool load(handle src, bool) {
if (!src) {
Expand Down Expand Up @@ -176,8 +172,7 @@ template <>
struct type_caster<wpi::telemetry::MockTelemetryBackend::LogRawValue> {
using Type = wpi::telemetry::MockTelemetryBackend::LogRawValue;

PYBIND11_TYPE_CASTER(
Type, const_name("telemetry.mock_backend.LogRawValue"));
PYBIND11_TYPE_CASTER(Type, const_name("telemetry.mock_backend.LogRawValue"));

bool load(handle src, bool) {
if (!src) {
Expand Down Expand Up @@ -220,8 +215,7 @@ template <>
struct type_caster<wpi::telemetry::MockTelemetryBackend::Action> {
using Type = wpi::telemetry::MockTelemetryBackend::Action;

static constexpr auto name =
const_name("telemetry.mock_backend.Action");
static constexpr auto name = const_name("telemetry.mock_backend.Action");

static handle cast(const Type& src, return_value_policy, handle) {
object cls = wpi::telemetry::python::GetMockBackendValueType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ class PyTelemetryTable {
* bytearray, and memoryview). Wrap other buffer exporters in memoryview to
* explicitly log their raw bytes in C order.
*/
void Log(
std::string_view name, pybind11::object value,
pybind11::typing::Optional<pybind11::typing::Type<pybind11::object>>
elementType = pybind11::none(),
std::string_view typeString = "") const;
void Log(std::string_view name, pybind11::object value,
pybind11::typing::Optional<pybind11::typing::Type<pybind11::object>>
elementType = pybind11::none(),
std::string_view typeString = "") const;

private:
using ElementType = pybind11::typing::Type<pybind11::object>;
Expand Down Expand Up @@ -123,8 +122,7 @@ class PyTelemetryTable {
void LogSequence(std::string_view name, const pybind11::sequence& value,
pybind11::handle valueType) const;
void LogStruct(std::string_view name, pybind11::handle value) const;
void LogStructSequence(std::string_view name,
const pybind11::sequence& value,
void LogStructSequence(std::string_view name, const pybind11::sequence& value,
const pybind11::type& type) const;
void LogStructSequenceImpl(
const wpi::telemetry::TelemetryTable::EntryHandle& entry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ PyTelemetryTable GetTable(std::string_view name = "");
* bytearray, and memoryview). Wrap other buffer exporters in memoryview to
* explicitly log their raw bytes in C order.
*/
void Log(
std::string_view name, pybind11::object value,
pybind11::typing::Optional<pybind11::typing::Type<pybind11::object>>
elementType = pybind11::none(),
std::string_view typeString = "");
void Log(std::string_view name, pybind11::object value,
pybind11::typing::Optional<pybind11::typing::Type<pybind11::object>>
elementType = pybind11::none(),
std::string_view typeString = "");

/**
* Indicates duplicate values should be preserved. Normally duplicate values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace wpi::tunables::python {

using RawValue = pybind11::typing::Union<
pybind11::bytes, pybind11::bytearray, pybind11::memoryview,
pybind11::typing::Iterable<int>>;
using RawValue = pybind11::typing::Union<pybind11::bytes, pybind11::bytearray,
pybind11::memoryview,
pybind11::typing::Iterable<int>>;
using StructIterable = pybind11::typing::Iterable<pybind11::object>;

void SetRaw(wpi::tunables::MockTunableBackend& self, std::string_view path,
Expand All @@ -24,29 +24,29 @@ void SetStruct(wpi::tunables::MockTunableBackend& self, std::string_view path,
pybind11::handle value);
void SetStructVector(wpi::tunables::MockTunableBackend& self,
std::string_view path, StructIterable value);
void SetBoolVector(
wpi::tunables::MockTunableBackend& self, std::string_view path,
pybind11::typing::Iterable<bool> value);
void SetInt32Vector(
wpi::tunables::MockTunableBackend& self, std::string_view path,
pybind11::typing::Iterable<int32_t> value);
void SetInt64Vector(
wpi::tunables::MockTunableBackend& self, std::string_view path,
pybind11::typing::Iterable<int64_t> value);
void SetFloatVector(
wpi::tunables::MockTunableBackend& self, std::string_view path,
pybind11::typing::Iterable<float> value);
void SetDoubleVector(
wpi::tunables::MockTunableBackend& self, std::string_view path,
pybind11::typing::Iterable<double> value);
void SetStringVector(
wpi::tunables::MockTunableBackend& self, std::string_view path,
pybind11::typing::Iterable<std::string> value);

std::optional<uint32_t> GetUid(
const wpi::tunables::MockTunableBackend& self, std::string_view path);

pybind11::object GetTunableValue(
const wpi::tunables::MockTunableBackend& self, std::string_view path);
void SetBoolVector(wpi::tunables::MockTunableBackend& self,
std::string_view path,
pybind11::typing::Iterable<bool> value);
void SetInt32Vector(wpi::tunables::MockTunableBackend& self,
std::string_view path,
pybind11::typing::Iterable<int32_t> value);
void SetInt64Vector(wpi::tunables::MockTunableBackend& self,
std::string_view path,
pybind11::typing::Iterable<int64_t> value);
void SetFloatVector(wpi::tunables::MockTunableBackend& self,
std::string_view path,
pybind11::typing::Iterable<float> value);
void SetDoubleVector(wpi::tunables::MockTunableBackend& self,
std::string_view path,
pybind11::typing::Iterable<double> value);
void SetStringVector(wpi::tunables::MockTunableBackend& self,
std::string_view path,
pybind11::typing::Iterable<std::string> value);

std::optional<uint32_t> GetUid(const wpi::tunables::MockTunableBackend& self,
std::string_view path);

pybind11::object GetTunableValue(const wpi::tunables::MockTunableBackend& self,
std::string_view path);

} // namespace wpi::tunables::python
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class PyComplexTunableAdapter
std::string m_type;
mutable std::vector<std::pair<std::string, std::shared_ptr<PyTunable>>>
m_values;
std::vector<
std::pair<std::string, std::shared_ptr<PyComplexTunableAdapter>>>
std::vector<std::pair<std::string, std::shared_ptr<PyComplexTunableAdapter>>>
m_complex;
std::vector<std::pair<std::string, pybind11::object>> m_nativeComplex;
};
Expand Down
66 changes: 28 additions & 38 deletions subprojects/robotpy-tunables/tunables/src/rpy/PyTunable.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ namespace wpi::tunables::python {
class PyTunable : public std::enable_shared_from_this<PyTunable> {
public:
using Getter = pybind11::typing::Callable<pybind11::object()>;
using Setter =
pybind11::typing::Callable<void(pybind11::object)>;
using TuneCallback =
pybind11::typing::Callable<void(pybind11::object)>;
using Setter = pybind11::typing::Callable<void(pybind11::object)>;
using TuneCallback = pybind11::typing::Callable<void(pybind11::object)>;
using PythonType = pybind11::typing::Type<pybind11::object>;
using Properties =
pybind11::typing::Dict<pybind11::str, pybind11::object>;
using Properties = pybind11::typing::Dict<pybind11::str, pybind11::object>;

/**
* Creates an unpublished tunable. The tunable type is inferred from value
Expand All @@ -43,7 +40,8 @@ class PyTunable : public std::enable_shared_from_this<PyTunable> {
*
* @param value initial value
* @param getter optional function that supplies the current local value
* @param setter optional function that receives values set locally or remotely
* @param setter optional function that receives values set locally or
* remotely
* @param onTune callback that receives the value after a remote update
* @param robust whether to separately echo a remotely set value
* @param isMutable whether remote updates may change the tunable
Expand All @@ -53,16 +51,16 @@ class PyTunable : public std::enable_shared_from_this<PyTunable> {
* @param typeString custom tunable type string
* @param alwaysGet whether to call getter on every backend update
*/
PyTunable(pybind11::object value,
std::optional<Getter> getter = std::nullopt,
std::optional<Setter> setter = std::nullopt,
std::optional<TuneCallback> onTune = std::nullopt,
bool robust = false, bool isMutable = true,
pybind11::typing::Optional<PythonType> valueType = pybind11::none(),
pybind11::typing::Optional<PythonType> elementType = pybind11::none(),
std::optional<Properties> properties = std::nullopt,
std::string typeString = "", bool alwaysGet = false,
bool narrowScalar = false);
PyTunable(
pybind11::object value, std::optional<Getter> getter = std::nullopt,
std::optional<Setter> setter = std::nullopt,
std::optional<TuneCallback> onTune = std::nullopt, bool robust = false,
bool isMutable = true,
pybind11::typing::Optional<PythonType> valueType = pybind11::none(),
pybind11::typing::Optional<PythonType> elementType = pybind11::none(),
std::optional<Properties> properties = std::nullopt,
std::string typeString = "", bool alwaysGet = false,
bool narrowScalar = false);

wpi::tunables::detail::TunableBase& GetBase();

Expand Down Expand Up @@ -102,32 +100,25 @@ class PyTunable : public std::enable_shared_from_this<PyTunable> {
private:
class CallbackOwner;

using TunableVariant =
std::variant<wpi::tunables::TunableBool,
wpi::tunables::TunableInt32,
wpi::tunables::TunableInt64,
wpi::tunables::TunableFloat,
wpi::tunables::TunableDouble,
wpi::tunables::TunableString,
wpi::tunables::TunableRaw,
wpi::tunables::TunableBoolVector,
wpi::tunables::TunableInt64Vector,
wpi::tunables::TunableDoubleVector,
wpi::tunables::TunableStringVector,
wpi::tunables::Tunable<WPyStruct, WPyStructInfo>,
wpi::tunables::Tunable<std::vector<WPyStruct>,
WPyStructInfo>>;
using TunableVariant = std::variant<
wpi::tunables::TunableBool, wpi::tunables::TunableInt32,
wpi::tunables::TunableInt64, wpi::tunables::TunableFloat,
wpi::tunables::TunableDouble, wpi::tunables::TunableString,
wpi::tunables::TunableRaw, wpi::tunables::TunableBoolVector,
wpi::tunables::TunableInt64Vector, wpi::tunables::TunableDoubleVector,
wpi::tunables::TunableStringVector,
wpi::tunables::Tunable<WPyStruct, WPyStructInfo>,
wpi::tunables::Tunable<std::vector<WPyStruct>, WPyStructInfo>>;

template <typename T>
static bool CachedValuesEqual(const T& lhs, const T& rhs);

template <typename T>
static constexpr bool IsStructCachedValue =
std::same_as<T, WPyStruct> ||
std::same_as<T, std::vector<WPyStruct>>;
std::same_as<T, WPyStruct> || std::same_as<T, std::vector<WPyStruct>>;

static std::vector<uint8_t> PackStructValue(const WPyStruct& value,
const WPyStructInfo& info);
const WPyStructInfo& info);

template <typename T>
static std::optional<std::vector<uint8_t>> PackStructData(const T&);
Expand All @@ -146,9 +137,8 @@ class PyTunable : public std::enable_shared_from_this<PyTunable> {
std::optional<std::vector<uint8_t>> PackCachedStructData() const;

wpi::tunables::TunableConfig MakeConfig(
bool robust, bool isMutable,
const std::optional<Properties>& properties, std::string typeString,
bool alwaysGet);
bool robust, bool isMutable, const std::optional<Properties>& properties,
std::string typeString, bool alwaysGet);
TunableVariant MakeValue(
pybind11::handle value, bool robust, bool isMutable,
const pybind11::typing::Optional<PythonType>& valueType,
Expand Down
Loading
Loading