Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

  if 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)


Topological sorting is in the stdlib: https://docs.python.org/3/library/graphlib.html




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: