I'd like to create a standalone python script that uses invoke
and also includes the tasks to be executed. A minimal working example looks like:
#!/usr/bin/env python3
from invoke import task, Program
@task()
def foo(c):
print("Task...")
program = Program()
program.run()
If I name the script example.py
, I'd like to be able to take the script and do:
(py37) bash-3.00$ ./example.py foo
Task...
If I put the task in a separate file named tasks.py
, things work. The documentation shows how to put the tasks in a separate package, but not the top-level script itself. I suspect it may be possible by providing the right namespace
argument to Program()
, but I haven't found a value that works.