eqasim-org / synpp

Synthetic population pipeline code for eqasim
http://www.eqasim.org
MIT License
18 stars 12 forks source link

Decorator as a stage wrapper #57

Closed davibicudo closed 3 years ago

davibicudo commented 3 years ago

I'm considering refactoring existing code to use synpp, and to avoid changing too much the code, one option that came to my mind would be to use decorator functions for converting existing functions to pipeline stages, in a similar way to pytest's parametrize. Something like:

@synpp.stage(df="module.stage1", df2="module.stage2", param="config_key")
def old_function(df1, df2, param): ...

This would be converted during process_stages (i.e. before running the pipeline) to something like:

class old_function:
    def configure(self, context):
        context.stage("module.stage1")
        context.stage("module.stage2")
        context.config("config_key")

    def execute(self, context):
        return old_function(context.stage("module.stage1"), context.stage("module.stage2"), context.config("config_key"))

Do you think this could work?

sebhoerl commented 3 years ago

Yes, could be a nice idea!

davibicudo commented 3 years ago

Implemented by #58.