Skip to content

Commit c0f8eee

Browse files
Document new parameters in Harness.output(), _render(), and parse()
Addresses gemini-code-assist feedback on #3 — template_dir was missing from the docstrings of Harness.output(), Harness._render(), and wireviz.parse(). Expanded scope to also document the parameters that earlier PRs in this chain added without docstring coverage: * Harness.output(): Args section now describes filename (incl. None → stdout semantics), fmt (incl. str→tuple normalization), output_dir, output_name, and template_dir; view/cleanup are noted as kept for API compat. * Harness._render(): Args + Returns sections describing fmt, output_dir, output_name, template_dir, and the bytes-vs-str per-format return contract. * wireviz.parse(): source_path (added during PR #1's loopback fix and threaded through PR #2's stdin/stdout port) and template_dir (this PR) added to the Args section, with template-search-priority semantics spelled out. No behavior change. Verified against build_examples.py: deterministic outputs unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a8abc2b commit c0f8eee

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

src/wireviz/Harness.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,26 @@ def output(
687687
``filename`` is None, exactly one format must be requested and
688688
its bytes/text are written to stdout — supports piping the CLI
689689
into other tools.
690+
691+
Args:
692+
filename: Output base path (without extension). ``None``
693+
routes a single format to stdout instead of writing files.
694+
fmt: One or more formats from ``html``, ``png``, ``svg``,
695+
``gv``, ``tsv``, ``csv``, ``pdf``. A bare string is
696+
normalized to a one-tuple.
697+
view: Reserved (unused — kept for API compatibility with the
698+
pre-refactor signature).
699+
cleanup: Reserved (unused — kept for API compatibility).
700+
output_dir: Output directory. Used only to populate the
701+
``<!-- %filename% -->`` HTML template placeholder and to
702+
resolve a custom ``metadata.template.name`` reference.
703+
output_name: Output base name (without extension). Used only
704+
to populate the ``<!-- %filename_stem% -->`` HTML
705+
template placeholder.
706+
template_dir: Explicit directory to search first when
707+
resolving a ``metadata.template.name`` reference. Falls
708+
through to the YAML source directory, then ``output_dir``,
709+
then the built-in templates shipped with WireViz.
690710
"""
691711
if isinstance(fmt, str):
692712
fmt = (fmt,)
@@ -737,6 +757,26 @@ def _render(
737757
Pipes graphviz once per binary output rather than via ``render()``
738758
+ temporary files so the caller can write files OR pipe to stdout
739759
without the SVG-file roundtrip the previous implementation used.
760+
761+
Args:
762+
fmt: One or more formats from ``html``, ``png``, ``svg``,
763+
``gv``, ``tsv``. ``csv`` and ``pdf`` are recognized at
764+
the dispatch layer but not produced here. A bare string
765+
is normalized to a one-tuple.
766+
output_dir: Forwarded to ``generate_html_output`` for
767+
``<!-- %filename% -->`` and ``<!-- %diagram_png_b64% -->``
768+
template-placeholder resolution, and as the third-priority
769+
directory in the custom-template search path.
770+
output_name: Forwarded to ``generate_html_output`` for
771+
``<!-- %filename_stem% -->`` resolution.
772+
template_dir: Forwarded to ``generate_html_output`` as the
773+
first-priority directory in the custom-template search
774+
path.
775+
776+
Returns:
777+
``{format: bytes|str}``. Binary formats (``png``) yield
778+
bytes; text formats (``svg``, ``html``, ``gv``, ``tsv``)
779+
yield str.
740780
"""
741781
if isinstance(fmt, str):
742782
fmt = (fmt,)

src/wireviz/wireviz.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ def parse(
7777
Paths to use when resolving any image paths included in the data.
7878
Note: If inp is a path to a YAML file,
7979
its parent directory will automatically be included in the list.
80+
source_path (Path | str, optional):
81+
Path of the originating YAML file when ``inp`` is a string or dict.
82+
Used to: (1) resolve a custom ``metadata.template.name`` reference
83+
against the source's directory, and (2) resolve relative
84+
``<image src=...>`` paths embedded in graphviz output.
85+
When ``inp`` is itself a Path, this is filled in automatically.
86+
template_dir (Path | str, optional):
87+
Explicit first-priority directory to search when resolving a
88+
``metadata.template.name`` reference. Searched before the YAML
89+
source directory and the output directory; the built-in
90+
templates ship as the final fallback.
8091
8192
Returns:
8293
Depending on the return_types parameter, may return:

0 commit comments

Comments
 (0)