def add_dependencies(self, module): """ Adds a module and its dependencies to the list of dependencies. Top-level entry point for adding a module and its dependecies. """ if module in self._processed_modules: return None if hasattr(module, "__name__"): mn = module.__name__ else: mn = '<unknown>' _debug.debug("add_dependencies:module=%s", module) # If the module in which the class/function is defined is __main__, don't add it. Just add its dependencies. if mn == "__main__": self._processed_modules.add(module) # add the module as a dependency elif not self._add_dependency(module, mn): _debug.debug("add_dependencies:not added:module=%s", mn) return None _debug.debug("add_dependencies:ADDED:module=%s", mn) # recursively get the module's imports and add those as dependencies for dm in self._find_dependent_modules(module): _debug.debug("add_dependencies:adding dependent module %s for %s", dm, mn) self.add_dependencies(dm)
def add_dependencies(self, module): """ Adds a module and its dependencies to the list of dependencies. Top-level entry point for adding a module and its dependecies. """ if module in self._processed_modules: return None if hasattr(module, "__name__"): mn = module.__name__ else: mn = '<unknown>' _debug.debug("add_dependencies:module=%s", module) # If the module in which the class/function is defined is __main__, don't add it. Just add its dependencies. if mn == "__main__": self._processed_modules.add(module) # add the module as a dependency elif not self._add_dependency(module, mn): _debug.debug("add_dependencies:not added:module=%s", mn) return None _debug.debug("add_dependencies:ADDED:module=%s", mn) # recursively get the module's imports and add those as dependencies for dm in self._find_dependent_modules(module): _debug.debug("add_dependencies:adding dependent module %s for %s", dm, mn) self.add_dependencies(dm)
def _include_module(self, module, mn): """ See if a module should be included or excluded based upon included_packages and excluded_packages. As some packages have the following format: scipy.special.specfun scipy.linalg Where the top-level package name is just a prefix to a longer package name, we don't want to do a direct comparison. Instead, we want to exclude packages which are either exactly "<package_name>", or start with "<package_name>". """ if mn in self.topology.include_packages: _debug.debug( "_include_module:explicit using __include_packages: module=%s", mn) return True if '.' in mn: for include_package in self.topology.include_packages: if mn.startswith(include_package + '.'): _debug.debug("_include_module:explicit pattern using __include_packages: module=%s pattern=%s", mn, \ include_package + '.') return True if mn in self.topology.exclude_packages: _debug.debug( "_include_module:explicit using __exclude_packages: module=%s", mn) return False if '.' in mn: for exclude_package in self.topology.exclude_packages: if mn.startswith(exclude_package + '.'): _debug.debug("_include_module:explicit pattern using __exclude_packages: module=%s pattern=%s", mn, \ exclude_package + '.') return False _debug.debug("_include_module:including: module=%s", mn) return True
def _include_module(self, module, mn): """ See if a module should be included or excluded based upon included_packages and excluded_packages. As some packages have the following format: scipy.special.specfun scipy.linalg Where the top-level package name is just a prefix to a longer package name, we don't want to do a direct comparison. Instead, we want to exclude packages which are either exactly "<package_name>", or start with "<package_name>". """ if mn in self.topology.include_packages: _debug.debug("_include_module:explicit using __include_packages: module=%s", mn) return True if '.' in mn: for include_package in self.topology.include_packages: if mn.startswith(include_package + '.'): _debug.debug("_include_module:explicit pattern using __include_packages: module=%s pattern=%s", mn, \ include_package + '.') return True if mn in self.topology.exclude_packages: _debug.debug("_include_module:explicit using __exclude_packages: module=%s", mn) return False if '.' in mn: for exclude_package in self.topology.exclude_packages: if mn.startswith(exclude_package + '.'): _debug.debug("_include_module:explicit pattern using __exclude_packages: module=%s pattern=%s", mn, \ exclude_package + '.') return False _debug.debug("_include_module:including: module=%s", mn) return True
def _add_dependency(self, module, mn): """ Adds a module to the list of dependencies wihtout handling the modules dependences. """ _debug.debug("_add_dependency:module=%s", mn) if _is_streamsx_module(module): _debug.debug("_add_dependency:streamsx module=%s", mn) return False if _is_builtin_module(module): _debug.debug("_add_dependency:builtin module=%s", mn) return False if not self._include_module(module, mn): #print ("ignoring dependencies for {0} {1}".format(module.__name__, module)) return False package_name = _get_package_name(module) top_package_name = module.__name__.split('.')[0] if package_name and top_package_name in sys.modules: # module is part of a package # get the top-level package top_package = sys.modules[top_package_name] if "__path__" in top_package.__dict__: # for regular packages, there is one top-level directory # for namespace packages, there can be more than one. # they will be merged in the bundle for top_package_path in reversed(list(top_package.__path__)): top_package_path = os.path.abspath(top_package_path) self._add_package(top_package_path) elif hasattr(top_package, '__file__'): # package that is an individual python file with empty __path__ #print ("Adding package that is an individual file", top_package) self._add_package(os.path.abspath(top_package.__file__)) elif hasattr(module, '__file__'): # individual Python module module_path = os.path.abspath(module.__file__) self._modules.add(module_path) self._processed_modules.add(module) return True
def _add_dependency(self, module, mn): """ Adds a module to the list of dependencies wihtout handling the modules dependences. """ _debug.debug("_add_dependency:module=%s", mn) if _is_streamsx_module(module): _debug.debug("_add_dependency:streamsx module=%s", mn) return False if _is_builtin_module(module): _debug.debug("_add_dependency:builtin module=%s", mn) return False if not self._include_module(module, mn): #print ("ignoring dependencies for {0} {1}".format(module.__name__, module)) return False package_name = _get_package_name(module) top_package_name = module.__name__.split('.')[0] if package_name and top_package_name in sys.modules: # module is part of a package # get the top-level package top_package = sys.modules[top_package_name] if "__path__" in top_package.__dict__: # for regular packages, there is one top-level directory # for namespace packages, there can be more than one. # they will be merged in the bundle for top_package_path in reversed(list(top_package.__path__)): top_package_path = os.path.abspath(top_package_path) self._add_package(top_package_path) elif hasattr(top_package, '__file__'): # package that is an individual python file with empty __path__ #print ("Adding package that is an individual file", top_package) self._add_package(os.path.abspath(top_package.__file__)) elif hasattr(module, '__file__'): # individual Python module module_path = os.path.abspath(module.__file__) self._modules.add(module_path) self._processed_modules.add(module) return True
def _add_package(self, path): if path == self._streamsx_topology_dir: return None _debug.debug("_add_package: path=%s", path) self._packages[path] = None
def _add_package(self, path): if path == self._streamsx_topology_dir: return None _debug.debug("_add_package: path=%s", path) self._packages[path] = None