From 5328a9d0f802e6f5b2d331b0bb177ccb73c10754 Mon Sep 17 00:00:00 2001 From: Mikhail Korobov Date: Thu, 9 Aug 2012 23:12:12 +0600 Subject: [PATCH] restore (but deprecate) @taskset.task decorator; updated readme, changelog and authors; minor docstring tweaks --- AUTHORS.rst | 5 +++++ CHANGES.rst | 19 +++++++++++++++++++ MANIFEST.in | 3 ++- README.rst | 38 ++++++++++++++++++++++++++++++-------- setup.py | 2 +- taskset/__init__.py | 15 ++++++++++----- 6 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 AUTHORS.rst create mode 100644 CHANGES.rst diff --git a/AUTHORS.rst b/AUTHORS.rst new file mode 100644 index 0000000..25efab2 --- /dev/null +++ b/AUTHORS.rst @@ -0,0 +1,5 @@ +Authors +======= + +* Mikhail Korobov ; +* Denis Untevskiy. diff --git a/CHANGES.rst b/CHANGES.rst new file mode 100644 index 0000000..90a01e7 --- /dev/null +++ b/CHANGES.rst @@ -0,0 +1,19 @@ + +Changes +======= + +0.2 (TBA) +--------- + +- ``@task`` decorator is deprecated and replaced with ``@task_method``. + This was a bad name because of ``@fabric.task`` decorator + (thanks Denis Untevskiy); +- ``Taskset.expose_as_module`` method that allows to use TaskSet instances + from command line without creating dummy modules on disk + (thanks Denis Untevskiy). + + +0.1 (2012-03-03) +---------------- + +Initial release. diff --git a/MANIFEST.in b/MANIFEST.in index 11bcff7..a8d6b8e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ include LICENSE include README.rst -include AUTHORS +include AUTHORS.rst +include CHANGES.rst diff --git a/README.rst b/README.rst index 0e94214..4bb945f 100644 --- a/README.rst +++ b/README.rst @@ -21,14 +21,15 @@ Usage Example:: - # my_lib/say.py - from taskset import TaskSet, task + + # fabfile.py + from taskset import TaskSet, task_method class SayBase(TaskSet): def say(self, what): raise NotImplemented() - @task(default=True, alias='hi') + @task_method(default=True, alias='hi') def hello(self): self.say('hello') @@ -36,11 +37,8 @@ Example:: def say(self, what): local('echo ' + what) - instance = EchoSay() - instance.expose_to_current_module() + say = EchoSay().expose_as_module('say') - # fabfile.py - from mylib import say and then e.g.:: @@ -48,10 +46,34 @@ and then e.g.:: hello -``taskset.task`` is a decorator declaring the wrapped method to be task. +``taskset.task_method`` is a decorator declaring the wrapped method to be task. It acceps the same arguments as ``fabric.decorators.task`` so use it on methods just like fabric's decorator is used on functions. +You can also create an "on-disk" Python module and populate it with tasks:: + + # my_lib/say.py + from taskset import TaskSet, task_method + + class SayBase(TaskSet): + def say(self, what): + raise NotImplemented() + + @task_method(default=True, alias='hi') + def hello(self): + self.say('hello') + + class EchoSay(SayBase): + def say(self, what): + local('echo ' + what) + + instance = EchoSay() + instance.expose_to_current_module() + + # fabfile.py + from mylib import say + + Acknowledgements ---------------- diff --git a/setup.py b/setup.py index 52aa591..107ddb0 100755 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ license = 'MIT license', description = """ Expose class members as Fabric tasks """, - long_description = open('README.rst').read(), + long_description = open('README.rst').read() + open('CHANGES.rst').read(), requires = ['Fabric (>= 1.1)'], classifiers=( diff --git a/taskset/__init__.py b/taskset/__init__.py index d066d1a..15f4e26 100644 --- a/taskset/__init__.py +++ b/taskset/__init__.py @@ -3,6 +3,7 @@ import inspect import sys import types +import warnings from fabric.tasks import WrappedCallableTask def task_method(*args, **kwargs): @@ -29,6 +30,10 @@ def decorator(func): return decorator if invoked else decorator(func) +def task(*args, **kwargs): + msg = "@taskset.task decorator is deprecated and will be removed soon; please use @taskset.task_method instead." + warnings.warn(msg, DeprecationWarning) + return task_method(*args, **kwargs) class TaskSet(object): @@ -88,11 +93,11 @@ def expose_to_current_module(self): frm = inspect.stack()[1] mod = inspect.getmodule(frm[0]) return self.expose_to(mod.__name__) - + def expose_as_module(self, module_name, module_type=types.ModuleType): - """ - Creates new module of type ``module_type`` and named ``module_name`` - populates it with tasks and returns it. + """ + Creates a new module of type ``module_type`` and named ``module_name``, + populates it with tasks and returns this newly created module. """ module = module_type(module_name) for name, task in self._get_fabric_tasks(): @@ -104,7 +109,7 @@ def _expose_to(self, module_name): for name, task in self._get_fabric_tasks(): setattr(module_obj, name, task) yield name - + def _is_task(self, func): return hasattr(func, '_task_info')