-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[components][rfc]
@component_loader
decorator (#27182)
## Summary & Motivation Adds an `@component_loader` decorator and the corresponding infrastructure to allow users to write arbitrary python code to load their Components. Note that the convention I've gone with here has the user manually call `XComponent.load()`, rather than going through the `__init__`. My thought here was basically just that this feels like better practice as it provides a common shared format between the python and yaml interfaces. In short, the way to use this is to have a `component.py` file instead of a `component.yaml` file, which will look something like: ```python from dagster_components import ComponentLoadContext, component_loader from ... import MyComponentClass @component_loader def load(context: ComponentLoadContext) -> MyComponentClass: return MyComponentClass.load( params=..., context=context, ) ``` And again, there's nothing stopping you from using the regular constructor, I just think that might be harder to use. ## How I Tested These Changes ## Changelog NOCHANGELOG
- Loading branch information
1 parent
1c7bfb3
commit 5db5906
Showing
6 changed files
with
103 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ts_tests/code_locations/python_script_location/components/script_python_decl/component.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from dagster_components import AssetAttributesModel, ComponentLoadContext | ||
from dagster_components.core.component import component_loader | ||
from dagster_components.lib import PipesSubprocessScriptCollection | ||
from dagster_components.lib.pipes_subprocess_script_collection import ( | ||
PipesSubprocessScriptCollectionParams, | ||
PipesSubprocessScriptParams, | ||
) | ||
|
||
|
||
@component_loader | ||
def load(context: ComponentLoadContext) -> PipesSubprocessScriptCollection: | ||
params = PipesSubprocessScriptCollectionParams( | ||
scripts=[ | ||
PipesSubprocessScriptParams( | ||
path="cool_script.py", | ||
assets=[ | ||
AssetAttributesModel( | ||
key="cool_script", | ||
automation_condition="{{ automation_condition.eager() }}", | ||
), | ||
], | ||
), | ||
] | ||
) | ||
return PipesSubprocessScriptCollection.load(params=params, context=context) |
6 changes: 6 additions & 0 deletions
6
..._tests/code_locations/python_script_location/components/script_python_decl/cool_script.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def do_thing() -> None: | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
do_thing() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters