def __onImportList(self, fileName, imports): """Works with a list of imports""" # It has already been checked that the file is a Python one resolvedList, errors = resolveImports(fileName, imports) del errors # errors are OK here if resolvedList: # Display the import selection widget self.importsBar.showResolvedImports(resolvedList) else: GlobalData().mainWindow.showStatusBarMessage( "Could not resolve any imports")
def __onImportList( self, basePath, imports ): " Works with a list of imports " # It has already been checked that the file is a Python one resolvedList = resolveImports( basePath, imports ) if not resolvedList: GlobalData().mainWindow.showStatusBarMessage( "No imports are resolved.", 0 ) return # Display the import selection widget self.__importsBar.showResolvedList( resolvedList ) return
def __onImportList(self, basePath, imports): " Works with a list of imports " # It has already been checked that the file is a Python one resolvedList = resolveImports(basePath, imports) if not resolvedList: GlobalData().mainWindow.showStatusBarMessage( "No imports are resolved.", 0) return # Display the import selection widget self.__importsBar.showResolvedList(resolvedList) return
def __addSingleFileToDataModel(self, info, fName): """Adds a single file to the data model""" if fName.endswith('__init__.py'): if not info.classes and not info.functions and \ not info.globals and not info.imports: # Skip dummy init files return modBox = DgmModule() modBox.refFile = fName modBox.kind = DgmModule.ModuleOfInterest modBox.title = self.__getModuleTitle(fName) self.__addBoxInfo(modBox, info) modBoxName = self.dataModel.addModule(modBox) self.__addDocstringBox(info, fName, modBoxName) # Analyze what was imported resolvedImports, errors = resolveImports(fName, info.imports) if errors: message = 'Errors while analyzing ' + fName + ':' for err in errors: message += '\n ' + err logging.warning(message) for item in resolvedImports: importName = item[0] # from name resolvedPath = item[1] # 'built-in', None or absolute path importedNames = item[2] # list of strings impBox = DgmModule() impBox.title = importName if self.__isLocalOrProject(fName, resolvedPath): impBox.kind = DgmModule.OtherProjectModule impBox.refFile = resolvedPath if isPythonFile(resolvedPath): otherInfo = GlobalData().briefModinfoCache.get( resolvedPath) self.__addBoxInfo(impBox, otherInfo) else: if resolvedPath is None: # e.g. 'import sys' will have None for the path impBox.kind = DgmModule.UnknownModule elif os.path.isabs(resolvedPath): impBox.kind = DgmModule.SystemWideModule impBox.refFile = resolvedPath impBox.docstring = \ self.__getSytemWideImportDocstring(resolvedPath) else: # e.g. 'import time' will have 'built-in' in the path impBox.kind = DgmModule.BuiltInModule impBoxName = self.dataModel.addModule(impBox) impConn = DgmConnection() impConn.kind = DgmConnection.ModuleDependency impConn.source = modBoxName impConn.target = impBoxName if self.__options.includeConnText: for impWhat in importedNames: if impWhat: impConn.labels.append(impWhat) self.dataModel.addConnection(impConn)