mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[robotpy] Mirror most other subprojects (#8208)
GitOrigin-RevId: ac60fd3cf4a24023184376687da28373d14b781a This mirrors the robotpy files for the following projects: - apriltag - datalog - hal - ntcore - romiVendordep - wpilibc - wpimath - xrpVendordep This excludes cscore and the halsim wrappers for at this time. NOTE: This does not hook these projects up to the build system, just simply mirrors the files. The building will take place in a follow up PR to make it easier to review the changes necessary to build.
This commit is contained in:
64
ntcore/src/main/python/devtools/gen-pubsub.py
Executable file
64
ntcore/src/main/python/devtools/gen-pubsub.py
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sphinxify
|
||||
from cxxheaderparser.simple import parse_string
|
||||
from cxxheaderparser.tokfmt import tokfmt
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("ntcore/include/ntcore_cpp.h") as fp:
|
||||
data = parse_string(fp.read())
|
||||
|
||||
for c in data.namespace.namespaces["nt"].classes:
|
||||
if c.class_decl.typename.format() == "struct PubSubOptions":
|
||||
params = []
|
||||
docs = []
|
||||
|
||||
for f in c.fields:
|
||||
if f.static or f.name == "structSize":
|
||||
continue
|
||||
|
||||
if f.type.format() == "NT_Publisher":
|
||||
params.append(
|
||||
(
|
||||
"std::optional<std::shared_ptr<nt::Publisher>>",
|
||||
f.name,
|
||||
f"{f.name}.has_value() ? {f.name}.value()->GetHandle() : {f.value.format()}",
|
||||
"std::nullopt",
|
||||
)
|
||||
)
|
||||
else:
|
||||
v = f.value.format()
|
||||
if v == "kDefaultPeriodic":
|
||||
v = f"nt::PubSubOptions::{v}"
|
||||
params.append((f.type, f.name, f.name, v))
|
||||
|
||||
if f.doxygen:
|
||||
docs.append(f"@param {f.name} {f.doxygen}")
|
||||
|
||||
paramstr = ",\n ".join(f"{t.format()} {n}" for t, n, _, _ in params)
|
||||
args = ",\n ".join(f'py::arg("{n}") = {v}' for _, n, _, v in params)
|
||||
options = ",\n ".join(f".{fn} = {n}" for _, fn, n, _ in params)
|
||||
|
||||
doc = "\n ".join(
|
||||
sphinxify.process_raw("\n".join(docs)).splitlines()
|
||||
)
|
||||
|
||||
print(
|
||||
f"""
|
||||
// autogenerated by gen-pubsub.py
|
||||
.def(py::init([](
|
||||
{paramstr}
|
||||
) -> nt::PubSubOptions {{
|
||||
return nt::PubSubOptions{{
|
||||
{options}
|
||||
}};
|
||||
}}),
|
||||
py::kw_only(),
|
||||
{args},
|
||||
R"(
|
||||
{doc}
|
||||
)"
|
||||
)
|
||||
|
||||
"""
|
||||
)
|
||||
Reference in New Issue
Block a user