Skip to content

Commit eee12ee

Browse files
committed
Show as table
1 parent b91d380 commit eee12ee

File tree

2 files changed

+246
-62
lines changed

2 files changed

+246
-62
lines changed

docs/source/ProtobufStructures.rst

Lines changed: 213 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,20 @@ SimulatorTableData
3333

3434
**Repeated Fields:**
3535

36-
* ``compdat`` (list[SimulatorCompdatEntry])
37-
* ``welspecs`` (list[SimulatorWelspecsEntry])
36+
.. list-table::
37+
:header-rows: 1
38+
:widths: 30 20 50
39+
40+
* - Field
41+
- Type
42+
- Description
43+
* - ``compdat``
44+
- ``list[SimulatorCompdatEntry]``
45+
-
46+
* - ``welspecs``
47+
- ``list[SimulatorWelspecsEntry]``
48+
-
49+
3850

3951

4052
SimulatorCompdatEntry
@@ -44,25 +56,73 @@ SimulatorCompdatEntry
4456

4557
**Attributes:**
4658

47-
* ``well_name`` (str)
48-
* ``grid_i`` (int)
49-
* ``grid_j`` (int)
50-
* ``upper_k`` (int)
51-
* ``lower_k`` (int)
52-
* ``open_shut_flag`` (str)
59+
.. list-table::
60+
:header-rows: 1
61+
:widths: 30 20 50
62+
63+
* - Field
64+
- Type
65+
- Description
66+
* - ``well_name``
67+
- ``str``
68+
-
69+
* - ``grid_i``
70+
- ``int``
71+
-
72+
* - ``grid_j``
73+
- ``int``
74+
-
75+
* - ``upper_k``
76+
- ``int``
77+
-
78+
* - ``lower_k``
79+
- ``int``
80+
-
81+
* - ``open_shut_flag``
82+
- ``str``
83+
-
84+
5385

5486
**Optional Attributes:**
5587

56-
* ``saturation`` (float | None)
57-
* ``transmissibility`` (float | None)
58-
* ``diameter`` (float | None)
59-
* ``kh`` (float | None)
60-
* ``skin_factor`` (float | None)
61-
* ``d_factor`` (float | None)
62-
* ``direction`` (str | None)
63-
* ``start_md`` (float | None)
64-
* ``end_md`` (float | None)
65-
* ``comment`` (str | None)
88+
.. list-table::
89+
:header-rows: 1
90+
:widths: 30 20 50
91+
92+
* - Field
93+
- Type
94+
- Description
95+
* - ``saturation``
96+
- ``float | None``
97+
-
98+
* - ``transmissibility``
99+
- ``float | None``
100+
-
101+
* - ``diameter``
102+
- ``float | None``
103+
-
104+
* - ``kh``
105+
- ``float | None``
106+
-
107+
* - ``skin_factor``
108+
- ``float | None``
109+
-
110+
* - ``d_factor``
111+
- ``float | None``
112+
-
113+
* - ``direction``
114+
- ``str | None``
115+
-
116+
* - ``start_md``
117+
- ``float | None``
118+
-
119+
* - ``end_md``
120+
- ``float | None``
121+
-
122+
* - ``comment``
123+
- ``str | None``
124+
-
125+
66126

67127

68128
SimulatorWelspecsEntry
@@ -72,22 +132,64 @@ SimulatorWelspecsEntry
72132

73133
**Attributes:**
74134

75-
* ``well_name`` (str)
76-
* ``group_name`` (str)
77-
* ``grid_i`` (int)
78-
* ``grid_j`` (int)
79-
* ``phase`` (str)
135+
.. list-table::
136+
:header-rows: 1
137+
:widths: 30 20 50
138+
139+
* - Field
140+
- Type
141+
- Description
142+
* - ``well_name``
143+
- ``str``
144+
-
145+
* - ``group_name``
146+
- ``str``
147+
-
148+
* - ``grid_i``
149+
- ``int``
150+
-
151+
* - ``grid_j``
152+
- ``int``
153+
-
154+
* - ``phase``
155+
- ``str``
156+
-
157+
80158

81159
**Optional Attributes:**
82160

83-
* ``bhp_depth`` (float | None)
84-
* ``drainage_radius`` (float | None)
85-
* ``inflow_equation`` (str | None)
86-
* ``auto_shut_in`` (str | None)
87-
* ``cross_flow`` (str | None)
88-
* ``pvt_num`` (int | None)
89-
* ``hydrostatic_density_calc`` (str | None)
90-
* ``fip_region`` (int | None)
161+
.. list-table::
162+
:header-rows: 1
163+
:widths: 30 20 50
164+
165+
* - Field
166+
- Type
167+
- Description
168+
* - ``bhp_depth``
169+
- ``float | None``
170+
-
171+
* - ``drainage_radius``
172+
- ``float | None``
173+
-
174+
* - ``inflow_equation``
175+
- ``str | None``
176+
-
177+
* - ``auto_shut_in``
178+
- ``str | None``
179+
-
180+
* - ``cross_flow``
181+
- ``str | None``
182+
-
183+
* - ``pvt_num``
184+
- ``int | None``
185+
-
186+
* - ``hydrostatic_density_calc``
187+
- ``str | None``
188+
-
189+
* - ``fip_region``
190+
- ``int | None``
191+
-
192+
91193

92194

93195
SimulatorTableRequest
@@ -97,8 +199,20 @@ SimulatorTableRequest
97199

98200
**Attributes:**
99201

