Skip to content

Is it possible to decorate functions with @script at runtime? #1235

Answered by alicederyn
autumnkelsey asked this question in Q&A
Discussion options

You must be logged in to vote

Try calling the decorator outside of the with blocks?

def dynamicallyDecorate(*steps: Callable):
    decorated_steps = [
        script(image="python:3.11", constructor="inline")(step)
        for step in steps
    ]
    with Workflow(entrypoint="steps", generate_name="idk") as w:
        with Steps(name="steps"):
            for step in decorated_steps:
                step()
    print(w.to_yaml())

This works locally for me and produces the same yaml as staticallyDecorate

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@autumnkelsey
Comment options

Answer selected by elliotgunton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants