New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running a task from inside a Python script #112
Comments
I am having the same issue. Any ideas how to do this? |
Say you have your
Just call |
Yes, but it will not execute it's dependencies if it has any. From my -Leo
|
@leourbina you're right. I guess what you're looking for is something like fabric's execute: http://docs.fabfile.org/en/1.8/api/core/tasks.html?highlight=execute#fabric.tasks.execute Unfortunately I don't think invoke has an equivalent. The closest way I could find to manage your own context is this: from invoke import run, task, Collection
from invoke.executor import Executor
from invoke.context import Context
@task
def mytask():
run("ls .")
def main():
collection = Collection(mytask)
context = Context()
executor = Executor(collection, context)
executor.execute("mytask")
if __name__ == '__main__':
main() |
The problem with this solution is that I cannot use the built in invoke command line to list tasks, etc, and somewhat have to redo that if I were to use your solution. One idea that comes to mind is making the executor a singleton. This way it would be trivial to implement an run_task function that takes the task name as the only argument and executes it by retrieving the current executor and calling the execute method on it. I'm not sure how hard this is, but I may try to cook something up later and submit a PR. Let me know if this makes sense, Best, |
@leourbina I don't see why you can't put |
From what I gather it seems that there are three ways of running a task Importing the task and calling it directly Creating a new executor and calling execute on it Calling the task using invoke's run Ideally I would like an equivalent to fabric's execute, which preserves the Best, On Mon, Apr 21, 2014 at 5:59 AM, Alex Plugaru notifications@github.comwrote:
|
It's totally correct that right now calling tasks from other tasks is clunky at best :( I'm rolling this into a newer ticket I just whipped up with a bunch of dumb brainstormy things on the topic: #170 |
Hi there,
I am new to
invoke
so please forgive my inexperience.I am trying to set up several
@task
s but I would like to be able to execute them from within aPython
script.There is plenty of excllent documentation on how to execute a task from the command line, but is this possible from within a script?
I can certainly execute a system command using
invoke.runner.run('ls -la')
, but if I had the taskhow could I use
invoke
to callmytask
from inside a script?The text was updated successfully, but these errors were encountered: