fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] How to dynamically define tasks in different modules?


From: Brandon Whaley
Subject: Re: [Fab-user] How to dynamically define tasks in different modules?
Date: Wed, 18 Nov 2015 14:08:34 +0000

Hi Chris,

If I'm not mistaken, extract_tasks is only looking for modules in the fabfile.py namespace and only runs once at import time.  Have you tried executing your code at the end of your fabfile so the arbitrarily named module is in that namespace at import time?

On Wed, Nov 18, 2015 at 12:39 AM Chris Spencer <address@hidden> wrote:
Is it possible to dynamically expose tasks in a namespace other than the module in which they appear?

Say I have the file `myfabtasks.py` containing the tasks `configure_apache`. By default, Fabric exposes this as `myfabtasks.configure_apache`, which is a little clunky. How would I expose it as `apache.configure` without renaming my module filename and task?

My goal is to make tasks class-based, and I'm currently able to dynamically create tasks with arbitrary names, but they're still restricted to the namespace of their module's filename, which causes conflicts if I have two classes in the same file that have the same method name.

I spent some time digging through the code, specifically in main.py and the `extract_tasks` function, but this behavior unfortunately seems to be hardcoded. Is there any workaround?

I tried dynamically creating a module with an arbitrary name and reassigning my tasks there, as explained at http://stackoverflow.com/questions/3799545/dynamically-importing-python-module/3799609#3799609, but Fab never seems to find the dynamic module.
_______________________________________________
Fab-user mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/fab-user

reply via email to

[Prev in Thread] Current Thread [Next in Thread]