annotate intentmademanifest/actions.py @ 19:74ada5cb1cb8 default tip

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