# HG changeset patch # User Jeff Hammel # Date 1370700735 25200 # Node ID c7585bd93680b9d3457261bf097dc46ee9811302 # Parent 6715102c5a8662d45b86d23b88d655afcb06bcc1 stub for actions module for python function dep unrolling diff -r 6715102c5a86 -r c7585bd93680 intentmademanifest/actions.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/intentmademanifest/actions.py Sat Jun 08 07:12:15 2013 -0700 @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +""" +``intentmademanifest.actions`` is a dependency resolver for python instance +methods +""" + +# TODO: generalize, if possible. For instance, we don't care about +# parameter space; should we? how? + +class Actions(object): + + @classmethod + def requires(cls, method, *requirements): + """ + Require all dependencies to be run before invoking the method. + - requirements: method names + """ + # TODO: as is, the intent is to run all of the requirements + # and then invoke ``method`` + # alternatively, e.g. via subclass, one could err out if the + # requirements have not been run + +class ActionsCLI(object): + """command line handler for an actions-based class""" + def __init__(self): + raise NotImplementedError("TODO") + +requires = Actions.requires + +if __name__ == '__main__': + # TODO: -> test + + class ActionsExample(object): + """example class for illustration of ``intentmademanifest.actions``""" + + def foo(self): + self.attr = 1 + + @requires('foo') + def bar(self): + self.attr *= 2 + + def fleem(self): + self.another_attr = 3 + + @requires('bar', 'fleem') + def result(self): + return self.attr * self.another_attr + + instance = ActionsExample() + assert instance.result() == 6