Skip to content

Commit 02169a1

Browse files
committed
Add more documentation
1 parent f5a66ee commit 02169a1

File tree

3 files changed

+258
-115
lines changed

3 files changed

+258
-115
lines changed

robotpy_build/hooks_datacfg.py

+58-39
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,68 @@
66
import enum
77
from typing import Dict, List, Tuple, Optional
88

9-
from pydantic import BaseModel, validator
10-
11-
12-
class Model(BaseModel):
13-
class Config:
14-
extra = "forbid"
9+
from pydantic import validator
10+
from .util import Model, _generating_documentation
1511

1612

1713
class ParamData(Model):
1814
"""Various ways to modify parameters"""
1915

20-
# Rename parameter
16+
#: Set parameter name to this
2117
name: Optional[str] = None
2218

23-
# C++ type emitted
19+
#: Change C++ type emitted
2420
x_type: Optional[str] = None
2521

26-
# Default value for parameter
22+
#: Default value for parameter
2723
default: Optional[str] = None
2824

25+
#: Force this to be an 'out' parameter
26+
#:
27+
#: .. seealso:: :ref:`autowrap_out_params`
28+
#:
2929
force_out: bool = False
3030

31+
#: Force an array size
3132
array_size: Optional[int] = None
3233

34+
#: Ignore this parameter
3335
ignore: bool = False
3436

3537

3638
class BufferType(str, enum.Enum):
39+
40+
#: The buffer must indicate that it is readable (such as bytes, or bytearray)
3741
IN = "in"
42+
43+
#: The buffer must indicate that it is writeable (such as a bytearray)
3844
OUT = "out"
45+
46+
#: The buffer must indicate that it readable or writeable (such as a bytearray)
3947
INOUT = "inout"
4048

4149

4250
class BufferData(Model):
43-
"""Describes buffers"""
4451

45-
# Indicates what type of buffer is required: out/inout buffers require
46-
# a writeable buffer such as a bytearray, but in only needs a readonly
47-
# buffer (such as bytes)
52+
#: Indicates what type of python buffer is required
4853
type: BufferType
4954

50-
# Name of source parameter -- user must pass in something that implements
51-
# the buffer protocol (eg bytes, bytearray)
55+
#: Name of C++ parameter that the buffer will use
5256
src: str
5357

54-
# Name of length parameter. An out-only parameter, it will be set to the size
55-
# of the src buffer, and will be returned so the caller can determine how
56-
# many bytes were written
58+
#: Name of the C++ length parameter. An out-only parameter, it will be set
59+
#: to the size of the python buffer, and will be returned so the caller can
60+
#: determine how many bytes were written
5761
len: str
5862

59-
# If specified, the minimum size of the passed in buffer
63+
#: If specified, the minimum size of the python buffer
6064
minsz: Optional[int] = None
6165

6266

6367
class ReturnValuePolicy(enum.Enum):
6468
"""
65-
see pybind11 documentation for this
69+
See `pybind11 documentation <https://pybind11.readthedocs.io/en/stable/advanced/functions.html#return-value-policies>`_
70+
for what each of these values mean.
6671
"""
6772

6873
TAKE_OWNERSHIP = "take_ownership"
@@ -75,37 +80,42 @@ class ReturnValuePolicy(enum.Enum):
7580

7681

7782
class FunctionData(Model):
78-
# If True, don't wrap this
83+
"""
84+
85+
86+
"""
87+
88+
#: If True, don't wrap this
7989
ignore: bool = False
8090

81-
# If True, don't wrap this, but provide a pure virtual implementation
82-
# -> in theory we could autodetect this, but sometimes ignore
83-
# is used for when CppHeaderParser totally blows it
91+
#: If True, don't wrap this, but provide a pure virtual implementation
8492
ignore_pure: bool = False
8593

86-
# Generate this in an `#ifdef`
94+
#: Generate this in an `#ifdef`
8795
ifdef: Optional[str] = None
88-
# Generate this in an `#ifndef`
96+
#: Generate this in an `#ifndef`
8997
ifndef: Optional[str] = None
9098

91-
# Use this code instead of the generated code
99+
#: Use this code instead of the generated code
92100
cpp_code: Optional[str] = None
93101

94-
# Docstring for the function
102+
#: Docstring for the function
95103
doc: Optional[str] = None
96104

97-
# If True, prepends an underscore to the python name
105+
#: If True, prepends an underscore to the python name
98106
internal: bool = False
99107

100-
# Set this to rename the function
108+
#: Use this to set the name of the function as exposed to python
101109
rename: Optional[str] = None
102110

103-
# Mechanism to override individual parameters
111+
#: Mechanism to override individual parameters
104112
param_override: Dict[str, ParamData] = {}
105113

106114
#: If specified, put the function in a sub.pack.age
107115
subpackage: Optional[str] = None
108116

117+
#: By default, robotpy-build will release the GIL whenever a wrapped
118+
#: function is called.
109119
no_release_gil: Optional[bool] = None
110120

111121
buffers: List[BufferData] = []
@@ -133,7 +143,8 @@ def validate_overloads(cls, value):
133143
return value
134144

135145

136-
FunctionData.update_forward_refs()
146+
if not _generating_documentation:
147+
FunctionData.update_forward_refs()
137148

138149

139150
class PropAccess(enum.Enum):
@@ -154,9 +165,11 @@ class PropAccess(enum.Enum):
154165

155166

156167
class PropData(Model):
168+
169+
#: If set to True, this property is not made available to python
157170
ignore: bool = False
158171

159-
#: Set the name of this property to the specified value
172+
#: Set the python name of this property to the specified string
160173
rename: Optional[str]
161174

162175
#: Python code access to this property
@@ -167,7 +180,11 @@ class PropData(Model):
167180

168181

169182
class EnumValue(Model):
183+
184+
#: If set to True, this property is not made available to python
170185
ignore: bool = False
186+
187+
#: Set the python name of this enum value to the specified string
171188
rename: Optional[str] = None
172189

173190
#: Docstring for the enum value
@@ -176,11 +193,15 @@ class EnumValue(Model):
176193

177194
class EnumData(Model):
178195

179-
# Docstring for the enum
196+
#: Set your own docstring for the enum
180197
doc: Optional[str] = None
181198

199+
#: If set to True, this property is not made available to python
182200
ignore: bool = False
201+
202+
#: Set the python name of this enum to the specified string
183203
rename: Optional[str] = None
204+
184205
value_prefix: Optional[str] = None
185206

186207
#: If specified, put the enum in a sub.pack.age (ignored for
@@ -198,7 +219,7 @@ class ClassData(Model):
198219
ignore: bool = False
199220
ignored_bases: List[str] = []
200221

201-
# Specify fully qualified names for the bases
222+
#: Specify fully qualified names for the bases
202223
base_qualnames: Dict[str, str] = {}
203224

204225
attributes: Dict[str, PropData] = {}
@@ -281,14 +302,12 @@ def validate_methods(cls, value):
281302

282303
class TemplateData(Model):
283304

284-
# Fully qualified name of template
305+
#: Fully qualified name of template
285306
qualname: str
286307

287-
# Template parameters to use
308+
#: Template parameters to use
288309
params: List[str]
289310

290-
# TODO: other parameters useful for concrete types
291-
292311

293312
class HooksDataYaml(Model):
294313
"""

0 commit comments

Comments
 (0)