Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fabric integration beginnings (refs #14)

  • Loading branch information...
commit a20e29aa5859ab89c0aa8791932999cc74f07bb2 1 parent 95b0bda
@Almad Almad authored
Showing with 129 additions and 0 deletions.
  1. +61 −0 paver/discovery.py
  2. +68 −0 tests_integration/test_discovery/test_fabric.py
View
61 paver/discovery.py
@@ -1,3 +1,4 @@
+from paver.path import path
from paver import tasks
class DjangoTaskFinder(object):
@@ -31,3 +32,63 @@ def discover_django(options):
if not hasattr(env, "_django_tasks_installed"):
env.task_finders.append(DjangoTaskFinder(options))
env._django_tasks_installed = True
+
+
+class FabricTaskFinder(object):
+ def __init__(self, options):
+ super(FabricTaskFinder, self).__init__()
+
+ self.options = options
+
+ def _load_fabfile(self):
+ from fabric import state
+ from fabric.main import load_fabfile
+
+ result = load_fabfile(self.options.fabfile)
+ state.commands.update(result[1])
+ return result
+
+ def get_task(self, taskname):
+ if taskname.startswith('fab.'):
+ taskname = taskname[len('fab.'):]
+
+ taskinfo = self._load_fabfile()
+
+ try:
+ from fabric.tasks import execute
+ return tasks.Task(lambda: execute(taskname))
+ except ImportError:
+ task = taskinfo[1][taskname]
+
+ # First, try class-based tasks
+ if hasattr(task, 'run') and callable(task.run):
+ return tasks.Task(lambda: task.run())
+ # Fallback to callable behavior
+ return tasks.Task(lambda: task())
+
+ def get_tasks(self):
+ self._load_fabfile()
+
+ from fabric import state
+ return set(tasks.Task(t) for t in state.commands.values())
+
+def discover_fabric(options):
+ """ Look for manage.py and import it's task into main pavement """
+ fabfile = getattr(options, "fabfile", None)
+ if not fabfile:
+ from fabric.main import find_fabfile
+ fabfile = find_fabfile()
+
+ if fabfile:
+ fabfile = path(fabfile)
+
+ if not fabfile or not fabfile.exists():
+ raise tasks.BuildFailure("fabric.py cannot be found")
+
+ #FIXME: use options.discovery.fabric.fabfile
+ options.fabfile = path(fabfile.abspath())
+
+ env = tasks.environment
+ if not hasattr(env, "_fabric_tasks_installed"):
+ env.task_finders.append(FabricTaskFinder(options))
+ env._fabric_tasks_installed = True
View
68 tests_integration/test_discovery/test_fabric.py
@@ -0,0 +1,68 @@
+from __future__ import with_statement
+
+import os
+from shutil import rmtree
+from subprocess import Popen, PIPE
+from tempfile import mkdtemp
+
+from nose.plugins.skip import SkipTest
+from nose.tools import assert_equals, assert_true
+
+class TestBasicFabricDiscovery(object):
+
+ def setUp(self):
+ try:
+ import fabric
+ except ImportError:
+ raise SkipTest("Django must be installed for django discovery tests")
+
+ self.testbed = mkdtemp(prefix="paver-test-fabric-")
+
+ FABFILE = """
+from fabric.api import local
+
+def show_xxx():
+ local('echo xxx')
+"""
+
+ with open(os.path.join(self.testbed, "fabfile.py"), 'w') as f:
+ f.write(FABFILE)
+
+ pavement = """
+from paver.easy import *
+from paver.setuputils import setup
+
+from paver.discovery import discover_fabric
+
+setup(
+ name="MyCoolProject",
+ packages=['mycool'],
+ version="1.0",
+ url="http://www.blueskyonmars.com/",
+ author="Kevin Dangoor",
+ author_email="dangoor@gmail.com"
+)
+
+discover_fabric(options)
+ """
+
+ with open(os.path.join(self.testbed, "pavement.py"), 'w') as f:
+ f.write(pavement)
+
+
+ def test_namespaced_django_commands_available(self):
+ p = Popen(["fab", "show_xxx"], cwd=self.testbed, stdout=PIPE, stderr=PIPE)
+ expected_output, _ = p.communicate()
+
+ assert_equals(0, p.returncode, "Unexpected failure when communicating with fabric -- is it installed properly?")
+
+ p = Popen(["paver", "fab.show_xxx"], cwd=self.testbed, stdout=PIPE, stderr=PIPE)
+ output, stderr = p.communicate()
+
+ assert_equals(0, p.returncode, "Command failed: stdout: %s, stderr: %s" % (output, stderr))
+
+ assert_equals("xxx", output.splitlines()[0])
+
+
+ def tearDown(self):
+ rmtree(self.testbed)
Please sign in to comment.
Something went wrong with that request. Please try again.