From 851d50d395475941d4a61290ad792dd50f7e9890 Mon Sep 17 00:00:00 2001 From: Maxime Armstrong <46797220+maximearmstrong@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:03:38 -0400 Subject: [PATCH] Update tutorials to remove Dagster code from `__init__.py` (code) (#23346) ## Summary & Motivation This PR updates tutorial examples to remove Dagster code from `__init__.py`: - tutorial - tutorial_notebook_assets ## How I Tested These Changes Deployed locally BK with existing tests --- examples/tutorial/dagster_cloud.yaml | 2 +- examples/tutorial/pyproject.toml | 3 ++- examples/tutorial/tutorial/__init__.py | 9 --------- examples/tutorial/tutorial/definitions.py | 9 +++++++++ .../tutorial/{resources/__init__.py => resources.py} | 0 .../tutorial_finished/__init__.py | 9 --------- .../tutorial_finished/{assets/__init__.py => assets.py} | 2 +- .../tutorial_finished/definitions.py | 9 +++++++++ .../tutorial_template/__init__.py | 9 --------- .../tutorial_template/{assets/__init__.py => assets.py} | 2 +- .../tutorial_template/definitions.py | 9 +++++++++ examples/tutorial_notebook_assets/workspace.yaml | 6 ++++-- 12 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 examples/tutorial/tutorial/definitions.py rename examples/tutorial/tutorial/{resources/__init__.py => resources.py} (100%) rename examples/tutorial_notebook_assets/tutorial_finished/{assets/__init__.py => assets.py} (89%) create mode 100644 examples/tutorial_notebook_assets/tutorial_finished/definitions.py rename examples/tutorial_notebook_assets/tutorial_template/{assets/__init__.py => assets.py} (93%) create mode 100644 examples/tutorial_notebook_assets/tutorial_template/definitions.py diff --git a/examples/tutorial/dagster_cloud.yaml b/examples/tutorial/dagster_cloud.yaml index 95f327365ed2e..90b7ca408c37c 100644 --- a/examples/tutorial/dagster_cloud.yaml +++ b/examples/tutorial/dagster_cloud.yaml @@ -1,4 +1,4 @@ locations: - location_name: tutorial code_source: - package_name: tutorial + module_name: tutorial.definitions diff --git a/examples/tutorial/pyproject.toml b/examples/tutorial/pyproject.toml index 136d3effa6b10..5594bcc4d06aa 100644 --- a/examples/tutorial/pyproject.toml +++ b/examples/tutorial/pyproject.toml @@ -3,4 +3,5 @@ requires = ["setuptools"] build-backend = "setuptools.build_meta" [tool.dagster] -module_name = "tutorial" +module_name = "tutorial.definitions" +code_location_name = "tutorial" diff --git a/examples/tutorial/tutorial/__init__.py b/examples/tutorial/tutorial/__init__.py index a36556aa3da5d..e69de29bb2d1d 100644 --- a/examples/tutorial/tutorial/__init__.py +++ b/examples/tutorial/tutorial/__init__.py @@ -1,9 +0,0 @@ -from dagster import Definitions, load_assets_from_modules - -from . import assets - -all_assets = load_assets_from_modules([assets]) - -defs = Definitions( - assets=all_assets, -) diff --git a/examples/tutorial/tutorial/definitions.py b/examples/tutorial/tutorial/definitions.py new file mode 100644 index 0000000000000..a36556aa3da5d --- /dev/null +++ b/examples/tutorial/tutorial/definitions.py @@ -0,0 +1,9 @@ +from dagster import Definitions, load_assets_from_modules + +from . import assets + +all_assets = load_assets_from_modules([assets]) + +defs = Definitions( + assets=all_assets, +) diff --git a/examples/tutorial/tutorial/resources/__init__.py b/examples/tutorial/tutorial/resources.py similarity index 100% rename from examples/tutorial/tutorial/resources/__init__.py rename to examples/tutorial/tutorial/resources.py diff --git a/examples/tutorial_notebook_assets/tutorial_finished/__init__.py b/examples/tutorial_notebook_assets/tutorial_finished/__init__.py index 0b46c59bc3ff3..e69de29bb2d1d 100644 --- a/examples/tutorial_notebook_assets/tutorial_finished/__init__.py +++ b/examples/tutorial_notebook_assets/tutorial_finished/__init__.py @@ -1,9 +0,0 @@ -from dagster import Definitions, load_assets_from_package_module -from dagstermill import ConfigurableLocalOutputNotebookIOManager - -from . import assets - -defs = Definitions( - assets=load_assets_from_package_module(assets), - resources={"output_notebook_io_manager": ConfigurableLocalOutputNotebookIOManager()}, -) diff --git a/examples/tutorial_notebook_assets/tutorial_finished/assets/__init__.py b/examples/tutorial_notebook_assets/tutorial_finished/assets.py similarity index 89% rename from examples/tutorial_notebook_assets/tutorial_finished/assets/__init__.py rename to examples/tutorial_notebook_assets/tutorial_finished/assets.py index 19c4b250ffd77..93399734bd4fb 100644 --- a/examples/tutorial_notebook_assets/tutorial_finished/assets/__init__.py +++ b/examples/tutorial_notebook_assets/tutorial_finished/assets.py @@ -22,7 +22,7 @@ def iris_dataset_finished(): iris_kmeans_jupyter_notebook_finished = define_dagstermill_asset( name="iris_kmeans_jupyter_finished", - notebook_path=file_relative_path(__file__, "../notebooks/iris-kmeans.ipynb"), + notebook_path=file_relative_path(__file__, "notebooks/iris-kmeans.ipynb"), ins={"iris": AssetIn("iris_dataset_finished")}, group_name="finished_tutorial", ) diff --git a/examples/tutorial_notebook_assets/tutorial_finished/definitions.py b/examples/tutorial_notebook_assets/tutorial_finished/definitions.py new file mode 100644 index 0000000000000..4b10062dbdee7 --- /dev/null +++ b/examples/tutorial_notebook_assets/tutorial_finished/definitions.py @@ -0,0 +1,9 @@ +from dagster import Definitions, load_assets_from_modules +from dagstermill import ConfigurableLocalOutputNotebookIOManager + +from . import assets + +defs = Definitions( + assets=load_assets_from_modules([assets]), + resources={"output_notebook_io_manager": ConfigurableLocalOutputNotebookIOManager()}, +) diff --git a/examples/tutorial_notebook_assets/tutorial_template/__init__.py b/examples/tutorial_notebook_assets/tutorial_template/__init__.py index 94cf0fb97e6c4..e69de29bb2d1d 100644 --- a/examples/tutorial_notebook_assets/tutorial_template/__init__.py +++ b/examples/tutorial_notebook_assets/tutorial_template/__init__.py @@ -1,9 +0,0 @@ -# from dagster import Definitions, load_assets_from_package_module -# from dagstermill import ConfigurableLocalOutputNotebookIOManager - -# from . import assets - -# defs = Definitions( -# assets=load_assets_from_package_module(assets), -# resources={"output_notebook_io_manager": ConfigurableLocalOutputNotebookIOManager()}, -# ) diff --git a/examples/tutorial_notebook_assets/tutorial_template/assets/__init__.py b/examples/tutorial_notebook_assets/tutorial_template/assets.py similarity index 93% rename from examples/tutorial_notebook_assets/tutorial_template/assets/__init__.py rename to examples/tutorial_notebook_assets/tutorial_template/assets.py index 3d8b54b9ad99d..138e7f6ced97a 100644 --- a/examples/tutorial_notebook_assets/tutorial_template/assets/__init__.py +++ b/examples/tutorial_notebook_assets/tutorial_template/assets.py @@ -28,7 +28,7 @@ # iris_kmeans_jupyter_notebook = define_dagstermill_asset( # name="iris_kmeans_jupyter", -# notebook_path=file_relative_path(__file__, "../notebooks/iris-kmeans.ipynb"), +# notebook_path=file_relative_path(__file__, "notebooks/iris-kmeans.ipynb"), # group_name="template_tutorial", # # ins={"iris": AssetIn("iris_dataset")}, # this code to remain commented until TODO 3 # ) diff --git a/examples/tutorial_notebook_assets/tutorial_template/definitions.py b/examples/tutorial_notebook_assets/tutorial_template/definitions.py new file mode 100644 index 0000000000000..5f3926b386a04 --- /dev/null +++ b/examples/tutorial_notebook_assets/tutorial_template/definitions.py @@ -0,0 +1,9 @@ +# from dagster import Definitions, load_assets_from_modules +# from dagstermill import ConfigurableLocalOutputNotebookIOManager + +# from . import assets + +# defs = Definitions( +# assets=load_assets_from_modules([assets]), +# resources={"output_notebook_io_manager": ConfigurableLocalOutputNotebookIOManager()}, +# ) diff --git a/examples/tutorial_notebook_assets/workspace.yaml b/examples/tutorial_notebook_assets/workspace.yaml index 0e92c6a004887..bf952c8593db8 100644 --- a/examples/tutorial_notebook_assets/workspace.yaml +++ b/examples/tutorial_notebook_assets/workspace.yaml @@ -1,5 +1,7 @@ load_from: - python_package: - package_name: tutorial_template + package_name: tutorial_template.definitions + location_name: tutorial_template - python_package: - package_name: tutorial_finished + package_name: tutorial_finished.definitions + location_name: tutorial_finished