comparison intentmademanifest/actions.py @ 15:c7585bd93680

stub for actions module for python function dep unrolling
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 08 Jun 2013 07:12:15 -0700
parents
children
comparison
equal deleted inserted replaced
14:6715102c5a86 15:c7585bd93680
1 #!/usr/bin/env python
2
3 """
4 ``intentmademanifest.actions`` is a dependency resolver for python instance
5 methods
6 """
7
8 # TODO: generalize, if possible. For instance, we don't care about
9 # parameter space; should we? how?
10
11 class Actions(object):
12
13 @classmethod
14 def requires(cls, method, *requirements):
15 """
16 Require all dependencies to be run before invoking the method.
17 - requirements: method names
18 """
19 # TODO: as is, the intent is to run all of the requirements
20 # and then invoke ``method``
21 # alternatively, e.g. via subclass, one could err out if the
22 # requirements have not been run
23
24 class ActionsCLI(object):
25 """command line handler for an actions-based class"""
26 def __init__(self):
27 raise NotImplementedError("TODO")
28
29 requires = Actions.requires
30
31 if __name__ == '__main__':
32 # TODO: -> test
33
34 class ActionsExample(object):
35 """example class for illustration of ``intentmademanifest.actions``"""
36
37 def foo(self):
38 self.attr = 1
39
40 @requires('foo')
41 def bar(self):
42 self.attr *= 2
43
44 def fleem(self):
45 self.another_attr = 3
46
47 @requires('bar', 'fleem')
48 def result(self):
49 return self.attr * self.another_attr
50
51 instance = ActionsExample()
52 assert instance.result() == 6