Skip to content

Commit 88476f0

Browse files
Documentation generation for yellow_pages.py and element_array.py
1 parent b74e986 commit 88476f0

File tree

3 files changed

+33
-51
lines changed

3 files changed

+33
-51
lines changed

pyaml/apidoc/gen_api.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"pyaml.tuning_tools.orbit_response_matrix",
8383
"pyaml.tuning_tools.response_matrix",
8484
"pyaml.tuning_tools.tune",
85+
"pyaml.yellow_pages",
8586
]
8687

8788

@@ -111,27 +112,21 @@ def generate_selective_module(m):
111112
file.write(f".. automodule:: {p.__name__}\n")
112113
if len(all_cls) > 0:
113114
# Exclude classes that will be treated by autoclass
114-
file.write(
115-
f" :exclude-members: {','.join([c.__name__ for c in all_cls])}\n\n"
116-
)
115+
file.write(f" :exclude-members: {','.join([c.__name__ for c in all_cls])}\n\n")
117116
for c in all_cls:
118117
file.write(f" .. autoclass:: {c.__name__}\n")
119118
file.write(" :members:\n")
120119
if m in ["pyaml.arrays.element_array"]:
121120
# Include special members for operator overloading
122-
file.write(
123-
" :special-members: __add__, __and__, __or__, __sub__ \n"
124-
)
121+
file.write(" :special-members: __add__, __and__, __or__, __sub__ \n")
125122
file.write(" :exclude-members: model_config\n")
126123
file.write(" :undoc-members:\n")
127124
file.write(" :show-inheritance:\n\n")
128125

129126

130127
def generate_toctree(filename: str, title: str, level: int, module: str):
131128
sub_modules = [m for m in modules if m.startswith(module)]
132-
level_path = sorted(
133-
set([m.split(".")[level + 1 : level + 2][0] for m in sub_modules])
134-
)
129+
level_path = sorted(set([m.split(".")[level + 1 : level + 2][0] for m in sub_modules]))
135130

136131
paths = []
137132

@@ -166,9 +161,7 @@ def gen_doc():
166161
while len(paths) > 0:
167162
npaths = []
168163
for p in paths:
169-
npaths.extend(
170-
generate_toctree(f"api/{'pyaml.' + p}.rst", f"{p}", level, "pyaml." + p)
171-
)
164+
npaths.extend(generate_toctree(f"api/{'pyaml.' + p}.rst", f"{p}", level, "pyaml." + p))
172165
paths = npaths
173166
level += 1
174167
print("done")

pyaml/arrays/element_array.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ def __create_array(self, array_name: str, element_type: type, elements: list):
9696
elif issubclass(element_type, Element):
9797
return ElementArray(array_name, elements, self.__use_aggregator)
9898
else:
99-
raise PyAMLException(
100-
f"Unsupported sliced array for type {str(element_type)}"
101-
)
99+
raise PyAMLException(f"Unsupported sliced array for type {str(element_type)}")
102100

103101
def __eval_field(self, attribute_name: str, element: Element) -> str:
104102
function_name = "get_" + attribute_name
@@ -109,16 +107,14 @@ def __ensure_compatible_operand(self, other: object) -> "ElementArray":
109107
"""Validate the operand used for set-like operations between arrays."""
110108
if not isinstance(other, ElementArray):
111109
raise TypeError(
112-
f"Unsupported operand type(s) for set operation: "
113-
f"'{type(self).__name__}' and '{type(other).__name__}'"
110+
f"Unsupported operand type(s) for set operation: '{type(self).__name__}' and '{type(other).__name__}'"
114111
)
115112

116113
if len(self) > 0 and len(other) > 0:
117114
if self.get_peer() is not None and other.get_peer() is not None:
118115
if self.get_peer() != other.get_peer():
119116
raise PyAMLException(
120-
f"{self.__class__.__name__}: cannot operate on arrays "
121-
"attached to different peers"
117+
f"{self.__class__.__name__}: cannot operate on arrays attached to different peers"
122118
)
123119
return other
124120

@@ -170,9 +166,7 @@ def __is_bool_mask(self, other: object) -> bool:
170166
pass
171167

