close
Skip to content

Controllable pre/post task arguments #135

@bitprophet

Description

@bitprophet

I.e.:

@task
def pretask():
    pass

@task(pre='pretask')
def realtask(arg):
    pass

This will fail because at the bottom of Executor.execute() we build a task list and then give all of them the CLI arguments. I.e. pre/post tasks are given the same input as the "main" task.

The API we would need to fix this is probably:

@task
def pretask():
    pass

@task(pre={'pretask': []})
def realtask(arg):
    pass

Or, with a pretask that has an interesting signature:

@task
def pretask(myarg):
    pass

@task(pre={'pretask': ['foo']})
def realtask(arg):
    pass

Would be equivalent to calling pretask('foo') prior to calling realtask().

Allowing a dict for keyword args would also make sense; however the full implementation would want both an args list and a kwargs dict, which would then both need wrapping in a tuple or list. That gets pretty fugly pretty fast:

@task(pre={'pretask': ([], {'kwarg': 'value'}})

Another possibility (this is actually what nate-pycon on IRC originally thought of) is to reuse the parser and say e.g.:

@task(pre=['pretask --kwarg=value'])

However I think even the most complex pure-Python version above is preferable, because:

  • it's not sufficient to be the ONLY way of doing this, because forcing a serialize/deserialize step when pure Python is much faster/easier;
  • if we make it just another alternative, that's almost definitely crossing my "too many ways to do it -> confusing and overly complex code" threshold

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions