Skip to content Skip to sidebar Skip to footer

Implicitly Called Task / Function On Python Fabric Startup?

There are a few environment variables I need to set in Fabric each invocation and so far I'm doing something like: env['FOO'] = 'one' @task def one(): env['FOO'] = 'one' p

Solution 1:

You can make your task a subclass of a custom class with certain attributes that are passed as parameters:

from fabric.api import task
from fabric.tasks import Task

class CustomTask(Task):
    def __init__(self, func, *args, **kwargs):
        super(CustomTask, self).__init__(*args, **kwargs)
        self.func = func
        self.foo = "one"

    def run(self, *args, **kwargs):
        return self.func(self.foo, *args, **kwargs)

@task(task_class=CustomTask)
def one(foo):
    print(cyan('Using FOO %s' % foo))

Post a Comment for "Implicitly Called Task / Function On Python Fabric Startup?"