forked from wireviz/WireViz
-
Notifications
You must be signed in to change notification settings - Fork 0
Add --template-dir CLI option (port of upstream PR #444) #3
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -678,6 +678,7 @@ def output( | |
| cleanup: bool = True, | ||
| output_dir: Optional[Union[str, Path]] = None, | ||
| output_name: Optional[str] = None, | ||
| template_dir: Optional[Union[str, Path]] = None, | ||
| ) -> None: | ||
| """Render the harness in the requested formats. | ||
|
|
||
|
|
@@ -686,13 +687,34 @@ def output( | |
| ``filename`` is None, exactly one format must be requested and | ||
| its bytes/text are written to stdout — supports piping the CLI | ||
| into other tools. | ||
|
|
||
| Args: | ||
| filename: Output base path (without extension). ``None`` | ||
| routes a single format to stdout instead of writing files. | ||
| fmt: One or more formats from ``html``, ``png``, ``svg``, | ||
| ``gv``, ``tsv``, ``csv``, ``pdf``. A bare string is | ||
| normalized to a one-tuple. | ||
| view: Reserved (unused — kept for API compatibility with the | ||
| pre-refactor signature). | ||
| cleanup: Reserved (unused — kept for API compatibility). | ||
| output_dir: Output directory. Used only to populate the | ||
| ``<!-- %filename% -->`` HTML template placeholder and to | ||
| resolve a custom ``metadata.template.name`` reference. | ||
| output_name: Output base name (without extension). Used only | ||
| to populate the ``<!-- %filename_stem% -->`` HTML | ||
| template placeholder. | ||
| template_dir: Explicit directory to search first when | ||
| resolving a ``metadata.template.name`` reference. Falls | ||
| through to the YAML source directory, then ``output_dir``, | ||
| then the built-in templates shipped with WireViz. | ||
| """ | ||
| if isinstance(fmt, str): | ||
| fmt = (fmt,) | ||
| outputs: Dict[str, Union[str, bytes]] = self._render( | ||
| fmt, | ||
| output_dir=output_dir, | ||
| output_name=output_name, | ||
| template_dir=template_dir, | ||
| ) | ||
|
|
||
| if "csv" in fmt: | ||
|
|
@@ -728,12 +750,33 @@ def _render( | |
| fmt: Union[str, Tuple[str, ...], List[str]], | ||
| output_dir: Optional[Union[str, Path]] = None, | ||
| output_name: Optional[str] = None, | ||
| template_dir: Optional[Union[str, Path]] = None, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) -> Dict[str, Union[str, bytes]]: | ||
| """Produce in-memory representations of each requested format. | ||
|
|
||
| Pipes graphviz once per binary output rather than via ``render()`` | ||
| + temporary files so the caller can write files OR pipe to stdout | ||
| without the SVG-file roundtrip the previous implementation used. | ||
|
|
||
| Args: | ||
| fmt: One or more formats from ``html``, ``png``, ``svg``, | ||
| ``gv``, ``tsv``. ``csv`` and ``pdf`` are recognized at | ||
| the dispatch layer but not produced here. A bare string | ||
| is normalized to a one-tuple. | ||
| output_dir: Forwarded to ``generate_html_output`` for | ||
| ``<!-- %filename% -->`` and ``<!-- %diagram_png_b64% -->`` | ||
| template-placeholder resolution, and as the third-priority | ||
| directory in the custom-template search path. | ||
| output_name: Forwarded to ``generate_html_output`` for | ||
| ``<!-- %filename_stem% -->`` resolution. | ||
| template_dir: Forwarded to ``generate_html_output`` as the | ||
| first-priority directory in the custom-template search | ||
| path. | ||
|
|
||
| Returns: | ||
| ``{format: bytes|str}``. Binary formats (``png``) yield | ||
| bytes; text formats (``svg``, ``html``, ``gv``, ``tsv``) | ||
| yield str. | ||
| """ | ||
| if isinstance(fmt, str): | ||
| fmt = (fmt,) | ||
|
|
@@ -788,6 +831,7 @@ def _render( | |
| output_name=output_name, | ||
| png_b64=png_b64, | ||
| source_path=self.source_path, | ||
| template_dir=template_dir, | ||
| ) | ||
|
|
||
| return outputs | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ def parse( | |
| output_name: Union[None, str] = None, | ||
| image_paths: Union[Path, str, List] = [], | ||
| source_path: Union[Path, str, None] = None, | ||
| template_dir: Union[Path, str, None] = None, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) -> Any: | ||
| """ | ||
| This function takes an input, parses it as a WireViz Harness file, | ||
|
|
@@ -76,6 +77,17 @@ def parse( | |
| Paths to use when resolving any image paths included in the data. | ||
| Note: If inp is a path to a YAML file, | ||
| its parent directory will automatically be included in the list. | ||
| source_path (Path | str, optional): | ||
| Path of the originating YAML file when ``inp`` is a string or dict. | ||
| Used to: (1) resolve a custom ``metadata.template.name`` reference | ||
| against the source's directory, and (2) resolve relative | ||
| ``<image src=...>`` paths embedded in graphviz output. | ||
| When ``inp`` is itself a Path, this is filled in automatically. | ||
| template_dir (Path | str, optional): | ||
| Explicit first-priority directory to search when resolving a | ||
| ``metadata.template.name`` reference. Searched before the YAML | ||
| source directory and the output directory; the built-in | ||
| templates ship as the final fallback. | ||
|
|
||
| Returns: | ||
| Depending on the return_types parameter, may return: | ||
|
|
@@ -421,14 +433,20 @@ def alternate_type(): # flip between connector and cable/arrow | |
| raise ValueError( | ||
| "Exactly one output format must be specified when writing to stdout." | ||
| ) | ||
| harness.output(filename=None, fmt=output_formats, view=False) | ||
| harness.output( | ||
| filename=None, | ||
| fmt=output_formats, | ||
| view=False, | ||
| template_dir=template_dir, | ||
| ) | ||
| else: | ||
| harness.output( | ||
| filename=output_file, | ||
| fmt=output_formats, | ||
| view=False, | ||
| output_dir=output_dir, | ||
| output_name=output_name, | ||
| template_dir=template_dir, | ||
| ) | ||
|
|
||
| if return_types: | ||
|
|
||
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
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
template_dirparameter is missing from theoutputmethod's docstring. Please update the docstring to include a description of this new parameter, explaining that it specifies an explicit directory to search for HTML templates.