Skip to content

Commit d37ddee

Browse files
authored
Merge pull request #223 from AllenNeuralDynamics/docs-add-yml-sections
Document yaml tags for `ServiceSettings`
2 parents 05c5350 + 192a3ee commit d37ddee

File tree

5 files changed

+141
-4
lines changed

5 files changed

+141
-4
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 Allen Institute for Neural Dynamics
3+
Copyright (c) 2026 Allen Institute for Neural Dynamics
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Command-line-interface Launcher for AIND Behavior Experiments
1313
</div>
1414

1515

16-
[![Documentation](https://camo.githubusercontent.com/d7111793c727ad754311b21d4f083d842f5071163a74f406822a63eb0fb2af69/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f63756d656e746174696f6e2d626c75653f636f6c6f723d344138424431266c696e6b3d6874747073253341253246253246616c6c656e6e657572616c64796e616d6963732e6769746875622e696f253246426f6e7361692e416c6c656e4e657572616c44796e616d696373253246)](https://allenneuraldynamics.github.io/clabe/)
16+
[![Documentation](https://img.shields.io/badge/documentation-blue)](https://allenneuraldynamics.github.io/clabe/)
1717
![CI](https://github.com/AllenNeuralDynamics/Aind.Behavior.ExperimentLauncher/actions/workflows/clabe.yml/badge.svg)
1818
[![PyPI - Version](https://img.shields.io/pypi/v/aind-clabe)](https://pypi.org/project/aind-clabe/)
1919
[![License](https://img.shields.io/badge/license-MIT-brightgreen)](LICENSE)

docs/articles/.gitkeep

Whitespace-only changes.

docs/build.py

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import ast
12
import logging
23
import shutil
34
from pathlib import Path
4-
from typing import Any, Dict, List, Union
5+
from typing import Any, Dict, List, Optional, Tuple, Union
56

67
import yaml
78

@@ -153,6 +154,94 @@ def copy_assets() -> None:
153154
log.warning(f"Source: {file_or_dir} not found, skipping.")
154155

155156

157+
def find_service_settings_classes(src_dir: Path) -> List[Tuple[str, Optional[str]]]: # noqa: C901
158+
"""
159+
Scan all Python files in the source directory to find classes that inherit from ServiceSettings.
160+
161+
Returns a list of tuples: (class_name, yml_section_value)
162+
"""
163+
service_settings: List[Tuple[str, Optional[str]]] = []
164+
165+
for py_file in src_dir.rglob("*.py"):
166+
try:
167+
with open(py_file, "r", encoding="utf-8") as f:
168+
tree = ast.parse(f.read(), filename=str(py_file))
169+
170+
for node in ast.walk(tree):
171+
if isinstance(node, ast.ClassDef):
172+
# Check if class inherits from ServiceSettings
173+
inherits_from_service_settings = False
174+
for base in node.bases:
175+
if isinstance(base, ast.Name) and base.id == "ServiceSettings":
176+
inherits_from_service_settings = True
177+
break
178+
179+
if not inherits_from_service_settings:
180+
continue
181+
182+
# Look for __yml_section__ attribute
183+
yml_section: Optional[str] = None
184+
for item in node.body:
185+
# Handle annotated assignments: __yml_section__: ClassVar[str] = "value"
186+
if isinstance(item, ast.AnnAssign):
187+
if isinstance(item.target, ast.Name) and item.target.id == "__yml_section__":
188+
if item.value and isinstance(item.value, ast.Constant):
189+
yml_section = item.value.value
190+
break
191+
# Handle simple assignments: __yml_section__ = "value"
192+
elif isinstance(item, ast.Assign):
193+
for target in item.targets:
194+
if isinstance(target, ast.Name) and target.id == "__yml_section__":
195+
if isinstance(item.value, ast.Constant):
196+
yml_section = item.value.value
197+
break
198+
if yml_section is not None:
199+
break
200+
201+
service_settings.append((node.name, yml_section))
202+
203+
except Exception as e:
204+
log.warning(f"Failed to parse {py_file}: {e}")
205+
206+
return sorted(service_settings, key=lambda x: x[0])
207+
208+
209+
def generate_service_settings_table() -> None:
210+
"""
211+
Generate a markdown table of ServiceSettings classes and their yml_section values.
212+
"""
213+
log.info("Generating service settings documentation...")
214+
215+
service_settings = find_service_settings_classes(SRC_DIR)
216+
217+
if not service_settings:
218+
log.warning("No ServiceSettings classes found.")
219+
return
220+
221+
# Build markdown content
222+
content = [
223+
"# Service Settings",
224+
"",
225+
"This table lists all service settings classes and their YAML section names.",
226+
"",
227+
]
228+
content.append("| Class Name | YAML Section |")
229+
content.append("|------------|--------------|")
230+
231+
for class_name, yml_section in service_settings:
232+
section_display = yml_section if yml_section else "None"
233+
content.append(f"| `{class_name}` | `{section_display}` |")
234+
235+
# Write to file in articles directory
236+
articles_dir = DOCS_DIR / "articles"
237+
articles_dir.mkdir(exist_ok=True)
238+
output_path = articles_dir / "service_settings.md"
239+
with open(output_path, "w", encoding="utf-8") as f:
240+
f.write("\n".join(content))
241+
242+
log.info(f"Service settings documentation written to {output_path}")
243+
244+
156245
def main() -> None:
157246
log.info("Starting API documentation regeneration...")
158247
copy_assets()
@@ -163,6 +252,9 @@ def main() -> None:
163252
# Update mkdocs.yml
164253
update_mkdocs_yml(api_structure)
165254

255+
# Generate service settings table
256+
generate_service_settings_table()
257+
166258
log.info("API documentation regenerated successfully.")
167259

168260

mkdocs.yml

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
site_name: clabe
22
site_description: Documentation for the clabe python package.
33
site_author: Bruno F. Cruz
4-
copyright: 2025, Allen Institute for Neural Dynamics
4+
copyright: 2026, Allen Institute for Neural Dynamics
55
repo_url: https://github.com/AllenNeuralDynamics/clabe
66
repo_name: GitHub
77
theme:
@@ -90,6 +90,51 @@ markdown_extensions:
9090
nav:
9191
- Home: index.md
9292
- API Reference:
93+
- Cache Manager:
94+
- cache_manager: api/cache_manager.md
95+
- Cli:
96+
- cli: api/cli.md
97+
- Constants:
98+
- constants: api/constants.md
99+
- Services:
100+
- services: api/services.md
101+
- Apps:
102+
- apps: api/apps/apps.md
103+
- open_ephys: api/apps/open_ephys.md
104+
- Data Mapper:
105+
- data_mapper: api/data_mapper/data_mapper.md
106+
- aind_data_schema: api/data_mapper/aind_data_schema.md
107+
- helpers: api/data_mapper/helpers.md
108+
- Data Transfer:
109+
- data_transfer: api/data_transfer/data_transfer.md
110+
- aind_watchdog: api/data_transfer/aind_watchdog.md
111+
- robocopy: api/data_transfer/robocopy.md
112+
- Git Manager:
113+
- git_manager: api/git_manager/git_manager.md
114+
- Launcher:
115+
- launcher: api/launcher/launcher.md
116+
- Logging Helper:
117+
- logging_helper: api/logging_helper/logging_helper.md
118+
- aibs: api/logging_helper/aibs.md
119+
- Pickers:
120+
- pickers: api/pickers/pickers.md
121+
- dataverse: api/pickers/dataverse.md
122+
- default_behavior: api/pickers/default_behavior.md
123+
- Resource Monitor:
124+
- resource_monitor: api/resource_monitor/resource_monitor.md
125+
- Ui:
126+
- ui: api/ui/ui.md
127+
- questionary_ui_helper: api/ui/questionary_ui_helper.md
128+
- ui_helper: api/ui/ui_helper.md
129+
- Utils:
130+
- utils: api/utils/utils.md
131+
- aind_auth: api/utils/aind_auth.md
132+
- keepass: api/utils/keepass.md
133+
- Xml Rpc:
134+
- xml_rpc: api/xml_rpc/xml_rpc.md
135+
- models: api/xml_rpc/models.md
136+
- Articles:
137+
- ServiceSettings and yaml tags: articles/service_settings.md
93138
- Issues: https://github.com/AllenNeuralDynamics/clabe/issues
94139
- Examples:
95140
- AIND Experiment: docs_examples/behavior_launcher.md

0 commit comments

Comments
 (0)