Skip to content

Commit 20a5e30

Browse files
committed
Remove pydantic and switch to dataclasses/validobj
1 parent 5b4bd49 commit 20a5e30

File tree

13 files changed

+276
-210
lines changed

13 files changed

+276
-210
lines changed

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies = [
2828
"setuptools >= 45",
2929
"setuptools_scm >= 6.2, < 8",
3030
"sphinxify >= 0.7.3",
31-
"pydantic >= 1.7.0, < 2, != 1.10.20",
31+
"validobj ~= 1.2",
3232
"cxxheaderparser[pcpp] ~= 1.4.1",
3333
"tomli",
3434
"tomli_w",

Diff for: robotpy_build/autowrap/context.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ class TemplateInstanceContext:
494494
full_cpp_name_identifier: str
495495
binder_typename: str
496496

497-
params: typing.List[str]
497+
params: typing.List[typing.Union[int, str]]
498498

499499
header_name: str
500500

Diff for: robotpy_build/autowrap/cxxparser.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ def _gen_int_types():
115115

116116

117117
_rvp_map = {
118-
ReturnValuePolicy.TAKE_OWNERSHIP: "py::return_value_policy::take_ownership",
119-
ReturnValuePolicy.COPY: "py::return_value_policy::copy",
120-
ReturnValuePolicy.MOVE: "py::return_value_policy::move",
121-
ReturnValuePolicy.REFERENCE: "py::return_value_policy::reference",
122-
ReturnValuePolicy.REFERENCE_INTERNAL: "py::return_value_policy::reference_internal",
123-
ReturnValuePolicy.AUTOMATIC: "",
124-
ReturnValuePolicy.AUTOMATIC_REFERENCE: "py::return_value_policy::automatic_reference",
118+
ReturnValuePolicy.take_ownership: "py::return_value_policy::take_ownership",
119+
ReturnValuePolicy.copy: "py::return_value_policy::copy",
120+
ReturnValuePolicy.move: "py::return_value_policy::move",
121+
ReturnValuePolicy.reference: "py::return_value_policy::reference",
122+
ReturnValuePolicy.reference_internal: "py::return_value_policy::reference_internal",
123+
ReturnValuePolicy.automatic: "",
124+
ReturnValuePolicy.automatic_reference: "py::return_value_policy::automatic_reference",
125125
}
126126

127127
# fmt: off
@@ -938,7 +938,7 @@ def _on_class_field(
938938
else:
939939
py_name = prop_name
940940

941-
if propdata.access == PropAccess.AUTOMATIC:
941+
if propdata.access == PropAccess.auto:
942942
# const variables can't be written
943943
if f.constexpr or getattr(f.type, "const", False):
944944
prop_readonly = True
@@ -949,7 +949,7 @@ def _on_class_field(
949949
else:
950950
prop_readonly = _is_prop_readonly(f.type)
951951
else:
952-
prop_readonly = propdata.access == PropAccess.READONLY
952+
prop_readonly = propdata.access == PropAccess.readonly
953953

954954
doc = self._process_doc(f.doxygen, propdata)
955955

@@ -2038,7 +2038,8 @@ def parse_header(
20382038
break
20392039

20402040
for param in tmpl_data.params:
2041-
visitor._add_user_type_caster(param)
2041+
if isinstance(param, str):
2042+
visitor._add_user_type_caster(param)
20422043

20432044
# User typealias additions
20442045
visitor._extract_typealias(user_cfg.typealias, hctx.user_typealias, set())

Diff for: robotpy_build/autowrap/generator_data.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
AutowrapConfigYaml,
77
PropData,
88
FunctionData,
9+
OverloadData,
910
)
1011
from .context import OverloadTracker
1112

@@ -40,6 +41,23 @@ class ClsReportData:
4041
functions: FnMissingData = dataclasses.field(default_factory=dict)
4142

4243

44+
def _merge_overload(data: FunctionData, overload: OverloadData) -> FunctionData:
45+
# merge overload information
46+
# - create a dictionary that contains things that haven't changed
47+
changes = {"overloads": {}}
48+
for f in dataclasses.fields(OverloadData):
49+
v = getattr(overload, f.name)
50+
if f.default_factory is not dataclasses.MISSING:
51+
default = f.default_factory()
52+
else:
53+
default = f.default
54+
55+
if v != default:
56+
changes[f.name] = v
57+
58+
return dataclasses.replace(data, **changes)
59+
60+
4361
class GeneratorData:
4462
"""
4563
Used by the hooks to retrieve user-specified generation data, and
@@ -141,11 +159,7 @@ def get_function_data(
141159
overload = data.overloads.get(signature)
142160
missing = overload is None
143161
if not missing and overload:
144-
# merge overload information
145-
data = data.dict(exclude_unset=True)
146-
del data["overloads"]
147-
data.update(overload.dict(exclude_unset=True))
148-
data = FunctionData(**data)
162+
data = _merge_overload(data, overload)
149163
report_data.overloads[signature] = is_private or not missing
150164

151165
report_data.tracker.add_overload()

Diff for: robotpy_build/autowrap/render_tmpl_inst.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def render_template_inst_cpp(
1010
r = RenderBuffer()
1111
render_class_prologue(r, hctx)
1212

13-
tmpl_params = ", ".join(tmpl_data.params)
13+
tmpl_params = ", ".join(str(p) for p in tmpl_data.params)
1414

1515
r.write_trim(
1616
f"""

0 commit comments

Comments
 (0)