Exemplo n.º 1
0
 def copy_for_configured(
     self,
     name: str,
     description: Optional[str],
     config_schema: Any,
     config_or_config_fn: Any,
 ):
     if not self.has_config_mapping:
         raise DagsterInvalidDefinitionError(
             "Only graphs utilizing config mapping can be pre-configured. The graph "
             '"{graph_name}" does not have a config mapping, and thus has nothing to be '
             "configured.".format(graph_name=self.name))
     config_mapping = cast(ConfigMapping, self.config_mapping)
     return GraphDefinition(
         name=name,
         description=check.opt_str_param(description,
                                         "description",
                                         default=self.description),
         node_defs=self._node_defs,
         dependencies=self._dependencies,
         input_mappings=self._input_mappings,
         output_mappings=self._output_mappings,
         config=ConfigMapping(
             config_mapping.config_fn,
             config_schema=config_schema,
             receive_processed_config_values=config_mapping.
             receive_processed_config_values,
         ),
     )
Exemplo n.º 2
0
def _config_mapping_with_default_value(
    inner_schema: ConfigType,
    default_config: Dict[str, Any],
    job_name: str,
    graph_name: str,
) -> ConfigMapping:
    if not isinstance(inner_schema, Shape):
        check.failed(
            "Only Shape (dictionary) config_schema allowed on Job ConfigMapping"
        )

    def config_fn(x):
        return x

    updated_fields = {}
    field_aliases = inner_schema.field_aliases
    for name, field in inner_schema.fields.items():
        if name in default_config:
            updated_fields[name] = Field(
                config=field.config_type,
                default_value=default_config[name],
                description=field.description,
            )
        elif name in field_aliases and field_aliases[name] in default_config:
            updated_fields[name] = Field(
                config=field.config_type,
                default_value=default_config[field_aliases[name]],
                description=field.description,
            )
        else:
            updated_fields[name] = field

    config_schema = Shape(
        fields=updated_fields,
        description="run config schema with default values from default_config",
        field_aliases=inner_schema.field_aliases,
    )

    config_evr = validate_config(config_schema, default_config)
    if not config_evr.success:
        raise DagsterInvalidConfigError(
            f"Error in config when building job '{job_name}' from graph '{graph_name}' ",
            config_evr.errors,
            default_config,
        )

    return ConfigMapping(config_fn=config_fn,
                         config_schema=config_schema,
                         receive_processed_config_values=False)
Exemplo n.º 3
0
def _config_mapping_with_default_value(
    inner_schema: ConfigType,
    default_config: Dict[str, Any],
) -> ConfigMapping:
    if not isinstance(inner_schema, Shape):
        check.failed(
            "Only Shape (dictionary) config_schema allowed on Job ConfigMapping"
        )

    def config_fn(x):
        return x

    updated_fields = {}
    field_aliases = inner_schema.field_aliases
    for name, field in inner_schema.fields.items():
        if name in default_config:
            updated_fields[name] = Field(
                config=field.config_type,
                default_value=default_config[name],
                description=field.description,
            )
        elif name in field_aliases and field_aliases[name] in default_config:
            updated_fields[name] = Field(
                config=field.config_type,
                default_value=default_config[field_aliases[name]],
                description=field.description,
            )

    return ConfigMapping(
        config_fn=config_fn,
        config_schema=Shape(
            fields=updated_fields,
            description=
            "run config schema with default values from default_config",
        ),
    )