-
Notifications
You must be signed in to change notification settings - Fork 0
Docs/pipe 2738 migrate cli documentation #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
r-xue
wants to merge
30
commits into
main
Choose a base branch
from
docs/PIPE-2738-migrate-cli-documentation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
02b465a
PIPE-2738: Add a draft doc to describe some potential improvenments f…
r-xue d424b7e
PIPE-2738: fix the link to `config.yaml`
r-xue d440af7
PIPE-2738: Switch docs to Furo theme with collapsible TOC
r-xue 8d1f06e
PIPE-2738: Switch to native RTD pixi support in `.readthedocs.yaml`
r-xue ce9ce2b
PIPE-2738: Clean up docs landing page and footer
r-xue ac8fd00
Update `docs/README.rst` landing page description
r-xue 97f24ea
PIPE-2738: Improve docs UI - fix labels, add mermaid reset button
r-xue 6a94f89
PIPE-2738: Move Developer Notes into dedicated index page
r-xue 02c01a8
PIPE-2738: Add PDF format support to Read the Docs configuration
r-xue 4378906
PIPE-2738: Remove outdated autosummary section for Pipeline domain/co…
r-xue fe2fe24
PIPE-2738: Reorganize API documentation structure in `apisummary.rst`…
r-xue 49c5e4e
PIPE-2738 Migrate releases/timeline to MyST Markdown
r-xue a691e1c
PIPE-2738: Adjust global font size for improved readability
r-xue 756e6c1
PIPE-2738: Add sidebar hierarchy for automodapi and CLI docs
r-xue 1480c0e
PIPE-2738: Reorganize API sections and fix Task diagram
r-xue 2d26a77
PIPE-2738/PIPE-2890: Migrate PLUG task docs into CLI docstrings
r-xue 8e586f9
PIPE-2738: Add CalLibrary overview doc as MyST Markdown
r-xue 985a0b7
PIPE-2738: Replace Unicode symbols with ASCII in CLI docstrings
r-xue 64dcdd4
PIPE-2738: Convert recipes and releases tables to MyST markdown
r-xue 607c44d
PIPE-2738: Enhance TOC toggle button dynamical positioning for better…
r-xue 2a4998a
PIPE-2738: Refactor dependencies documentation for clarity and accuracy
r-xue eb0187e
PIPE-2738: Migrate dependencies documentation from reStructuredText t…
r-xue caeab92
PIPE-2738: Migrate interface documentation from reStructuredText to M…
r-xue 38e875e
Merge remote-tracking branch 'origin/main' into docs/PIPE-2738-migrat…
r-xue ef71532
PIPE-3009: Update documentation and dependencies for Python 3.12+ com…
r-xue 89bed2d
Merge remote-tracking branch 'origin/main' into docs/PIPE-2738-migrat…
r-xue feb3ffa
PIPE-2738: Update API summary to include additional subpackages and m…
r-xue 31359bc
PIPE-2738: Update `casa675-py313` feature to include solve-group for …
r-xue 8b797c5
PIPE-2738: Fix `__all__` type in direction_utils
r-xue 620de95
PIPE-2738: Update platform compatibility for casa675-py313 and adjust…
r-xue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,33 @@ | ||
| version: 2 | ||
|
|
||
| # Build tools and environment setup | ||
| formats: | ||
|
|
||
| build: | ||
| os: ubuntu-24.04 | ||
| tools: | ||
| python: miniconda-latest # use miniconda-latest before miniforge3 becomes available. | ||
| python: "latest" | ||
| apt_packages: | ||
| - git | ||
| - xvfb | ||
| - imagemagick | ||
| - poppler-utils | ||
| - latexmk | ||
| - texlive-latex-recommended | ||
| - texlive-latex-extra | ||
| - texlive-fonts-recommended | ||
| # Build commands for HTML and PDF | ||
| commands: | ||
| - conda env update --file=environment.yml | ||
| - conda run -n pipeline python -m pip install .[docs] | ||
| - mkdir -p ~/.casa/data | ||
| - cd docs && conda run -n pipeline make html_docs | ||
| - cd docs && conda run -n pipeline make latexpdf | ||
| - mkdir --parents _readthedocs/html/ _readthedocs/pdf/ | ||
| - cp --recursive docs/_build/html/* _readthedocs/html/ | ||
| - cp --recursive docs/_build/latex/*.pdf _readthedocs/pdf/ | ||
| jobs: | ||
| create_environment: | ||
| - asdf plugin add pixi | ||
| - asdf install pixi latest | ||
| - asdf global pixi latest | ||
| - mkdir -p ~/.casa/data | ||
| install: | ||
| - pixi install -e docs | ||
| build: | ||
| html: | ||
| - pixi run -e docs --frozen sphinx-build -T -b html docs/source $READTHEDOCS_OUTPUT/html | ||
| pdf: | ||
| - pixi run -e docs --frozen sphinx-build -T -b latex docs/source docs/_build/latex | ||
| - cd docs/_build/latex && latexmk -pdf -interaction=nonstopmode *.tex | ||
| - mkdir -p $READTHEDOCS_OUTPUT/pdf/ | ||
| - cp docs/_build/latex/*.pdf $READTHEDOCS_OUTPUT/pdf/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| """Generate autosummary stubs for CLI task functions. | ||
|
|
||
| Sphinx autosummary only generates stubs for items listed directly in | ||
| source ``.. autosummary:: :toctree:`` directives. It does NOT process | ||
| nested ``:toctree:`` inside stubs it just generated, **and** it strips | ||
| directive options (like ``:toctree:`` / ``:nosignatures:``) and extra | ||
| blocks (like ``.. toctree:: :hidden:``) from template-generated stubs. | ||
|
|
||
| This extension works around both limitations: | ||
|
|
||
| 1. Hook ``builder-inited`` with priority 900 (after autosummary at 500) | ||
| so the module stubs already exist. | ||
| 2. Introspect each CLI module to discover public functions. | ||
| 3. Generate an individual ``.rst`` stub for every function. | ||
| 4. Append a ``.. toctree:: :hidden:`` block to each module stub so that | ||
| the sidebar shows functions nested under their parent module. | ||
| """ | ||
|
|
||
| import importlib | ||
| import inspect | ||
| import logging | ||
| from pathlib import Path | ||
|
|
||
| from sphinx.application import Sphinx | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| #: CLI modules whose public functions should get individual stubs. | ||
| CLI_MODULES = [ | ||
| 'pipeline.h.cli', | ||
| 'pipeline.hif.cli', | ||
| 'pipeline.hifa.cli', | ||
| 'pipeline.hifv.cli', | ||
| 'pipeline.hsd.cli', | ||
| 'pipeline.hsdn.cli', | ||
| ] | ||
|
|
||
| #: Directory (relative to source) where stubs are written. | ||
| AUTOSUMMARY_DIR = '_autosummary' | ||
|
|
||
| #: Template for individual function stubs. | ||
| STUB_TEMPLATE = """\ | ||
| {title} | ||
| {underline} | ||
|
|
||
| .. currentmodule:: {module} | ||
|
|
||
| .. autofunction:: {name} | ||
| """ | ||
|
|
||
| #: Marker so we only patch a module stub once. | ||
| _TOCTREE_MARKER = '.. cli_function_stubs toctree' | ||
|
|
||
|
|
||
| def _discover_functions(mod_name: str) -> list[str]: | ||
| """Return sorted list of public function names exported by *mod_name*.""" | ||
| try: | ||
| mod = importlib.import_module(mod_name) | ||
| except ImportError: | ||
| logger.warning('cli_function_stubs: could not import %s', mod_name) | ||
| return [] | ||
|
|
||
| names = [] | ||
| for name, obj in inspect.getmembers(mod, inspect.isfunction): | ||
| if name.startswith('_'): | ||
| continue | ||
| func_module = getattr(obj, '__module__', '') or '' | ||
| if func_module.startswith(mod_name): | ||
| names.append(name) | ||
| return sorted(names) | ||
|
|
||
|
|
||
| def _generate_cli_function_stubs(app: Sphinx) -> None: | ||
| """Generate function stubs and patch module stubs with a hidden toctree.""" | ||
| srcdir = Path(app.srcdir) | ||
| outdir = srcdir / AUTOSUMMARY_DIR | ||
| outdir.mkdir(exist_ok=True) | ||
|
|
||
| overwrite = getattr(app.config, 'autosummary_generate_overwrite', True) | ||
|
|
||
| for mod_name in CLI_MODULES: | ||
| func_names = _discover_functions(mod_name) | ||
| if not func_names: | ||
| continue | ||
|
|
||
| # --- 1. Generate individual function stubs --- | ||
| for name in func_names: | ||
| stub_path = outdir / f'{mod_name}.{name}.rst' | ||
| if stub_path.exists() and not overwrite: | ||
| continue | ||
|
|
||
| escaped = name.replace('_', r'\_') | ||
| content = STUB_TEMPLATE.format( | ||
| title=escaped, | ||
| underline='=' * len(escaped), | ||
| module=mod_name, | ||
| name=name, | ||
| ) | ||
| stub_path.write_text(content) | ||
|
|
||
| # --- 2. Patch module stub with hidden toctree --- | ||
| mod_stub = outdir / f'{mod_name}.rst' | ||
| if not mod_stub.exists(): | ||
| continue | ||
|
|
||
| text = mod_stub.read_text() | ||
| if _TOCTREE_MARKER in text: | ||
| continue # already patched | ||
|
|
||
| toctree_entries = '\n'.join(f' {mod_name}.{n}' for n in func_names) | ||
| patch = ( | ||
| f'\n.. {_TOCTREE_MARKER}\n' | ||
| f'.. toctree::\n' | ||
| f' :hidden:\n\n' | ||
| f'{toctree_entries}\n' | ||
| ) | ||
| mod_stub.write_text(text + patch) | ||
|
|
||
|
|
||
| def setup(app: Sphinx) -> dict: | ||
| app.connect('builder-inited', _generate_cli_function_stubs, priority=900) | ||
| return {'version': '0.1', 'parallel_read_safe': True} | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module-stub patching is skipped once the marker is present, so the hidden toctree will never be updated if new CLI functions are added (or removed) after the first build. Consider rewriting/replacing the existing marked toctree block each run (or at least appending any newly discovered functions) so navigation stays in sync with the code.