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 = 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 ? importError(name) return pymodule
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 = 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 ? importError(name) return pymodule
def _check(files, cfg=None, suppressions=None, printProcessing=False): # snapshot modules before and after processing, so that we only warn # about the modules loaded because of these files. # preferable to clearing the loaded modules because we don't have to # reprocess previously handled modules beforePCModules = getAllPCModules() beforeModules = dict(sys.modules.items()) utils.initConfig(cfg) utils.debug('main: Checking %d files', len(files)) utils.debug('main: Finding import warnings') importWarnings = processFiles( files, cfg, printProcessing and _print_processing or None) utils.debug('main: Found %d import warnings' % len(importWarnings)) utils.debug('main: %d modules in sys.modules' % len(sys.modules.keys())) fixupBuiltinModules() afterPCModules = getAllPCModules() newPCModules = afterPCModules[:] for m in beforePCModules: if m in newPCModules: newPCModules.remove(m) newModules = dict(sys.modules.items()) for k, v in beforeModules.items(): if k in newModules: del newModules[k] if cfg.printParse: for module in newPCModules: printer.module(module) utils.debug('main: %d Pychecker modules and %d python modules loaded', len(newPCModules), len(newModules)) # remove all sys.modules suspected of being sibling imports; they now # pollute the global namespace of sys.modules for k, v in newModules.items(): if v and _mightBeSiblingModule(v): utils.debug('main: unloading python module %s', v) del sys.modules[k] utils.debug('main: Finding warnings') # suppressions is a tuple of suppressions, suppressionRegexs dicts warnings = warn.find(newPCModules, cfg, suppressions) utils.debug('main: Found %d warnings in %d files and %d modules', len(importWarnings) + len(warnings), len(files), len(newPCModules)) # FIXME: any way to assert we are popping the one we pushed ? utils.popConfig() return importWarnings + warnings
def _check(files, cfg=None, suppressions=None, printProcessing=False): # snapshot modules before and after processing, so that we only warn # about the modules loaded because of these files. # preferable to clearing the loaded modules because we don't have to # reprocess previously handled modules beforePCModules = getAllPCModules() beforeModules = dict(sys.modules.items()) utils.initConfig(cfg) utils.debug('main: Checking %d files', len(files)) utils.debug('main: Finding import warnings') importWarnings = processFiles(files, cfg, printProcessing and _print_processing or None) utils.debug('main: Found %d import warnings' % len(importWarnings)) utils.debug('main: %d modules in sys.modules' % len(sys.modules.keys())) fixupBuiltinModules() afterPCModules = getAllPCModules() newPCModules = afterPCModules[:] for m in beforePCModules: if m in newPCModules: newPCModules.remove(m) newModules = dict(sys.modules.items()) for k, v in beforeModules.items(): if k in newModules: del newModules[k] if cfg.printParse : for module in newPCModules: printer.module(module) utils.debug('main: %d Pychecker modules and %d python modules loaded', len(newPCModules), len(newModules)) # remove all sys.modules suspected of being sibling imports; they now # pollute the global namespace of sys.modules for k, v in newModules.items(): if v and _mightBeSiblingModule(v): utils.debug('main: unloading python module %s', v) del sys.modules[k] utils.debug('main: Finding warnings') # suppressions is a tuple of suppressions, suppressionRegexs dicts warnings = warn.find(newPCModules, cfg, suppressions) utils.debug('main: Found %d warnings in %d files and %d modules', len(importWarnings) + len(warnings), len(files), len(newPCModules)) # FIXME: any way to assert we are popping the one we pushed ? utils.popConfig() return importWarnings + warnings
def checkSyntax(filename, messageView): """ Massively hacked version of main for ActiveGrid IDE integration """ global _cfg _cfg, files, suppressions = Config.setupFromArgs([filename]) if not files: return 0 global _output, _statusDlg, _count _output = messageView # wxBug: Need to show progress dialog box, or message window never gets updated until the method returns _statusDlg = wx.ProgressDialog(_("Check Code"), _("Checking %s") % filename, maximum=100, style=wx.PD_AUTO_HIDE | wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME) _count = 0 # insert this here, so we find files in the local dir before std library if sys.path[0] != '': sys.path.insert(0, '') importWarnings = processFiles(files, _cfg, _print_processing) fixupBuiltinModules() if _cfg.printParse: for module in getAllModules(): printer.module(module) warnings = warn.find(getAllModules(), _cfg, suppressions) _statusDlg.Update(100, _("Done")) _statusDlg.Destroy() if not _cfg.quiet: _output.AddLines(_("\nWarnings and Errors...\n")) if warnings or importWarnings: _printWarnings(importWarnings + warnings) return 1 if not _cfg.quiet: _output.AddLines(_("No Syntax Errors")) return 0
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
def checkSyntax(filename, messageView): """ Massively hacked version of main for ActiveGrid IDE integration """ global _cfg _cfg, files, suppressions = Config.setupFromArgs([filename]) if not files : return 0 global _output, _statusDlg, _count _output = messageView # wxBug: Need to show progress dialog box, or message window never gets updated until the method returns _statusDlg = wx.ProgressDialog(_("Check Code"), _("Checking %s") % filename, maximum = 100, style = wx.PD_AUTO_HIDE | wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME) _count = 0 # insert this here, so we find files in the local dir before std library if sys.path[0] != '' : sys.path.insert(0, '') importWarnings = processFiles(files, _cfg, _print_processing) fixupBuiltinModules() if _cfg.printParse : for module in getAllModules() : printer.module(module) warnings = warn.find(getAllModules(), _cfg, suppressions) _statusDlg.Update(100, _("Done")) _statusDlg.Destroy() if not _cfg.quiet : _output.AddLines(_("\nWarnings and Errors...\n")) if warnings or importWarnings : _printWarnings(importWarnings + warnings) return 1 if not _cfg.quiet : _output.AddLines(_("No Syntax Errors")) return 0
def getWarnings(files, cfg=None, suppressions=None): warnings = processFiles(files, cfg) fixupBuiltinModules() return warnings + warn.find(getAllModules(), _cfg, suppressions)
return 0 # Now that we've got the args, update the list of evil C objects for evil_doer in _cfg.evil: _EVIL_C_OBJECTS[evil_doer] = None # insert this here, so we find files in the local dir before std library sys.path.insert(0, '') importWarnings = processFiles(files, _cfg, _print_processing) fixupBuiltinModules() if _cfg.printParse: for module in getAllModules(): printer.module(module) warnings = warn.find(getAllModules(), _cfg, suppressions) if not _cfg.quiet: print "\nWarnings...\n" if warnings or importWarnings: _printWarnings(importWarnings + warnings) return 1 if not _cfg.quiet: print "None" return 0 if __name__ == '__main__': try: sys.exit(main(sys.argv)) except Config.UsageError:
def getWarnings(files, cfg = None, suppressions = None): warnings = processFiles(files, cfg) fixupBuiltinModules() return warnings + warn.find(getAllModules(), _cfg, suppressions)
return 0 # Now that we've got the args, update the list of evil C objects for evil_doer in _cfg.evil: _EVIL_C_OBJECTS[evil_doer] = None # insert this here, so we find files in the local dir before std library sys.path.insert(0, '') importWarnings = processFiles(files, _cfg, _print_processing) fixupBuiltinModules() if _cfg.printParse : for module in getAllModules() : printer.module(module) warnings = warn.find(getAllModules(), _cfg, suppressions) if not _cfg.quiet : print "\nWarnings...\n" if warnings or importWarnings : _printWarnings(importWarnings + warnings) return 1 if not _cfg.quiet : print "None" return 0 if __name__ == '__main__' : try : sys.exit(main(sys.argv)) except Config.UsageError :