Search code examples
djangopyinvoke

Python code running python invoke not executing tasks


Given the following tasks.py

from invoke import run, task

@task
def gems():
    print 'Installing Gems'
    run('echo $PWD')
    #run('export GEM_HOME=$PWD && GEM_PATH=$PWD && gem install sass')

@task('gems')
def setup():
    pass

My automation script:

import invoke
import invoke.cli

invoke.cli.parse(['-r', os.path.dirname(__file__), '--list'])

this returns

Available tasks:

  gems
  setup

But when try to execute 'gems' as below:

invoke.cli.parse(['-r', os.path.dirname(__file__), 'gems'])

It is not executing the task


Solution

  • Instead of using invoke.cli.parse should use invoke.cli.dispath like:

    invoke.cli.dispatch(['-r', os.path.dirname(__file__), 'setup'])