Skip to content

Commit adb2776

Browse files
committed
[dg docs] Add docs e2e test, screenshot generation for component type tutorial
1 parent 7c89080 commit adb2776

File tree

16 files changed

+736
-16
lines changed

16 files changed

+736
-16
lines changed

docs/docs-beta/src/code-examples-content.js

+387
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs/guides/preview/components/creating-a-component.md

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 'Creating a New Component Type'
2+
title: 'Creating a new component type'
33
sidebar_position: 100
44
---
55

@@ -36,13 +36,11 @@ For this example, we'll write a lightweight component that executes a shell comm
3636

3737
First, we use the `dg` command-line utility to scaffold a new component type:
3838

39-
```bash
40-
dg component-type generate shell_command
41-
```
39+
<CliInvocationExample path="docs_beta_snippets/docs_beta_snippets/guides/components/shell-script-component/1-dg-scaffold-shell-command.txt" />
4240

4341
This will add a new file to your project in the `lib` directory:
4442

45-
<CodeExample path="docs_beta_snippets/docs_beta_snippets/guides/components/shell-script-component/empty.py" language="python" />
43+
<CodeExample path="docs_beta_snippets/docs_beta_snippets/guides/components/shell-script-component/2-shell-command-empty.py" language="python" title="my_component_library/lib/shell_command.py" />
4644

4745
This file contains the basic structure for the new component type. There are two methods that you'll need to implement:
4846

@@ -88,18 +86,15 @@ Our `build_defs` method will create a single `@asset` that executes the provided
8886

8987
Following the steps above will automatically register your component type in your environment. You can now run:
9088

91-
```bash
92-
dg component-type list
93-
```
89+
<CliInvocationExample path="docs_beta_snippets/docs_beta_snippets/guides/components/shell-script-component/3-dg-list-component-types.txt" />
9490

9591
and see your new component type in the list of available component types.
9692

9793
You can also view automatically generated documentation describing your new component type by running:
9894

99-
```bash
100-
dg component-type docs your_library.shell_command
101-
```
95+
<CliInvocationExample path="docs_beta_snippets/docs_beta_snippets/guides/components/shell-script-component/4-dg-component-type-docs.txt" />
10296

97+
![](/images/guides/build/projects-and-components/components/component-type-docs.png)
10398
## [Advanced] Custom templating
10499

105100
The components system supports a rich templating syntax that allows you to load arbitrary Python values based off of your `component.yaml` file.
@@ -140,4 +135,4 @@ params:
140135
141136
## Next steps
142137
143-
- Add a new component to your project
138+
- [Add a new component to your project](./using-a-component.md)
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dg component-type scaffold shell_command
2+
3+
Creating a Dagster component type at /.../my-component-library/my_component_library/lib/shell_command.py.
4+
Scaffolded files for Dagster project in /.../my-component-library/my_component_library/lib.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from dagster import Definitions
2+
from dagster_components import (
3+
Component,
4+
ComponentLoadContext,
5+
DefaultComponentScaffolder,
6+
registered_component_type,
7+
)
8+
from pydantic import BaseModel
9+
10+
class ShellCommandParams(BaseModel):
11+
...
12+
13+
@registered_component_type(name="shell_command")
14+
class ShellCommand(Component):
15+
"""COMPONENT SUMMARY HERE.
16+
17+
COMPONENT DESCRIPTION HERE.
18+
"""
19+
20+
@classmethod
21+
def get_schema(cls):
22+
return ShellCommandParams
23+
24+
@classmethod
25+
def get_scaffolder(cls) -> DefaultComponentScaffolder:
26+
return DefaultComponentScaffolder()
27+
28+
@classmethod
29+
def load(
30+
cls,
31+
params: ShellCommandParams,
32+
context: ComponentLoadContext,
33+
) -> "ShellCommand":
34+
# Add logic for mapping schema parameters to constructor args here.
35+
return cls()
36+
37+
def build_defs(self, load_context: ComponentLoadContext) -> Definitions:
38+
# Add definition construction logic here.
39+
return Definitions()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
dg component-type list
2+
3+
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
4+
┃ Component Type ┃ Summary ┃
5+
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
6+
│ definitions@dagster_components │ Wraps an arbitrary set of │
7+
│ │ Dagster definitions. │
8+
│ pipes_subprocess_script_collection@dagster_components │ Assets that wrap Python │
9+
│ │ scripts executed with │
10+
│ │ Dagster's │
11+
│ │ PipesSubprocessClient. │
12+
│ shell_command@my_component_library │ Models a shell script as a │
13+
│ │ Dagster asset. │
14+
└───────────────────────────────────────────────────────┴────────────────────────────────┘
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dg component-type docs shell_command@my_component_library
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Markdown Preview</title>
8+
</head>
9+
<body>
10+
<h2>Component: <code>my_component_library.shell_command</code></h2>
11+
<h3>Description:</h3>
12+
<p>Models a shell script as a Dagster asset.</p>
13+
<h3>Sample Component Params:</h3>
14+
<textarea rows=24 cols=100>
15+
type: my_component_library.shell_command
16+
17+
params:
18+
script_path: '...'
19+
asset_attributes:
20+
deps:
21+
- '...'
22+
description: '...'
23+
metadata: '...'
24+
group_name: '...'
25+
skippable: false
26+
code_version: '...'
27+
owners:
28+
- '...'
29+
tags: '...'
30+
kinds:
31+
- '...'
32+
automation_condition: '...'
33+
key: '...'
34+
op:
35+
name: '...'
36+
tags: {}
37+
38+
</textarea>
39+
</body>
40+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type: shell_command@my_component_library
2+
3+
params: {}

