Skip to content

Commit

Permalink
Split up screenshot specs (#7460)
Browse files Browse the repository at this point in the history
* split up screenshot specs into multiple files

* move defining-an-asset screenshots
  • Loading branch information
sryza committed Apr 15, 2022
1 parent 1ec9318 commit a0cc868
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,17 @@ Serving dagit on http://127.0.0.1:3000 in process 70635

You should be able to navigate to <http://127.0.0.1:3000> in your web browser and view your asset.

<img
alt="defining_an_asset.png"
src="/images/guides/asset-tutorial/defining_an_asset.png"
/>
<img src="/images/dagster/guides/asset-tutorial/defining-an-asset/defining_an_asset.png" />

Clicking on the "Materialize All" button will launch a run that will materialize the asset. After that run has completed, the shaded box underneath "cereals" holds information about that run. Clicking on the Run ID, which is the string of characters in the upper right of that box, will take you to a view that includes a structured stream of logs and events that occurred during its execution.

<img alt="asset_run.png" src="/images/guides/asset-tutorial/asset_run.png" />
<img src="/images/dagster/guides/asset-tutorial/defining-an-asset/asset_run.png" />

In this view, you can filter and search through the logs corresponding to the run that's materializing your asset.

To see a history of all the materializations for your asset, you can navigate to the _Asset Details_ page for it. Click the "cereals" link in the upper left corner of this run page, next to "Success". Another way to get to the same page is to navigate back to the Asset Graph page by clicking "Assets" in the top navigation pane, clicking on your asset, and then clicking on "View in Asset Catalog" at the top of the pane that shows up on the right.

<img src="/images/guides/asset-tutorial/asset_details.png" />
<img src="/images/dagster/guides/asset-tutorial/defining-an-asset/asset_details.png" />

Success!

Expand Down
113 changes: 64 additions & 49 deletions docs/screenshot_capture/capture-screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,63 +13,71 @@
import subprocess
import sys
from time import sleep
from typing import Mapping, Sequence
from typing import Any, Mapping, Sequence

import yaml
from selenium import webdriver


def load_screenshot_specs():
with open("./docs/screenshot_capture/screenshots.yaml", "r") as f:
def load_screenshot_specs(path) -> Sequence[Mapping]:
with open(path, "r") as f:
return yaml.safe_load(f)


def capture_screenshots(screenshot_specs: Sequence[Mapping[str, str]]):
for screenshot_spec in screenshot_specs:
dagit_process = None
try:
defs_file = screenshot_spec.get("defs_file")
if defs_file:
if defs_file.endswith(".py"):
command = ["dagit", "-f", defs_file]
elif defs_file.endswith(".yaml"):
command = ["dagit", "-w", defs_file]
else:
assert False, "defs_file must be .py or .yaml"

print("Running this command:")
print(" ".join(command))
dagit_process = subprocess.Popen(command)
sleep(6)

driver = webdriver.Chrome()
driver.set_window_size(
screenshot_spec.get("width", 1024 * 1.3), screenshot_spec.get("height", 768 * 1.3)
)
driver.get(screenshot_spec["url"])
sleep(1)

if "steps" in screenshot_spec:
for step in screenshot_spec["steps"]:
print(step)
input("Press Enter to continue...")

screenshot_path = os.path.join("docs/next/public/images", screenshot_spec["path"])
driver.get_screenshot_as_file(screenshot_path)
print(f"Saved screenshot to {screenshot_path}")
driver.quit()
finally:
if dagit_process:
dagit_process.send_signal(signal.SIGINT)
dagit_process.wait()
def capture_screenshot(screenshot_spec: Sequence[Mapping[str, str]], save_path: str) -> None:
dagit_process = None
try:
defs_file = screenshot_spec.get("defs_file")
if defs_file:
if defs_file.endswith(".py"):
command = ["dagit", "-f", defs_file]
elif defs_file.endswith(".yaml"):
command = ["dagit", "-w", defs_file]
else:
assert False, "defs_file must be .py or .yaml"

print("Running this command:")
print(" ".join(command))
dagit_process = subprocess.Popen(command)
sleep(6)

driver = webdriver.Chrome()
driver.set_window_size(
screenshot_spec.get("width", 1024 * 1.3), screenshot_spec.get("height", 768 * 1.3)
)
driver.get(screenshot_spec["url"])
sleep(screenshot_spec.get("page_load_sleep", 1))

if "steps" in screenshot_spec:
for step in screenshot_spec["steps"]:
print(step)
input("Press Enter to continue...")

full_save_path = os.path.join("docs/next/public/images", save_path)
os.makedirs(os.path.dirname(full_save_path), exist_ok=True)
driver.get_screenshot_as_file(full_save_path)
print(f"Saved screenshot to {full_save_path}")
driver.quit()
finally:
if dagit_process:
dagit_process.send_signal(signal.SIGINT)
dagit_process.wait()


def find_screenshot_spec(screenshot_path: str) -> Mapping[str, Any]:
components = screenshot_path.split("/")
screenshot_specs_file_path = (
os.path.join(".", "docs", "screenshot_capture", *components[:-1]) + ".yaml"
)
screenshot_name = components[-1]
if os.path.exists(screenshot_specs_file_path):
screenshot_specs = load_screenshot_specs(screenshot_specs_file_path)
matching_specs = [spec for spec in screenshot_specs if spec["path"] == screenshot_name]
else:
print(f"{screenshot_specs_file_path} does not exist. Looking in mega screenshots.yaml.")
screenshot_specs = load_screenshot_specs("./docs/screenshot_capture/screenshots.yaml")
matching_specs = [spec for spec in screenshot_specs if spec["path"] == screenshot_path]


def main():
screenshot_specs = load_screenshot_specs()

assert len(sys.argv) > 1
screenshot_name = sys.argv[1]
matching_specs = [spec for spec in screenshot_specs if spec["path"] == screenshot_name]
if len(matching_specs) > 1:
print("Multiple matching screenshot paths")
sys.exit(1)
Expand All @@ -78,7 +86,14 @@ def main():
print("No matching screenshot paths")
sys.exit(1)

capture_screenshots(matching_specs)
return matching_specs[0]


def main():
assert len(sys.argv) > 1
screenshot_path = sys.argv[1]
screenshot_spec = find_screenshot_spec(screenshot_path)
capture_screenshot(screenshot_spec, screenshot_path)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- path: defining_an_asset.png
defs_file: examples/docs_snippets/docs_snippets/guides/dagster/asset_tutorial/cereal.py
url: http://127.0.0.1:3000/

- path: asset_run.png
defs_file: examples/docs_snippets/docs_snippets/guides/dagster/asset_tutorial/cereal.py
url: http://127.0.0.1:3000/
steps:
- launch a run and click on the run

- path: asset_details.png
defs_file: examples/docs_snippets/docs_snippets/guides/dagster/asset_tutorial/cereal.py
url: http://127.0.0.1:3000/instance/assets/cereals
steps:
- hit the materialize button and then close the run toast
16 changes: 0 additions & 16 deletions docs/screenshot_capture/screenshots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,6 @@
# Asset tutorial
#################

- path: guides/asset-tutorial/defining_an_asset.png
defs_file: examples/docs_snippets/docs_snippets/guides/dagster/asset_tutorial/cereal.py
url: http://127.0.0.1:3000/

- path: guides/asset-tutorial/asset_run.png
defs_file: examples/docs_snippets/docs_snippets/guides/dagster/asset_tutorial/cereal.py
url: http://127.0.0.1:3000/
steps:
- launch a run and click on the run

- path: guides/asset-tutorial/asset_details.png
defs_file: examples/docs_snippets/docs_snippets/guides/dagster/asset_tutorial/cereal.py
url: http://127.0.0.1:3000/instance/assets/cereals
steps:
- hit the materialize button and then close the run toast

- path: guides/asset-tutorial/serial_asset_graph.png
defs_file: examples/docs_snippets/docs_snippets/guides/dagster/asset_tutorial/serial_asset_graph.py
url: http://127.0.0.1:3000/
Expand Down

1 comment on commit a0cc868

@vercel
Copy link

@vercel vercel bot commented on a0cc868 Apr 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.