Пример #1
0
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
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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
Пример #5
0
    _cfg, files, suppressions = Config.setupFromArgs(argv[1:])
    if not files:
        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:
Пример #6
0
    _cfg, files, suppressions = Config.setupFromArgs(argv[1:])
    if not files :
        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 :