def __import__(name, globals=None, locals=None, fromlist=None): if globals is None: globals = {} if locals is None: locals = {} if fromlist is None: fromlist = [] check = not sys.modules.has_key(name) and name[:10] != 'pychecker.' pymodule = _orig__import__(name, globals, locals, fromlist) if check: try: # FIXME: can we find a good moduleDir ? module = pcmodules.PyCheckerModule(pymodule.__name__) if module.initModule(pymodule): warnings = warn.find([module], _cfg, _suppressions) _printWarnings(_get_unique_warnings(warnings)) else: print 'Unable to load module', pymodule.__name__ except Exception: name = getattr(pymodule, '__name__', utils.safestr(pymodule)) # FIXME: can we use it here ? utils.importError(name) return pymodule
def __import__(name, globals=None, locals=None, fromlist=None,level=-1): if globals is None: globals = {} if locals is None: locals = {} if fromlist is None: fromlist = [] #print "Before Load:",name check = not sys.modules.has_key(name) and name[:10] != 'pychecker.' pymodule = _orig__import__(name, globals, locals, fromlist,level) if check : try : # FIXME: can we find a good moduleDir ? module = pcmodules.PyCheckerModule(pymodule.__name__) if module.initModule(pymodule): warnings = warn.find([module], _cfg, _suppressions) _printWarnings(_get_unique_warnings(warnings)) else : print 'Unable to load module', pymodule.__name__ except Exception: name = getattr(pymodule, '__name__', utils.safestr(pymodule)) # FIXME: can we use it here ? utils.importError(name) return pymodule
def load(self, allowImportError=False): """ @param allowImportError: if True, do not catch ImportError but reraise them, so caller can know this module does not exist. """ try: # there's no need to reload modules we already have if no moduleDir # is specified for this module # NOTE: self.moduleDir can be '' if the module tested lives in # the current working directory if self.moduleDir is None: module = sys.modules.get(self.moduleName) if module: pcmodule = getPCModule(self.moduleName) if not pcmodule.module: return self._initModule(module) return 1 return self._initModule(self.setupMainCode()) except (SystemExit, KeyboardInterrupt): exc_type, exc_value, exc_tb = sys.exc_info() raise exc_type, exc_value except Exception, e: if allowImportError: raise utils.importError(self.moduleName, self.moduleDir) return utils.cfg().ignoreImportErrors
def load(self, allowImportError=False): """ @param allowImportError: if True, do not catch ImportError but reraise them, so caller can know this module does not exist. """ try : # there's no need to reload modules we already have if no moduleDir # is specified for this module # NOTE: self.moduleDir can be '' if the module tested lives in # the current working directory if self.moduleDir is None: module = sys.modules.get(self.moduleName) if module: pcmodule = getPCModule(self.moduleName) if not pcmodule.module: return self._initModule(module) return 1 return self._initModule(self.setupMainCode()) except (SystemExit, KeyboardInterrupt): exc_type, exc_value, exc_tb = sys.exc_info() raise exc_type, exc_value except Exception, e: if allowImportError: raise utils.importError(self.moduleName, self.moduleDir) return utils.cfg().ignoreImportErrors
def load(self): try : # there's no need to reload modules we already have if no moduleDir # is specified for this module # NOTE: self.moduleDir can be '' if the module tested lives in # the current working directory if self.moduleDir is None: module = sys.modules.get(self.moduleName) if module: pcmodule = getPCModule(self.moduleName) if not pcmodule.module: return self._initModule(module) return 1 return self._initModule(self.setupMainCode()) except (SystemExit, KeyboardInterrupt): exc_type, exc_value, exc_tb = sys.exc_info() raise exc_type, exc_value except: utils.importError(self.moduleName, self.moduleDir) return utils.cfg().ignoreImportErrors
def load(self): try: # there's no need to reload modules we already have if no moduleDir # is specified for this module # NOTE: self.moduleDir can be '' if the module tested lives in # the current working directory if self.moduleDir is None: module = sys.modules.get(self.moduleName) if module: pcmodule = getPCModule(self.moduleName) if not pcmodule.module: return self._initModule(module) return 1 return self._initModule(self.setupMainCode()) except (SystemExit, KeyboardInterrupt): exc_type, exc_value, exc_tb = sys.exc_info() raise exc_type, exc_value except: utils.importError(self.moduleName, self.moduleDir) return utils.cfg().ignoreImportErrors
def __import__(name, globals=None, locals=None, fromlist=None, level=None): if globals is None: globals = {} if locals is None: locals = {} if fromlist is None: fromlist = [] check = not sys.modules.has_key(name) and name[:10] != 'pychecker.' if level: pymodule = _orig__import__(name, globals, locals, fromlist, level) else: pymodule = _orig__import__(name, globals, locals, fromlist) if check: try: # FIXME: can we find a good moduleDir ? # based on possible module.__file__, check if it's from # sys.path, and if not, extract moduleDir moduleDir = os.path.dirname(pymodule.__file__) for path in sys.path: if os.path.abspath(moduleDir) == os.path.abspath(path): moduleDir = None break # FIXME: could it possibly be from a higher-level package, # instead of the current dir ? Loop up with __init__.py ? module = pcmodules.PyCheckerModule(pymodule.__name__, moduleDir=moduleDir) if module.initModule(pymodule): warnings = warn.find([module], _cfg, _suppressions) _printWarnings(_get_unique_warnings(warnings)) else: print 'Unable to load module', pymodule.__name__ except Exception: name = getattr(pymodule, '__name__', utils.safestr(pymodule)) # FIXME: can we use it here ? utils.importError(name) return pymodule
def __import__(name, globals=None, locals=None, fromlist=None, level=None): if globals is None: globals = {} if locals is None: locals = {} if fromlist is None: fromlist = [] check = not sys.modules.has_key(name) and name[:10] != 'pychecker.' if level: pymodule = _orig__import__(name, globals, locals, fromlist, level) else: pymodule = _orig__import__(name, globals, locals, fromlist) if check : try : # FIXME: can we find a good moduleDir ? # based on possible module.__file__, check if it's from # sys.path, and if not, extract moduleDir moduleDir = os.path.dirname(pymodule.__file__) for path in sys.path: if os.path.abspath(moduleDir) == os.path.abspath(path): moduleDir = None break # FIXME: could it possibly be from a higher-level package, # instead of the current dir ? Loop up with __init__.py ? module = pcmodules.PyCheckerModule(pymodule.__name__, moduleDir=moduleDir) if module.initModule(pymodule): warnings = warn.find([module], _cfg, _suppressions) _printWarnings(_get_unique_warnings(warnings)) else : print 'Unable to load module', pymodule.__name__ except Exception: name = getattr(pymodule, '__name__', utils.safestr(pymodule)) # FIXME: can we use it here ? utils.importError(name) return pymodule