Skip to content

Commit 3fd60d4

Browse files
committed
[dg] Add option to output html docs to file instead of tmpfile/browser
1 parent 95cc4bb commit 3fd60d4

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Diff for: python_modules/libraries/dagster-dg/dagster_dg/cli/component_type.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from dagster_dg.component_key import GlobalComponentKey
1313
from dagster_dg.config import normalize_cli_config
1414
from dagster_dg.context import DgContext
15-
from dagster_dg.docs import markdown_for_component_type, render_markdown_in_browser
15+
from dagster_dg.docs import html_from_markdown, markdown_for_component_type, open_html_in_browser
1616
from dagster_dg.scaffold import scaffold_component_type
1717
from dagster_dg.utils import DgClickCommand, DgClickGroup, exit_with_error
1818

@@ -56,11 +56,13 @@ def component_type_scaffold_command(
5656

5757
@component_type_group.command(name="docs", cls=DgClickCommand)
5858
@click.argument("component_type", type=str)
59+
@click.option("--output", type=click.Choice(["browser", "cli"]), default="browser")
5960
@dg_global_options
6061
@click.pass_context
6162
def component_type_docs_command(
6263
context: click.Context,
6364
component_type: str,
65+
output: str,
6466
**global_options: object,
6567
) -> None:
6668
"""Get detailed information on a registered Dagster component type."""
@@ -71,7 +73,11 @@ def component_type_docs_command(
7173
if not registry.has_global(component_key):
7274
exit_with_error(f"Component type`{component_type}` not found.")
7375

74-
render_markdown_in_browser(markdown_for_component_type(registry.get_global(component_key)))
76+
markdown = markdown_for_component_type(registry.get_global(component_key))
77+
if output == "browser":
78+
open_html_in_browser(html_from_markdown(markdown))
79+
else:
80+
click.echo(html_from_markdown(markdown))
7581

7682

7783
# ########################

Diff for: python_modules/libraries/dagster-dg/dagster_dg/docs.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def generate_sample_yaml(component_type: str, json_schema: Mapping[str, Any]) ->
143143
return "\n".join(commented_lines)
144144

145145

146-
def render_markdown_in_browser(markdown_content: str) -> None:
146+
def html_from_markdown(markdown_content: str) -> str:
147147
# Convert the markdown string to HTML
148148
html_content = markdown.markdown(markdown_content)
149149

@@ -161,10 +161,13 @@ def render_markdown_in_browser(markdown_content: str) -> None:
161161
</body>
162162
</html>
163163
"""
164+
return full_html
164165

166+
167+
def open_html_in_browser(html_content: str) -> None:
165168
# Create a temporary file
166169
with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as temp_file:
167-
temp_file.write(full_html.encode("utf-8"))
170+
temp_file.write(html_content.encode("utf-8"))
168171
temp_file_path = temp_file.name
169172

170173
# Open the temporary file in the default web browser
@@ -179,8 +182,8 @@ def markdown_for_component_type(remote_component_type: RemoteComponentType) -> s
179182
rows = len(sample_yaml.split("\n")) + 1
180183
return f"""
181184
## Component: `{component_type_name}`
182-
183-
### Description:
185+
186+
### Description:
184187
{remote_component_type.description}
185188
186189
### Sample Component Params:

0 commit comments

Comments
 (0)