# HG changeset patch # User Paul Boddie # Date 1481817996 -3600 # Node ID a980ec14c2cea68c549b2032a277c09c20e15aed # Parent 0c59d603a56928d0fd42455ab4dc2ad70beb61f7 Identify deduced inter-module dependencies caused by usage of functions with dynamic defaults. diff -r 0c59d603a569 -r a980ec14c2ce deducer.py --- a/deducer.py Thu Dec 15 16:09:01 2016 +0100 +++ b/deducer.py Thu Dec 15 17:06:36 2016 +0100 @@ -137,6 +137,7 @@ self.classify_accessors() self.classify_accesses() self.initialise_access_plans() + self.identify_dependencies() def to_output(self): @@ -647,6 +648,36 @@ original_location = self.const_accesses_rev.get(location) self.access_plans[original_location or location] = self.get_access_plan(location) + def identify_dependencies(self): + + "Introduce more module dependencies to the importer." + + for location, referenced_attrs in self.referenced_attrs.items(): + path, name, attrnames, version = location + + # Identify module-level paths. + + if self.importer.modules.has_key(path): + module_name = path + + # Identify the module containing other paths. + + else: + ref = self.importer.identify(path) + for objpath in ref.ancestors(): + if self.importer.modules.has_key(objpath): + module_name = objpath + break + else: + raise DeduceError("Cannot find module for path %s." % path) + + # Identify usage of callables employing dynamic defaults. + + for attrtype, objtype, attr in referenced_attrs: + if self.importer.uses_dynamic_callable(attr): + provider = self.importer.get_module_provider(attr) + self.importer.add_provider(path, provider) + def get_referenced_attrs(self, location): """ diff -r 0c59d603a569 -r a980ec14c2ce importer.py --- a/importer.py Thu Dec 15 16:09:01 2016 +0100 +++ b/importer.py Thu Dec 15 17:06:36 2016 +0100 @@ -456,8 +456,7 @@ # Record a module ordering dependency. if not found.static() or self.uses_dynamic_callable(found): - init_item(self.depends, module.name, set) - self.depends[module.name].add(provider) + self.add_provider(module.name, provider) module.deferred = original_deferred @@ -467,6 +466,13 @@ for module_name in self.waiting.keys(): self.require_providers(module_name) + def add_provider(self, module_name, provider): + + "Add a dependency for 'module_name' of 'provider'." + + init_item(self.depends, module_name, set) + self.depends[module_name].add(provider) + def require_providers(self, module_name): """