Skip to content

Commit 8562905

Browse files
committed
[dg] Add option to output html docs to file instead of tmpfile/browser
1 parent 1671608 commit 8562905

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

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 (
1818
DgClickCommand,
@@ -61,11 +61,13 @@ def component_type_scaffold_command(
6161

6262
@component_type_group.command(name="docs", cls=DgClickCommand)
6363
@click.argument("component_type", type=str)
64+
@click.option("--output", type=click.Choice(["browser", "cli"]), default="browser")
6465
@dg_global_options
6566
@click.pass_context
6667
def component_type_docs_command(
6768
context: click.Context,
6869
component_type: str,
70+
output: str,
6971
**global_options: object,
7072
) -> None:
7173
"""Get detailed information on a registered Dagster component type."""
@@ -76,7 +78,11 @@ def component_type_docs_command(
7678
if not registry.has_global(component_key):
7779
exit_with_error(f"Component type`{component_type}` not found.")
7880

79-
render_markdown_in_browser(markdown_for_component_type(registry.get_global(component_key)))
81+
markdown = markdown_for_component_type(registry.get_global(component_key))
82+
if output == "browser":
83+
open_html_in_browser(html_from_markdown(markdown))
84+
else:
85+
click.echo(html_from_markdown(markdown))
8086

8187

8288
# ########################

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)