-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[components] allow automation_condition to be set with AssetSpecModel (…
…#26451) ## Summary & Motivation As title. ## How I Tested These Changes ## Changelog NOCHANGELOG
- Loading branch information
1 parent
d3bd3f4
commit a64aa2c
Showing
8 changed files
with
114 additions
and
9 deletions.
There are no files selected for viewing
53 changes: 52 additions & 1 deletion
53
python_modules/libraries/dagster-components/dagster_components/core/dsl_schema.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 |
---|---|---|
@@ -1,8 +1,59 @@ | ||
from typing import Dict, Optional | ||
from typing import Any, Dict, Literal, Mapping, Optional, Union | ||
|
||
from dagster._core.definitions.asset_spec import AssetSpec, map_asset_specs | ||
from dagster._core.definitions.assets import AssetsDefinition | ||
from dagster._core.definitions.declarative_automation.automation_condition import ( | ||
AutomationCondition, | ||
) | ||
from dagster._core.definitions.definitions_class import Definitions | ||
from dagster._record import replace | ||
from dagster._utils.warnings import suppress_dagster_warnings | ||
from pydantic import BaseModel | ||
|
||
|
||
class OpSpecBaseModel(BaseModel): | ||
name: Optional[str] = None | ||
tags: Optional[Dict[str, str]] = None | ||
|
||
|
||
class AutomationConditionModel(BaseModel): | ||
type: str | ||
params: Mapping[str, Any] = {} | ||
|
||
def to_automation_condition(self) -> AutomationCondition: | ||
return getattr(AutomationCondition, self.type)(**self.params) | ||
|
||
|
||
class AssetSpecProcessorModel(BaseModel): | ||
target: str = "*" | ||
strategy: Union[Literal["replace"], Literal["merge"]] = "replace" | ||
description: Optional[str] = None | ||
metadata: Optional[Mapping[str, Any]] = None | ||
group_name: Optional[str] = None | ||
tags: Optional[Mapping[str, str]] = None | ||
automation_condition: Optional[AutomationConditionModel] = None | ||
|
||
def _props(self) -> Mapping[str, Any]: | ||
return { | ||
**self.model_dump(exclude={"target", "strategy"}), | ||
"automation_condition": self.automation_condition.to_automation_condition() | ||
if self.automation_condition | ||
else None, | ||
} | ||
|
||
@suppress_dagster_warnings | ||
def _apply_to_spec(self, spec: AssetSpec) -> AssetSpec: | ||
if self.strategy == "replace": | ||
return spec.replace_attributes(**self._props()) | ||
else: | ||
return spec.merge_attributes(**self._props()) | ||
|
||
def transform(self, defs: Definitions) -> Definitions: | ||
"""Applies the specified transformation to the asset specs in the given definitions.""" | ||
mappable = [d for d in defs.assets or [] if isinstance(d, (AssetsDefinition, AssetSpec))] | ||
mapped_assets = map_asset_specs(self._apply_to_spec, mappable) | ||
assets = [ | ||
*mapped_assets, | ||
*[d for d in defs.assets or [] if not isinstance(d, (AssetsDefinition, AssetSpec))], | ||
] | ||
return replace(defs, assets=assets) |
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
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
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