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] Rename component to component_type #26718

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/content/api/modules.json.gz
Binary file not shown.
Binary file modified docs/content/api/searchindex.json.gz
Binary file not shown.
Binary file modified docs/content/api/sections.json.gz
Binary file not shown.
Binary file modified docs/next/public/objects.inv
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ComponentGenerateRequest as ComponentGenerateRequest,
ComponentLoadContext as ComponentLoadContext,
ComponentRegistry as ComponentRegistry,
component as component,
component_type as component_type,
)
from dagster_components.core.component_defs_builder import (
build_component_defs as build_component_defs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,17 @@ def load_params(self, params_schema: Type[T]) -> T:
COMPONENT_REGISTRY_KEY_ATTR = "__dagster_component_registry_key"


def component(
cls: Optional[Type[Component]] = None,
*,
name: Optional[str] = None,
) -> Any:
def component_type(cls: Optional[Type[Component]] = None, *, name: Optional[str] = None) -> Any:
"""Decorator for registering a component type. You must annotate a component
type with this decorator in order for it to be inspectable and loaded by tools.

Args:
cls (Optional[Type[Component]]): The target of the decorator: the component class
to register. The class must inherit from Component.
name (Optional[str]): The name to register the component type under. If not
provided, the name will be the snake-cased version of the class name. The
name is used as a key in operations like scaffolding and loading.
"""
if cls is None:

def wrapper(actual_cls: Type[Component]) -> Type[Component]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from dagster_components.core.component import (
ComponentGenerateRequest,
TemplatedValueResolver,
component,
component_type,
)
from dagster_components.core.component_rendering import RenderingScope
from dagster_components.core.dsl_schema import AssetAttributes, AssetSpecProcessor, OpSpecBaseModel
Expand Down Expand Up @@ -70,7 +70,7 @@ def get_group_name(self, dbt_resource_props) -> Optional[str]:
)


@component(name="dbt_project")
@component_type(name="dbt_project")
class DbtProjectComponent(Component):
params_schema = DbtProjectParams
generate_params_schema = DbtGenerateParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
from pydantic import BaseModel
from typing_extensions import Self

from dagster_components import Component, ComponentGenerateRequest, ComponentLoadContext, component
from dagster_components import (
Component,
ComponentGenerateRequest,
ComponentLoadContext,
component_type,
)
from dagster_components.generate import generate_component_yaml


Expand All @@ -22,7 +27,7 @@ class DefinitionsParamSchema(BaseModel):
definitions_path: Optional[str] = None


@component(name="definitions")
@component_type(name="definitions")
class DefinitionsComponent(Component):
def __init__(self, definitions_path: Path):
self.definitions_path = definitions_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from dagster._utils.warnings import suppress_dagster_warnings
from pydantic import BaseModel

from dagster_components.core.component import Component, ComponentLoadContext, component
from dagster_components.core.component import Component, ComponentLoadContext, component_type
from dagster_components.core.dsl_schema import AutomationConditionModel

if TYPE_CHECKING:
Expand Down Expand Up @@ -52,7 +52,7 @@ class PipesSubprocessScriptCollectionParams(BaseModel):
scripts: Sequence[PipesSubprocessScriptParams]


@component(name="pipes_subprocess_script_collection")
@component_type(name="pipes_subprocess_script_collection")
class PipesSubprocessScriptCollection(Component):
"""Assets that wrap Python scripts executed with Dagster's PipesSubprocessClient."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from typing_extensions import Self

from dagster_components import Component, ComponentLoadContext
from dagster_components.core.component import ComponentGenerateRequest, component
from dagster_components.core.component import ComponentGenerateRequest, component_type
from dagster_components.core.dsl_schema import AssetAttributes, AssetSpecProcessor, OpSpecBaseModel
from dagster_components.generate import generate_component_yaml

Expand All @@ -23,7 +23,7 @@ class SlingReplicationParams(BaseModel):
asset_attributes: Optional[AssetAttributes] = None


@component(name="sling_replication")
@component_type(name="sling_replication")
class SlingReplicationComponent(Component):
params_schema = SlingReplicationParams

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dagster._core.execution.context.asset_execution_context import AssetExecutionContext
from typing_extensions import Self

from dagster_components import Component, ComponentLoadContext, component
from dagster_components import Component, ComponentLoadContext, component_type
from dagster_components.core.component import ComponentGenerateRequest
from dagster_components.core.component_decl_builder import YamlComponentDecl
from dagster_components.generate import generate_component_yaml
Expand All @@ -14,7 +14,7 @@
from dagster_components.core.component import ComponentDeclNode


@component(name="all_metadata_empty_asset")
@component_type(name="all_metadata_empty_asset")
class AllMetadataEmptyAsset(Component):
@classmethod
def from_decl_node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pydantic import BaseModel, TypeAdapter
from typing_extensions import Self

from dagster_components import Component, ComponentLoadContext, component
from dagster_components import Component, ComponentLoadContext, component_type
from dagster_components.core.component import ComponentGenerateRequest
from dagster_components.core.component_decl_builder import YamlComponentDecl
from dagster_components.generate import generate_component_yaml
Expand All @@ -21,7 +21,7 @@ class SimpleAssetParams(BaseModel):
value: str


@component(name="simple_asset")
@component_type(name="simple_asset")
class SimpleAsset(Component):
"""A simple asset that returns a constant string value."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pydantic import BaseModel, TypeAdapter
from typing_extensions import Self

