Package: dagster-fmt
dagster_fmtCreate an execution function and havedagster_fmtfill out the decorator arguments.Disclaimer: This project is not affiliated with Dagster.ExampleFor example, let's say we have the followingop:fromdagsterimportOutput,op@opdefsome_op1(context,a,b):c=context.op_config["c_field"]context.resources.some_resource.some_method(a,b,c)returnOutput(1,output_name="a")There are a couple of things we can infer from the body of the execution function:There must be a configuration field calledc_fieldbecause of it's access on line 3There must be a resource calledsome_resourcebecause of it's access on line 4There is a single output namedafrom the return statementThecontextargument can have a type annotation ofOpExecutionContextWe also think it would be helpful to have descriptions on the op, it's inputs, config and outputs.
In the op input, aNothingdependency can also be specified for more use cases later down the road.After runningdagster_fmton the file (formatting, and import sorting), the above op is converted to the following:fromtypingimportAnyimportdagsterfromdagsterimportField,In,Nothing,OpExecutionContext,Out,Output,op@op(ins={"a":In(dagster_type=Any,description=""),"b":In(dagster_type=Any,description=""),"run_after":In(dagster_type=Nothing,description="Placeholder dependency for orchestration with other ops.",),},config_schema={"c_field":Field(config=dagster.Any,description="",is_required=True,default_value="")},out={"a":Out(description="",is_required=True)},required_resource_keys={"some_resource"},)defsome_op1(context:OpExecutionContext,a,b):"""Op description"""c=context.op_config["c_field"]context.resources.some_resource.some_method(a,b,c)returnOutput(1,output_name="a")The point of this tool is to save on a lot of typing and to create a template to fill in with descriptions and type annotations. More arguments are created than needed, but you can simply delete them.The command only modies blank ops (without arguments) as to not modify existing code.Configuration OptionsConfiguration can be specified in thepyproject.toml. The following options are listed below.In thetool.dagster_fmtsection, there are options which apply to both ops and resources. The values in the individual ops and resources sections override these values.tool.dagster_fmtadd_docstrings: boolean [default=True]Whether to add docstrings to the execution function.add_descriptions: boolean [default=True]Whether to add adescription=""to applicable dagster classes.add_is_required: boolean [default=True]Whether to add ais_required=Trueto applicable dagster classes.dir: string [default="*"]Subdirectory to format files in. For example ifdir = "ops"then runningdagster_fmt .only formats files matching the path**/ops/*.py. By default, ignore sub directories.tool.dagster_fmt.opsadd_docstrings: boolean [default=tool.dagster_fmt.add_docstrings]Whether to add docstrings to the execution function.add_descriptions: boolean [default=tool.dagster_fmt.add_descriptions]Whether to add adescription=""to Ins, Fields, Outs and DynamicOuts.add_no_data_dep_in: boolean [default=True]Whether to add adagster_type=NothingIn to the op.no_data_dep_name: string [default="run_after"]Name of the no data dependency input.add_is_required: boolean [default=tool.dagster_fmt.add_is_required]Whether to add ais_required=Trueto Fields, Outs and DynamicOuts.tool.dagster_fmt.resourcesadd_docstrings: boolean [default=tool.dagster_fmt.add_docstrings]Whether to add docstrings to the execution function.add_descriptions: boolean [default=tool.dagster_fmt.add_descriptions]Whether to add adescription=""Fields.add_is_required: boolean [default=tool.dagster_fmt.add_is_required]Whether to add ais_required=Trueto Fields.