172168
# --- python sequence of bools (but not a string/bytes) ---
173-
if isinstance(other, Sequence) and not isinstance(
174-
other, (str, bytes, bytearray)
175-
):
169+
if isinstance(other, Sequence) and not isinstance(other, (str, bytes, bytearray)):
176170
# Avoid treating ElementArray as a mask
177171
if isinstance(other, ElementArray):
178172
return False
@@ -195,8 +189,7 @@ def __and__(self, other: object):
195189
If ``other`` is an ElementArray, the result contains elements
196190
whose names are present in both arrays.
197191
198-
Example
199-
-------
192+
**Example**
200193
201194
.. code-block:: python
202195
@@ -208,8 +201,8 @@ def __and__(self, other: object):
208201
If ``other`` is a boolean mask (list[bool] or numpy.ndarray of bool),
209202
elements are kept where the mask is True.
210203
211-
Example
212-
-------
204+
**Example**
205+
213206
.. code-block:: python
214207
215208
>>> mask = cell1.mask_by_type(Magnet)
@@ -232,8 +225,7 @@ def __and__(self, other: object):
232225
mask = list(other) # works for list/tuple and numpy arrays
233226
if len(mask) != len(self):
234227
raise ValueError(
235-
f"{self.__class__.__name__}: mask length ({len(mask)}) "
236-
f"does not match array length ({len(self)})"
228+
f"{self.__class__.__name__}: mask length ({len(mask)}) does not match array length ({len(self)})"
237229
)
238230
res = [e for e, keep in zip(self, mask, strict=True) if bool(keep)]
239231
return self.__auto_array(res)
@@ -261,8 +253,7 @@ def __sub__(self, other: object):
261253
If ``other`` is an ElementArray, the result contains elements
262254
whose names are present in ``self`` but not in ``other``.
263255
264-
Example
265-
-------
256+
**Example**
266257
267258
.. code-block:: python
268259
@@ -275,8 +266,7 @@ def __sub__(self, other: object):
275266
elements are removed where the mask is True.
276267
This is the inverse of ``& mask``.
277268
278-
Example
279-
-------
269+
**Example**
280270
281271
.. code-block:: python
282272
@@ -300,8 +290,7 @@ def __sub__(self, other: object):
300290
mask = list(other)
301291
if len(mask) != len(self):
302292
raise ValueError(
303-
f"{self.__class__.__name__}: mask length ({len(mask)}) "
304-
f"does not match array length ({len(self)})"
293+
f"{self.__class__.__name__}: mask length ({len(mask)}) does not match array length ({len(self)})"
305294
)
306295
res = [e for e, remove in zip(self, mask, strict=True) if not bool(remove)]
307296
return self.__auto_array(res)

pyaml/yellow_pages.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@
44
Fully dynamic YellowPages service attached to Accelerator.
55
66
Key points:
7-
- Auto-discovery only: arrays, tools and diagnostics are discovered at runtime
8-
by scanning all modes.
9-
- No caching: every call reflects current runtime state.
10-
- Simple query syntax for identifiers:
11-
- wildcard / fnmatch:
12-
yp["OH4*"]
13-
- regular expression:
14-
yp["re:^SH1A-C0[12]-H$"]
7+
- Auto-discovery only: arrays, tools and diagnostics are discovered at runtime
8+
by scanning all modes.
9+
- No caching: every call reflects current runtime state.
10+
- Simple query syntax for identifiers:
11+
- wildcard / fnmatch:
12+
yp["OH4*"]
13+
- regular expression:
14+
yp["re:^SH1A-C0[12]-H$"]
1515
1616
Expected Accelerator interface
1717
------------------------------
18-
- controls() -> dict[str, ElementHolder]
19-
- simulators() -> dict[str, ElementHolder]
20-
- modes() -> dict[str, ElementHolder]
18+
- controls() -> dict[str, ElementHolder]
19+
- simulators() -> dict[str, ElementHolder]
20+
- modes() -> dict[str, ElementHolder]
2121
2222
Expected ElementHolder interface
2323
--------------------------------
24-
- list_arrays() -> set[str]
25-
- list_tools() -> set[str]
26-
- list_diagnostics() -> set[str]
27-
- get_array(name: str) -> Any
28-
- get_tool(name: str) -> Any
29-
- get_diagnostic(name: str) -> Any
24+
- list_arrays() -> set[str]
25+
- list_tools() -> set[str]
26+
- list_diagnostics() -> set[str]
27+
- get_array(name: str) -> Any
28+
- get_tool(name: str) -> Any
29+
- get_diagnostic(name: str) -> Any
3030
"""
3131

3232
from __future__ import annotations

0 commit comments

Comments
 (0)