examples/docs_beta_snippets/docs_beta_snippets/guides/components/shell-script-component/resolving-resolvable-field.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, params):
2424
def build_defs(self, load_context: ComponentLoadContext) -> dg.Definitions:
2525
# highlight-start
2626
# resolve the script runner with its required additional scope
27-
script_runner = self.params.resolve_properties(
27+
script_runner = self.params.resolve(
2828
load_context.templated_value_resolver.with_scope(
2929
get_script_runner=_get_script_runner
3030
)

examples/docs_beta_snippets/docs_beta_snippets/guides/components/shell-script-component/with-build-defs.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class ShellScriptSchema(BaseModel):
2222

2323
@registered_component_type(name="shell_command")
2424
class ShellCommand(Component):
25+
"""Models a shell script as a Dagster asset."""
26+
2527
def __init__(self, params: ShellScriptSchema):
2628
self.params = params
2729

@@ -38,11 +40,11 @@ def load(
3840
return cls(params=params)
3941

4042
def build_defs(self, load_context: ComponentLoadContext) -> dg.Definitions:
41-
resolved_asset_attributes = self.params.asset_attributes.resolve_properties(
43+
resolved_asset_attributes = self.params.asset_attributes.resolve(
4244
load_context.templated_value_resolver
4345
)
4446
resolved_op_properties = (
45-
self.params.op.resolve_properties(load_context.templated_value_resolver)
47+
self.params.op.resolve(load_context.templated_value_resolver)
4648
if self.params.op
4749
else {}
4850
)

examples/docs_beta_snippets/docs_beta_snippets/guides/components/shell-script-component/with-config-schema.py

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class ShellScriptSchema(BaseModel):
2121

2222
@registered_component_type(name="shell_command")
2323
class ShellCommand(Component):
24+
"""Models a shell script as a Dagster asset."""
25+
2426
@classmethod
2527
def get_schema(cls) -> type[ShellScriptSchema]:
2628
# higlight-start

examples/docs_beta_snippets/docs_beta_snippets_tests/snippet_checks/conftest.py

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from collections.abc import Iterator
2+
13
import pytest
24

35

@@ -11,3 +13,23 @@ def pytest_addoption(parser: pytest.Parser) -> None:
1113
@pytest.fixture
1214
def update_snippets(request: pytest.FixtureRequest) -> bool:
1315
return bool(request.config.getoption("--update-snippets"))
16+
17+
18+
@pytest.fixture(scope="session")
19+
def get_selenium_driver():
20+
from selenium import webdriver
21+
22+
driver = None
23+
24+
try:
25+
26+
def _get_driver():
27+
nonlocal driver
28+
if driver is None:
29+
driver = webdriver.Chrome()
30+
return driver
31+
32+
yield _get_driver
33+
finally:
34+
if driver:
35+
driver.quit()

0 commit comments

Comments
 (0)