100-
* ``wellpath_name`` (str)
101-
* ``case_id`` (int)
202+
.. list-table::
203+
:header-rows: 1
204+
:widths: 30 20 50
205+
206+
* - Field
207+
- Type
208+
- Description
209+
* - ``wellpath_name``
210+
- ``str``
211+
-
212+
* - ``case_id``
213+
- ``int``
214+
-
215+
102216

103217

104218
Vec3d
@@ -108,9 +222,23 @@ Vec3d
108222

109223
**Attributes:**
110224

111-
* ``x`` (float)
112-
* ``y`` (float)
113-
* ``z`` (float)
225+
.. list-table::
226+
:header-rows: 1
227+
:widths: 30 20 50
228+
229+
* - Field
230+
- Type
231+
- Description
232+
* - ``x``
233+
- ``float``
234+
-
235+
* - ``y``
236+
- ``float``
237+
-
238+
* - ``z``
239+
- ``float``
240+
-
241+
114242

115243

116244
Vec3i
@@ -120,9 +248,23 @@ Vec3i
120248

121249
**Attributes:**
122250

123-
* ``i`` (int)
124-
* ``j`` (int)
125-
* ``k`` (int)
251+
.. list-table::
252+
:header-rows: 1
253+
:widths: 30 20 50
254+
255+
* - Field
256+
- Type
257+
- Description
258+
* - ``i``
259+
- ``int``
260+
-
261+
* - ``j``
262+
- ``int``
263+
-
264+
* - ``k``
265+
- ``int``
266+
-
267+
126268

127269

128270
CellCenters
@@ -139,14 +281,38 @@ CellCorners
139281

140282
**Attributes:**
141283

142-
* ``c0`` (Vec3d)
143-
* ``c1`` (Vec3d)
144-
* ``c2`` (Vec3d)
145-
* ``c3`` (Vec3d)
146-
* ``c4`` (Vec3d)
147-
* ``c5`` (Vec3d)
148-
* ``c6`` (Vec3d)
149-
* ``c7`` (Vec3d)
284+
.. list-table::
285+
:header-rows: 1
286+
:widths: 30 20 50
287+
288+
* - Field
289+
- Type
290+
- Description
291+
* - ``c0``
292+
- ``Vec3d``
293+
-
294+
* - ``c1``
295+
- ``Vec3d``
296+
-
297+
* - ``c2``
298+
- ``Vec3d``
299+
-
300+
* - ``c3``
301+
- ``Vec3d``
302+
-
303+
* - ``c4``
304+
- ``Vec3d``
305+
-
306+
* - ``c5``
307+
- ``Vec3d``
308+
-
309+
* - ``c6``
310+
- ``Vec3d``
311+
-
312+
* - ``c7``
313+
- ``Vec3d``
314+
-
315+
150316

151317

152318
Complete Structure Reference

docs/source/generate_protobuf_docs.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -424,39 +424,57 @@ def _format_message(self, msg: ProtoMessage, file_key: str, is_important: bool)
424424

425425
if required_fields:
426426
content += "**Attributes:**\n\n"
427-
for field in required_fields:
428-
content += self._format_field(field)
427+
content += self._format_fields_table(required_fields)
429428

430429
if repeated_fields:
431430
# Add newline separator only if there were previous fields
432431
if required_fields:
433432
content += "\n"
434433
content += "**Repeated Fields:**\n\n"
435-
for field in repeated_fields:
436-
content += self._format_field(field)
434+
content += self._format_fields_table(repeated_fields)
437435

438436
if optional_fields:
439437
# Add newline separator only if there were previous fields
440438
if required_fields or repeated_fields:
441439
content += "\n"
442440
content += "**Optional Attributes:**\n\n"
443-
for field in optional_fields:
444-
content += self._format_field(field)
441+
content += self._format_fields_table(optional_fields)
445442

446443
content += "\n"
447444
return content
448445

449-
def _format_field(self, field: Dict) -> str:
450-
"""Format a field as RST."""
451-
python_type = self.TYPE_MAP.get(field['type'], field['type'])
446+
def _format_fields_table(self, fields: List[Dict]) -> str:
447+
"""Format fields as an RST table."""
448+
if not fields:
449+
return ""
452450

453-
if field['modifier'] == 'repeated':
454-
python_type = f"list[{python_type}]"
455-
elif field['modifier'] == 'optional':
456-
python_type = f"{python_type} | None"
451+
# Create table header
452+
content = ".. list-table::\n"
453+
content += " :header-rows: 1\n"
454+
content += " :widths: 30 20 50\n\n"
455+
content += " * - Field\n"
456+
content += " - Type\n"
457+
content += " - Description\n"
457458

458-
desc = f" - {field['description']}" if field['description'] else ""
459-
return f"* ``{field['name']}`` ({python_type}){desc}\n"
459+
# Add each field as a table row
460+
for field in fields:
461+
python_type = self.TYPE_MAP.get(field['type'], field['type'])
462+
463+
if field['modifier'] == 'repeated':
464+
python_type = f"list[{python_type}]"
465+
elif field['modifier'] == 'optional':
466+
python_type = f"{python_type} | None"
467+
468+
field_name = f"``{field['name']}``"
469+
type_name = f"``{python_type}``"
470+
description = field['description'] if field['description'] else ""
471+
472+
content += f" * - {field_name}\n"
473+
content += f" - {type_name}\n"
474+
content += f" - {description}\n"
475+
476+
content += "\n"
477+
return content
460478

461479
def _format_enum(self, enum: ProtoEnum) -> str:
462480
"""Format an enum as RST."""

0 commit comments

Comments
 (0)