from dagster_components import Component, ComponentLoadContext, component
from dagster_components import Component, ComponentLoadContext, component_type
from dagster_components.core.component import ComponentGenerateRequest
from dagster_components.core.component_decl_builder import YamlComponentDecl
from dagster_components.generate import generate_component_yaml
Expand Down Expand Up @@ -43,7 +43,7 @@ def cli(asset_key: str, filename: str) -> "SimplePipesScriptAssetParams":
"""


@component(name="simple_pipes_script_asset")
@component_type(name="simple_pipes_script_asset")
class SimplePipesScriptAsset(Component):
"""A simple asset that runs a Python script with the Pipes subprocess client.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Iterator

from dagster._core.execution.context.asset_execution_context import AssetExecutionContext
from dagster_components import component
from dagster_components import component_type
from dagster_components.lib.sling_replication import SlingReplicationComponent
from dagster_embedded_elt.sling import SlingResource


@component(name="debug_sling_replication")
@component_type(name="debug_sling_replication")
class DebugSlingReplicationComponent(SlingReplicationComponent):
def execute(self, context: AssetExecutionContext, sling: SlingResource) -> Iterator:
return sling.replicate(context=context, debug=True)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
YamlComponentDecl,
build_components_from_component_folder,
)
from dagster_components.lib.sling_replication import SlingReplicationComponent, component
from dagster_components.lib.sling_replication import SlingReplicationComponent, component_type
from dagster_embedded_elt.sling import SlingResource

from dagster_components_tests.utils import assert_assets, get_asset_keys, script_load_context
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_load_from_path(sling_path: Path) -> None:


def test_sling_subclass() -> None:
@component(name="debug_sling_replication")
@component_type(name="debug_sling_replication")
class DebugSlingReplicationComponent(SlingReplicationComponent):
def execute(
self, context: AssetExecutionContext, sling: SlingResource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Mapping

from dagster import AssetSpec, AutomationCondition, Definitions
from dagster_components import Component, ComponentLoadContext, component
from dagster_components import Component, ComponentLoadContext, component_type
from pydantic import BaseModel


Expand All @@ -17,7 +17,7 @@ class CustomScopeParams(BaseModel):
attributes: Mapping[str, Any]


@component(name="custom_scope_component")
@component_type(name="custom_scope_component")
class HasCustomScope(Component):
params_schema = CustomScopeParams

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
from dagster_components import Component, component
from dagster_components import Component, component_type
from dagster_components.core.component import get_component_name, is_registered_component


def test_registered_component_with_default_name() -> None:
@component
@component_type
class RegisteredComponent(Component): ...

assert is_registered_component(RegisteredComponent)
assert get_component_name(RegisteredComponent) == "registered_component"


def test_registered_component_with_default_name_and_parens() -> None:
@component()
@component_type()
class RegisteredComponent(Component): ...

assert is_registered_component(RegisteredComponent)
assert get_component_name(RegisteredComponent) == "registered_component"


def test_registered_component_with_explicit_kwarg_name() -> None:
@component(name="explicit_name")
@component_type(name="explicit_name")
class RegisteredComponent(Component): ...

assert is_registered_component(RegisteredComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def _find_repo_root():

def _generate_test_component_source(number: int) -> str:
return textwrap.dedent(f"""
from dagster_components import Component, component
@component(name="test_component_{number}")
from dagster_components import Component, component_type
@component_type(name="test_component_{number}")
class TestComponent{number}(Component):
pass
""")
Expand Down
Loading