4 ms·
Is there a Python library that can check a timestamp and update some files according to a lambda? I don't want to learn Make syntax again.
by ogogmad 4y ago
Is there a Python library that can check a timestamp and update some files according to a lambda? I don't want to learn Make syntax again.
- Jtsummers 4y agoif os.stat(object).st_mtime < os.stat(dependency).st_mtime: ... Use a dict to contain each rule: rules["a.c"] = (["b.c", "c.c", "b.h", "c.h"], action) ... That can be simplified as well and then run a simple parser over it that takes a simpler representation and turns it into that dict. Then: def make(rules, rule): (deps, action) = rules[rule] run_rule = len(deps) == 0 # if there are no dependencies, the rule always runs for dep in deps: make(rules, dep) if os.stat(rule).st_mtime < os.stat(dep).st_mtime: run_rule = True if run_rule: action() Of course, this doesn't actually validate the DAG itself. ---------- An amendment: You'll probably want to pass both the rule name and the dependencies into the action function/lambda/object so that you can parameterize it and maybe reuse the action (like a common compiler command): if run_rule: action(rule, deps)
- andreareina 4y agoTopological sorting is in the stdlib: https://docs.python.org/3/library/graphlib.html https://docs.python.org/3/library/graphlib.html
- TillE 4y agoSCons can be used as a simple Make-style tool, in addition to the more complex stuff it supports.