Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[components][rfc] @component_loader decorator #27182

Merged

Conversation

OwenKephart
Copy link
Contributor

@OwenKephart OwenKephart commented Jan 16, 2025

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:

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

@OwenKephart OwenKephart force-pushed the 01-16-_components_rfc_component_loader_decorator branch from 80276e1 to 7d764bb Compare January 16, 2025 23:29
Copy link
Member

@schrockn schrockn left a comment

Choose a reason for hiding this comment

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

We could go all the way and do this?

@component_decl
def load(context: ComponentLoadContext) -> PipesSubprocessScriptCollectionParams:
   return PipesSubprocessScriptCollectionParams(
        scripts=[
            PipesSubprocessScriptParams(
                path="cool_script.py",
                assets=[
                    AssetAttributesModel(
                        key="cool_script",
                        automation_condition="{{ automation_condition.eager() }}",
                    ),
                ],
            ),
        ]
    )

@OwenKephart OwenKephart force-pushed the 01-16-_components_refactor_component_load_behavior branch from 3c6e30f to 8e92e27 Compare January 22, 2025 23:04
@OwenKephart OwenKephart force-pushed the 01-16-_components_rfc_component_loader_decorator branch from 7d764bb to 3326d2f Compare January 22, 2025 23:04
@OwenKephart OwenKephart force-pushed the 01-16-_components_refactor_component_load_behavior branch from 8e92e27 to 82497f2 Compare January 22, 2025 23:43
@OwenKephart OwenKephart force-pushed the 01-16-_components_rfc_component_loader_decorator branch from 3326d2f to a602eb7 Compare January 22, 2025 23:43
@OwenKephart OwenKephart force-pushed the 01-16-_components_refactor_component_load_behavior branch from 82497f2 to 5ee4d47 Compare January 23, 2025 00:22
@OwenKephart OwenKephart force-pushed the 01-16-_components_rfc_component_loader_decorator branch from a602eb7 to 202ebb1 Compare January 23, 2025 00:22
@OwenKephart OwenKephart force-pushed the 01-16-_components_refactor_component_load_behavior branch from 5ee4d47 to fcca097 Compare January 23, 2025 01:06
@OwenKephart OwenKephart force-pushed the 01-16-_components_rfc_component_loader_decorator branch from 202ebb1 to 9ea40e6 Compare January 23, 2025 01:06
Copy link
Contributor Author

I think I prefer leaving the init method accessible to the user here. This gives the user more control over what actually happens, and means that if we do come up with a good theory about how to craft a nice set of init args for a given component then users are able to access that with the same interface

@OwenKephart OwenKephart requested a review from schrockn January 23, 2025 01:08
@OwenKephart OwenKephart changed the base branch from 01-16-_components_refactor_component_load_behavior to graphite-base/27182 January 23, 2025 01:46
@OwenKephart OwenKephart force-pushed the 01-16-_components_rfc_component_loader_decorator branch from 9ea40e6 to f3750af Compare January 23, 2025 01:49
@OwenKephart OwenKephart changed the base branch from graphite-base/27182 to master January 23, 2025 01:49
@OwenKephart OwenKephart force-pushed the 01-16-_components_rfc_component_loader_decorator branch from f3750af to 6e8f617 Compare January 23, 2025 01:49
@OwenKephart OwenKephart force-pushed the 01-16-_components_rfc_component_loader_decorator branch from 6e8f617 to abab2a4 Compare January 23, 2025 17:50
@OwenKephart OwenKephart force-pushed the 01-16-_components_rfc_component_loader_decorator branch from abab2a4 to 4483a34 Compare January 23, 2025 23:53
Copy link
Contributor Author

OwenKephart commented Jan 24, 2025

Merge activity

  • Jan 23, 7:00 PM EST: A user started a stack merge that includes this pull request via Graphite.
  • Jan 23, 7:00 PM EST: A user merged this pull request with Graphite.

@OwenKephart OwenKephart merged commit 5db5906 into master Jan 24, 2025
4 of 5 checks passed
@OwenKephart OwenKephart deleted the 01-16-_components_rfc_component_loader_decorator branch January 24, 2025 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants