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
Hiding tasks from --listing #678
Comments
|
I'm -1 on this, especially given that the underscore prefix is already in use for classic-style tasks, and even if it weren't, I think it's just too confusing/complicated an API for a feature that IMHO doesn't make a ton of sense. If it's a legit task, it should be in the list -- if it's not a legit task, it should just be a Python function and not a task! There are several workarounds you could employ without changing Fabric core:
If a good enough argument can be made that "a task but not a task" is a legit use case, I think the best real solution is to have an explicit |
|
Thanks for your answer! I'll respond to your comments inline.
Can I execute old-style tasks if I am using
That's good to know!
Yes, this is my best bet as of today. Not the prettiest, but would probably work enough.
It's the same with this as with the first counter argument; This won't make it possible for me to execute the tasks individually.
I am out of arguments. I do value simplicity, too. If you think this proposal will not take |
From the command line, no -- if the fabfile loaded contains However, and this is partly why I brought it up later on, if a submodule contains only regular "helper" functions not decorated with This is slightly inelegant, but would work in the sense of having "second-class citizen" tasks that are normally invoked as subroutines within a "main" tasks, and do not show up normally, but can be loaded directly when you really need them.
Thanks, I appreciate it. I sympathize with the greater issue of "managing nontrivial collections of tasks is kind of crappy" because that is most definitely a problem, but I'm not convinced this particular approach is a great solution. I'll be re-examining this whole problem space soon with Invoke and hopefully something better will come out of it. |
|
I have a use case for hidden tasks in my project, as follows. We are using fab to deploy some web applications, and each application has multiple 'environments' on the remote server, one for production, staging, testing etc. I am handling this like follows in my fab files @task
def production():
_setup_path('production')
@task
def staging():
_setup_path('staging')
@task
def some_real_task():
require('environment', provided_by=('staging', 'production'))
# do the stuff with the thingsthe tasks 'staging' and 'production' are never actually run on their own, always before some other task like if the staging and production functions are not tasks, it bails out giving me a list of available tasks there are a few reasons we have the environments as tasks, and not arguments to each task, and i would like to keep the setup the way we have it. a task decorator kwarg to hide the tasks seems like the best solution to me also, i can see a few other use cases for hiding tasks the way we have constructed our deployment tasks is with many small, simple tasks that are called with execute in the deploy.full task (which is also the default task for the deploy namespace). most of the times, the only command you need to use is deploy.full, but the ability to push out JUST a specific piece is required, so they are left as commands. but this leaves us with many, mostly unused, commands in the list. if they could be hidden, it would increase the readability of the command list, and then perhaps a new flag --list-all could be implemented to list the hidden tasks. |
|
Here is how I ended up doing mine visually ... doesn't help if you have 20+ |
|
you can specify all with list of tasks that should be displayed with |
|
I think the issue with from fabric.api import task
__all__ = ['tester1']
@task
def tester1():
print "This one shows up."
@task
def tester2():
print "This one doesn't."If my init.py is as follows: import testerThe only task that shows up when I run |
|
I'm new to python, but here's what I have done. All the 'helper' code is in a class, then the fabfile has wrapper functions for anything I'd like to see via fabfile.py Good news is it keeps fabfile.py short and sweet. Downside is there's a little extra typing, and a tiny annoyance, AppDeploy will show in the listing with EDIT |
|
From here (mail.python.org > python-ideas): __all__ = []
def export(f):
sys._getframe(1).f_globals.setdefault("__all__", []).append(f.__name__)
return f
def do_stuff1():
pass
@export
def do_stuff2():
passWhich results in this: |
I have a larger fabric script that contains a bunch of different tasks. Initially I would issue
but then the number of tasks grew in proportion so much that I created a single task so that I could issue my command like so
and it would issue all initial tasks using the
execute(...)function. Now when I issuefab --listI get a fairly long list of tasks that I'm 99% of the times am not interested in executing. Request: Be able to hide certain tasks from--listing.Now you may be wondering why I simply can't remove
@taskdecorator and make basic function calls from my bigtask task. Two reasons:@runs_oncedecorator while others aren't. I expect that decorator to not work for non-@tasks. Am I wrong?To concretize, my proposal is as follows: Never list tasks with names starting with an underscore,
_, unless the filter proposed in #134 is in use. This proposal goes hand in hand with the Pythonesque way of making functions private.What do you think of this?
The text was updated successfully, but these errors were encountered: