Dependency resolver "arg" is a dependency dictionary in which the values are the dependencies of their respective keys.
(arg)
| 1 | def dep(arg): |
| 2 | ''' |
| 3 | Dependency resolver |
| 4 | |
| 5 | "arg" is a dependency dictionary in which |
| 6 | the values are the dependencies of their respective keys. |
| 7 | ''' |
| 8 | d=dict((k, set(arg[k])) for k in arg) |
| 9 | r=[] |
| 10 | while d: |
| 11 | # values not in keys (items without dep) |
| 12 | t=set(i for v in d.values() for i in v)-set(d.keys()) |
| 13 | # and keys without value (items without dep) |
| 14 | t.update(k for k, v in d.items() if not v) |
| 15 | # can be done right away |
| 16 | r.append(t) |
| 17 | # and cleaned up |
| 18 | d=dict(((k, v-t) for k, v in d.items() if v)) |
| 19 | return r |
| 20 | |
| 21 | if __name__=='__main__': |
| 22 | d=dict( |