Permalink
Browse files

Allow override of task name using the name="" argument in @task

This enables the use of Python-reserved words as task names, without the need to create an alias eg.:
    @task(name="import")
        def _import():
        [...]
  • Loading branch information...
1 parent 239b786 commit 83d58217cf1335db6c7a401c5bf73dad83ed9a62 @dansimau committed Mar 8, 2012
Showing with 7 additions and 2 deletions.
  1. +7 −2 fabric/tasks.py
View
9 fabric/tasks.py
@@ -37,12 +37,14 @@ class Task(object):
is_default = False
# TODO: make it so that this wraps other decorators as expected
- def __init__(self, alias=None, aliases=None, default=False,
+ def __init__(self, name=None, alias=None, aliases=None, default=False,
*args, **kwargs):
if alias is not None:
self.aliases = [alias, ]
if aliases is not None:
self.aliases = aliases
+ if name is not None:
+ self.name = name
self.is_default = default
def run(self):
@@ -102,7 +104,10 @@ def __init__(self, callable, *args, **kwargs):
# Don't use getattr() here -- we want to avoid touching self.name
# entirely so the superclass' value remains default.
if hasattr(callable, '__name__'):
- self.__name__ = self.name = callable.__name__
+ if self.name == 'undefined':
+ self.__name__ = self.name = callable.__name__
+ else:
+ self.__name__ = self.name
if hasattr(callable, '__doc__'):
self.__doc__ = callable.__doc__

0 comments on commit 83d5821

Please sign in to comment.