def OnConfigPyChecker(self, event):
        model = self.getModel()
        if model:
            home = os.environ.get('HOME')
            if home:
                appDir = home
                appConfig = home+'/.pycheckrc'
            else:
                filename = model.assertLocalFile()
                appDir = os.path.dirname(filename)
                appConfig = appDir+'/.pycheckrc'
            if not os.path.exists(appConfig):
                dlg = wx.MessageDialog(self.editor, _('The PyChecker configuration file '
                  'can not be found. Copy the default file here?'),
                  _('Config file not found'), wx.YES_NO | wx.ICON_QUESTION)
                try:
                    if dlg.ShowModal() == wx.ID_YES:
                        from pychecker import Config
                        open(appConfig, 'w').write(Config.outputRc(Config.Config()))
                    else:
                        return
                finally:
                    dlg.Destroy()

            from Explorers.PrefsExplorer import SourceBasedPrefColNode
            SourceBasedPrefColNode('PyChecker', ('*',), appConfig, -1, None).open(self.editor)
예제 #2
0
def processFiles(files, cfg=None, pre_process_cb=None):
    # insert this here, so we find files in the local dir before std library
    if sys.path[0] != '':
        sys.path.insert(0, '')

    # ensure we have a config object, it's necessary
    global _cfg
    if cfg is not None:
        _cfg = cfg
    elif _cfg is None:
        _cfg = Config.Config()

    if _cfg.ignoreImportErrors:
        install_ignore__import__()

    warnings = []
    utils.initConfig(_cfg)
    for file, (moduleName, moduleDir) in zip(files, getModules(files)):
        if callable(pre_process_cb):
            pre_process_cb("module %s (%s)" % (moduleName, file))
        oldsyspath = sys.path[:]
        sys.path.insert(0, moduleDir)
        module = PyCheckerModule(moduleName, moduleDir=moduleDir)
        if not module.load():
            w = Warning(module.filename(), 1,
                        msgs.Internal("NOT PROCESSED UNABLE TO IMPORT"))
            warnings.append(w)
        sys.path = oldsyspath
    utils.popConfig()
    return warnings
예제 #3
0
def processFiles(files, cfg=None, pre_process_cb=None):
    # insert this here, so we find files in the local dir before std library
    if sys.path[0] != '':
        sys.path.insert(0, '')

    # ensure we have a config object, it's necessary
    global _cfg
    if cfg is not None:
        _cfg = cfg
    elif _cfg is None:
        _cfg = Config.Config()

    warnings = []
    utils.initConfig(_cfg)
    for moduleName, filename in getModules(files):
        if callable(pre_process_cb):
            pre_process_cb(moduleName)
        module = Module(moduleName, fullpath=filename)

        # reload the given module, otherwise won't get new syntax errors.
        sysModule = sys.modules.get(moduleName)
        if sysModule:
            try:
                reload(sysModule)
            except:
                pass

        module.load(warnings)
    utils.popConfig()
    return warnings
예제 #4
0
    def check(self, paths):
        config = Config.Config()
        config.ignoreStandardLibrary = 1
        if os.environ.get('PYCHECKER_DEBUG'):
            config.debug = 1

        from pychecker.check import _check
        warnings = _check(paths, cfg=config)

        return warnings
예제 #5
0
    def _init():
        global _cfg, _suppressions, _orig__import__

        args = string.split(os.environ.get('PYCHECKER', ''))
        _cfg, files, _suppressions = Config.setupFromArgs(args)
        utils.initConfig(_cfg)
        fixupBuiltinModules(1)

        # keep the orig __import__ around so we can call it
        import __builtin__
        _orig__import__ = __builtin__.__import__
        __builtin__.__import__ = __import__
예제 #6
0
    def _init() :
        global _cfg, _suppressions, _orig__import__

        args = string.split(os.environ.get('PYCHECKER', ''))
        _cfg, files, _suppressions = Config.setupFromArgs(args)
        utils.initConfig(_cfg)
        fixupBuiltinModules(1)

        # keep the orig __import__ around so we can call it
        import __builtin__
        _orig__import__ = __builtin__.__import__
        __builtin__.__import__ = __import__
예제 #7
0
def processFiles(files, cfg=None, pre_process_cb=None):
    """
    @type  files:          list of str
    @type  cfg:            L{Config.Config}
    @param pre_process_cb: callable notifying of module name, filename
    @type  pre_process_cb: callable taking (str, str)
    """

    warnings = []

    # insert this here, so we find files in the local dir before std library
    if sys.path[0] != '':
        sys.path.insert(0, '')

    # ensure we have a config object, it's necessary
    global _cfg
    if cfg is not None:
        _cfg = cfg
    elif _cfg is None:
        _cfg = Config.Config()

    if _cfg.ignoreImportErrors:
        install_ignore__import__()

    utils.initConfig(_cfg)

    utils.debug('Processing %d files' % len(files))

    for file, (moduleName, moduleDir) in zip(files, getModules(files)):
        if callable(pre_process_cb):
            pre_process_cb("module %s (%s)" % (moduleName, file))

        # create and load the PyCheckerModule, tricking sys.path temporarily
        oldsyspath = sys.path[:]
        if moduleDir is not None:
            sys.path.insert(0, moduleDir)
        pcmodule = pcmodules.PyCheckerModule(moduleName, moduleDir=moduleDir)
        loaded = pcmodule.load()
        sys.path = oldsyspath

        if not loaded:
            w = Warning(pcmodule.filename(), 1,
                        msgs.Internal("NOT PROCESSED UNABLE TO IMPORT"))
            warnings.append(w)

    utils.debug('Processed %d files' % len(files))

    utils.popConfig()

    return warnings
예제 #8
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
예제 #9
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
예제 #10
0
파일: checker.py 프로젝트: italomaia/spe
def processFiles(files, cfg=None, pre_process_cb=None):
    # insert this here, so we find files in the local dir before std library
    if sys.path[0] != '':
        sys.path.insert(0, '')

    # ensure we have a config object, it's necessary
    global _cfg
    if cfg is not None:
        _cfg = cfg
    elif _cfg is None:
        _cfg = Config.Config()

    warnings = []
    utils.initConfig(_cfg)
    for moduleName in getModules(files):
        if callable(pre_process_cb):
            pre_process_cb(moduleName)
        module = PyCheckerModule(moduleName)
        if not module.load():
            w = Warning(module.filename(), 1,
                        msgs.Internal("NOT PROCESSED UNABLE TO IMPORT"))
            warnings.append(w)
    utils.popConfig()
    return warnings
예제 #11
0
        # read data from the file
        command_file = argv[1][1:]
        try:
            f = open(command_file, 'r')
            command_line = f.read()
            f.close()
        except IOError, err:
            sys.stderr.write("Unable to read commands from file: %s\n  %s\n" % \
                             (command_file, err))
            sys.exit(101)

        # convert to an argv list, keeping argv[0] and the files to process
        argv = argv[:1] + string.split(command_line) + argv[2:]

    global _cfg
    _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)
예제 #12
0
        # read data from the file
        command_file = argv[1][1:]
        try:
            f = open(command_file, 'r')
            command_line = f.read()
            f.close()
        except IOError, err:
            sys.stderr.write("Unable to read commands from file: %s\n  %s\n" % \
                             (command_file, err))
            sys.exit(101)

        # convert to an argv list, keeping argv[0] and the files to process
        argv = argv[:1] + string.split(command_line) + argv[2:]
 
    global _cfg
    _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)