1.1 --- a/importer.py Mon Mar 13 01:56:13 2017 +0100
1.2 +++ b/importer.py Mon Mar 13 16:57:32 2017 +0100
1.3 @@ -23,7 +23,7 @@
1.4 from errors import ProgramError
1.5 from os.path import exists, extsep, getmtime, join
1.6 from os import listdir, makedirs, remove
1.7 -from common import init_item, readfile, writefile
1.8 +from common import init_item, order_dependencies, readfile, writefile
1.9 from modules import CachedModule
1.10 from referencing import Reference
1.11 import inspector
1.12 @@ -677,44 +677,10 @@
1.13
1.14 self.condense_dependencies()
1.15
1.16 - # Record the number of modules using or depending on each module.
1.17 -
1.18 - usage = {}
1.19 -
1.20 - # Record path-based dependencies.
1.21 -
1.22 - for path in self.depends.keys():
1.23 - usage[path] = set()
1.24 -
1.25 - for path, depends in self.depends.items():
1.26 - for origin in depends:
1.27 - init_item(usage, origin, set)
1.28 - usage[origin].add(path)
1.29 -
1.30 - # Produce an ordering by obtaining exposed modules (required by modules
1.31 - # already processed) and putting them at the start of the list.
1.32 -
1.33 - ordered = []
1.34 -
1.35 - while usage:
1.36 - have_next = False
1.37 -
1.38 - for path, n in usage.items():
1.39 - if not n:
1.40 - ordered.insert(0, path)
1.41 - depends = self.depends.get(path)
1.42 -
1.43 - # Reduce usage of the referenced objects.
1.44 -
1.45 - if depends:
1.46 - for origin in depends:
1.47 - usage[origin].remove(path)
1.48 -
1.49 - del usage[path]
1.50 - have_next = True
1.51 -
1.52 - if not have_next:
1.53 - raise ProgramError("Modules with unresolvable dependencies exist: %s" % ", ".join(usage.keys()))
1.54 + try:
1.55 + ordered = order_dependencies(self.depends)
1.56 + except ValueError, exc:
1.57 + raise ProgramError("Modules with unresolvable dependencies exist: %s" % ", ".join(exc.args[0].keys()))
1.58
1.59 if "__main__" in ordered:
1.60 ordered.remove("__main__")