Permalink
Browse files

Merge branch '1.5'

  • Loading branch information...
2 parents 42c1bc6 + ae42d4d commit 0857b1afb37e682828b0267262158655b4899065 @bitprophet bitprophet committed Dec 28, 2012
Showing with 29 additions and 2 deletions.
  1. +3 −0 docs/changelog.rst
  2. +6 −2 fabric/main.py
  3. +7 −0 tests/support/classbased_task_fabfile.py
  4. +13 −0 tests/test_main.py
View
@@ -25,6 +25,9 @@ would have also been included in the 1.2 line.
Changelog
=========
+* :bug:`766` Use the variable name of a new-style ``fabric.tasks.Task``
+ subclass object when the object name attribute is undefined. Thanks to
+ `@todddeluca` for the patch.
* :bug:`604` Fixed wrong treatment of backslashes in put operation when uploading
directory tree on Windows. Thanks to Jason Coombs for the catch and
`@diresys` & Oliver Janik for the patch.
View
@@ -210,8 +210,12 @@ def extract_tasks(imported_vars):
name, obj = tup
if is_task_object(obj):
state.env.new_style_tasks = True
- # Honor instance.name
- new_style_tasks[obj.name] = obj
+ # Use instance.name if defined
+ if obj.name and obj.name != 'undefined':
+ new_style_tasks[obj.name] = obj
+ else:
+ obj.name = name
+ new_style_tasks[name] = obj
# Handle aliasing
if obj.aliases is not None:
for alias in obj.aliases:
@@ -0,0 +1,7 @@
+from fabric import tasks
+
+class ClassBasedTask(tasks.Task):
+ def run(self, *args, **kwargs):
+ pass
+
+foo = ClassBasedTask()
View
@@ -444,6 +444,19 @@ def test_class_based_tasks_are_found_with_proper_name(self):
eq_(len(funcs), 1)
ok_('foo' in funcs)
+ def test_class_based_tasks_are_found_with_variable_name(self):
+ """
+ A new-style tasks with undefined name attribute should use the instance
+ variable name.
+ """
+ module = fabfile('classbased_task_fabfile.py')
+ from fabric.state import env
+ with path_prefix(module):
+ docs, funcs = load_fabfile(module)
+ eq_(len(funcs), 1)
+ ok_('foo' in funcs)
+ eq_(funcs['foo'].name, 'foo')
+
def test_recursion_steps_into_nontask_modules(self):
"""
Recursive loading will continue through modules with no tasks

0 comments on commit 0857b1a

Please sign in to comment.