コード例 #1
0
    def RunModuleFind(self):
        """Run Module Finder
        @note: runs on background thread
        """
        results = FindResults()
        flag, localpythonpath = ToolConfig.GetPythonExecutablePath("PyFind")

        if not flag:
            # No configured Python
            results.Errors.add(localpythonpath)
            return results

        # No findmodule found in plugin
        if not pkg_resources.resource_exists("PyStudio.ModuleFinder",
                                             "findmodule.py"):
            results.Errors.add(ERROR_NO_FINDMODULE)
            return results

        findmodule_script = pkg_resources.resource_filename(
            "PyStudio.ModuleFinder", "findmodule.py")

        # Start find module
        finder_cmd = [localpythonpath, findmodule_script]
        if self.localpath:
            finder_cmd.append(self.localpath)
        finder_cmd.append(self.moduletofind)
        if self.quickfind:
            finder_cmd.append('firstmatch')
        processcreator = ProcessCreator("PyFind", ".", finder_cmd,
                                        self.pythonpath)
        process = processcreator.createprocess()
        stdoutdata, stderrdata = process.communicate()
        processcreator.restorepath()

        util.Log("[PyFind][info] stdout %s" % stdoutdata)
        util.Log("[PyFind][info] stderr %s" % stderrdata)
        util.Log("[PyFind][info] PyFind command finished running")
        try:
            stdoutrows = eval(stdoutdata.rstrip('\r\n'))
            if self.pythonpath:
                results.Info.append(
                    (INFO_USED_PATH, u", ".join(self.pythonpath)))
            results.Info.append((INFO_COMMAND_LINE, " ".join(finder_cmd)))
            if self.dirvarfile:
                results.Info.append((INFO_DIRVARS, self.dirvarfile))
            results.SetResults(stdoutrows)
            return results
        except Exception, ex:
            msg = repr(ex)
            util.Log("[PyFind][info] Error: %s" % msg)
            results.Errors.add(msg)
            return results
コード例 #2
0
    def RunModuleFind(self):
        """Run Module Finder
        @note: runs on background thread
        """
        results = FindResults()
        flag, localpythonpath = ToolConfig.GetPythonExecutablePath("PyFind")

        if not flag:
            # No configured Python
            results.Errors.add(localpythonpath)
            return results

        # No findmodule found in plugin
        if not pkg_resources.resource_exists("PyStudio.ModuleFinder", "findmodule.py"):
            results.Errors.add(ERROR_NO_FINDMODULE)
            return results

        findmodule_script = pkg_resources.resource_filename("PyStudio.ModuleFinder", "findmodule.py")

        # Start find module
        finder_cmd = [localpythonpath, findmodule_script]
        if self.localpath:
            finder_cmd.append(self.localpath)
        finder_cmd.append(self.moduletofind)
        if self.quickfind:
            finder_cmd.append('firstmatch')
        processcreator = ProcessCreator("PyFind", ".", finder_cmd, self.pythonpath)
        process = processcreator.createprocess()
        stdoutdata, stderrdata = process.communicate()
        processcreator.restorepath()

        util.Log("[PyFind][info] stdout %s" % stdoutdata)
        util.Log("[PyFind][info] stderr %s" % stderrdata)
        util.Log("[PyFind][info] PyFind command finished running")
        try:
            stdoutrows = eval(stdoutdata.rstrip('\r\n'))
            if self.pythonpath:
                results.Info.append((INFO_USED_PATH, u", ".join(self.pythonpath)))
            results.Info.append((INFO_COMMAND_LINE, " ".join(finder_cmd)))
            if self.dirvarfile:
                results.Info.append((INFO_DIRVARS, self.dirvarfile))
            results.SetResults(stdoutrows)
            return results
        except Exception, ex:
            msg = repr(ex)
            util.Log("[PyFind][info] Error: %s" % msg)
            results.Errors.add(msg)
            return results
コード例 #3
0
    def DoCompileCheck(self, path):
        """Run a compilation check on the given path
        @return: tuple(path, output)

        """
        flag, pypath = ToolConfig.GetPythonExecutablePath("CompileCheck")
        if not flag:
            # No configured Python
            return (None, u"No Python")  # TODO translations (send error code)
        # run 'python -m py_compile fname'
        parentPath = ebmlib.GetPathName(path)
        fname = ebmlib.GetFileName(path)
        cmd = [pypath, '-m', 'py_compile', fname]
        # TODO: pythonpath?
        processcreator = ProcessCreator("CompileCheck", parentPath, cmd)
        process = processcreator.createprocess()
        stdoutdata, stderrdata = process.communicate()
        processcreator.restorepath()
        return (path, stderrdata)
コード例 #4
0
    def DoCompileCheck(self, path):
        """Run a compilation check on the given path
        @return: tuple(path, output)

        """
        flag, pypath = ToolConfig.GetPythonExecutablePath("CompileCheck")
        if not flag:
            # No configured Python
            return (None, u"No Python") # TODO translations (send error code)
        # run 'python -m py_compile fname'
        parentPath = ebmlib.GetPathName(path)
        fname = ebmlib.GetFileName(path)
        cmd = [pypath, '-m', 'py_compile', fname]
        # TODO: pythonpath?
        processcreator = ProcessCreator("CompileCheck", parentPath, cmd)
        process = processcreator.createprocess()
        stdoutdata, stderrdata = process.communicate()
        processcreator.restorepath()
        return (path, stderrdata)
コード例 #5
0
    def RunSyntaxCheck(self):
        """Run pylint"""

        flag, localpythonpath = ToolConfig.GetPythonExecutablePath("PyLint")

        if not flag:
            # No configured Python
            return ([(u"No Python", localpythonpath, u"NA")], u"None")

        childPath, parentPath = PyStudioUtils.get_packageroot(self.filename)

        # Start pylint
        modpath = PyStudioUtils.get_modulepath(childPath)
        allargs = self.pylintargs + [modpath,]
        pythoncode = "from pylint import lint;lint.Run(%s)" % repr(allargs)
        plint_cmd = [localpythonpath, "-c", pythoncode]
        processcreator = ProcessCreator("Pylint", parentPath, plint_cmd, self.pythonpath)
        process = processcreator.createprocess()
        stdoutdata, stderrdata = process.communicate()
        processcreator.restorepath()

        util.Log("[Pylint][info] stdout %s" % stdoutdata)
        util.Log("[Pylint][info] stderr %s" % stderrdata)
        stderrlower = stderrdata.lower()
        ind = stderrlower.find("importerror")
        if ind != -1:
            if stderrlower.find("pylint", ind) != -1:
                return ([(u"No Pylint", self.nopylinterror, u"NA")], u"None")

        # The parseable line format is:
        #       '%(path)s:%(line)s: [%(sigle)s%(obj)s] %(msg)s'
        regex = re.compile(r"(.*):(.*): \[([A-Z])[, ]*(.*)\] (.*)%s" % os.linesep)
        rows = []
        # TODO: returned messages need to be translatable
        if self.pythonpath:
            rows.append((u"***", u"Using PYTHONPATH + %s"\
                          % u", ".join(self.pythonpath), u"NA"))
        rows.append((u"***", u"Pylint command line: %s" % " ".join(plint_cmd), u"NA"))
        rows.append((u"***", u"Directory Variables file: %s" % self.dirvarfile, u"NA"))
        rowsdict = {}
        lastmatchindex = 0
        for matcher in regex.finditer(stdoutdata):
            if matcher is None:
                continue
            mtypeabr = matcher.group(3)
            linenostr = matcher.group(2)
            classmeth = matcher.group(4)
            mtext = matcher.group(5)
            lastmatchindex = matcher.end(5)
            if mtypeabr in (u"E", u"F"):
                mtype = u"Error"
            elif mtypeabr == u"C":
                mtype = u"Convention"
            elif mtypeabr == u"R":
                mtype = u"Refactor"
            else: # TODO: add more specific filtering? / do translations on display
                mtype = u"Warning"

            outtext = mtext
            if classmeth:
                outtext = u"[%s] %s" % (classmeth, outtext)

            try:
                lineno = int(linenostr)
                mtyperows = rowsdict.get(mtype)
                if not mtyperows:
                    mtyperows = {}
                    rowsdict[mtype] = mtyperows
                linenorows = mtyperows.get(lineno)
                if not linenorows:
                    linenorows = set()
                    mtyperows[lineno] = linenorows
                linenorows.add(outtext)
            except:
                rows.append((mtype, outtext, linenostr))

        for mtype in sorted(rowsdict):
            mtyperows = rowsdict[mtype]
            for lineno in sorted(mtyperows):
                linenorows = mtyperows[lineno]
                for outtext in sorted(linenorows):
                    rows.append((mtype, outtext, lineno))

        index = stdoutdata.find("Report", lastmatchindex)
        util.Log("[PyLint][info] Pylint command finished running")
        if index == -1:
            return (rows, "")
        return (rows, stdoutdata[index:].replace("\r", ""))
コード例 #6
0
    def RunSyntaxCheck(self):
        """Run pep8
        @return: tuple([list_of_rows,], string)

        """

        flag, localpythonpath = ToolConfig.GetPythonExecutablePath("Pep8")

        if not flag:
            # No configured Python
            return ([(u"No Python", localpythonpath, u"NA")], u"None")

        childPath, parentPath = PyStudioUtils.get_packageroot(self.filename)

        # Start pep8 check
        pythoncode = "import sys,pep8;sys.argv=[u'pep8', %s];pep8._main()" % repr(
            childPath)
        pep8_cmd = [localpythonpath, "-c", pythoncode]
        processcreator = ProcessCreator("Pep8", parentPath, pep8_cmd,
                                        self.pythonpath)
        process = processcreator.createprocess()
        stdoutdata, stderrdata = process.communicate()
        processcreator.restorepath()

        util.Log("[Pep8][info] stdout %s" % stdoutdata)
        util.Log("[Pep8][info] stderr %s" % stderrdata)
        stderrlower = stderrdata.lower()
        ind = stderrlower.find("importerror")
        if ind != -1:
            if stderrlower.find("pep8", ind) != -1:
                return ([(u"No Pep8", self.nopep8error, u"NA")], u"None")

        # The parseable line format is:
        #       '%(path)s:%(line)s: [%(sigle)s%(obj)s] %(msg)s'
        regex = re.compile(r"(.*):(.*):(.*): ([A-Z])[0-9]* (.*)%s" %
                           os.linesep)
        rows = []
        # TODO: returned messages need to be translatable
        if self.pythonpath:
            rows.append((u"***", u"Using PYTHONPATH + %s"\
                          % u", ".join(self.pythonpath), u"NA"))
        rows.append(
            (u"***", u"Pep8 command line: %s" % " ".join(pep8_cmd), u"NA"))
        rowsdict = {}
        for matcher in regex.finditer(stdoutdata):
            if matcher is None:
                continue
            mtypeabr = matcher.group(4)
            linenostr = matcher.group(2)
            colnostr = matcher.group(3)
            mtext = matcher.group(5)
            if mtypeabr in (u"E", u"F"):
                mtype = u"Error"
            else:  #TODO: add more specific filtering? / do translations on display
                mtype = u"Warning"

            outtext = "%s: %s" % (colnostr, mtext)
            try:
                lineno = int(linenostr)
                mtyperows = rowsdict.get(mtype)
                if not mtyperows:
                    mtyperows = {}
                    rowsdict[mtype] = mtyperows
                linenorows = mtyperows.get(lineno)
                if not linenorows:
                    linenorows = set()
                    mtyperows[lineno] = linenorows
                linenorows.add(outtext)
            except:
                rows.append((mtype, outtext, linenostr))

        for mtype in sorted(rowsdict):
            mtyperows = rowsdict[mtype]
            for lineno in sorted(mtyperows):
                linenorows = mtyperows[lineno]
                for outtext in sorted(linenorows):
                    rows.append((mtype, outtext, lineno))

        util.Log("[Pep8][info] Pep8 command finished running")
        return (rows, stdoutdata)
コード例 #7
0
    def RunSyntaxCheck(self):
        """Run pep8
        @return: tuple([list_of_rows,], string)

        """

        flag, localpythonpath = ToolConfig.GetPythonExecutablePath("Pep8")

        if not flag:
            # No configured Python
            return ([(u"No Python", localpythonpath, u"NA")], u"None")

        childPath, parentPath = PyStudioUtils.get_packageroot(self.filename)

        # Start pep8 check
        pythoncode = "import sys,pep8;sys.argv=[u'pep8', %s];pep8._main()" % repr(childPath)
        pep8_cmd = [localpythonpath, "-c", pythoncode]
        processcreator = ProcessCreator("Pep8", parentPath, pep8_cmd, self.pythonpath)
        process = processcreator.createprocess()
        stdoutdata, stderrdata = process.communicate()
        processcreator.restorepath()

        util.Log("[Pep8][info] stdout %s" % stdoutdata)
        util.Log("[Pep8][info] stderr %s" % stderrdata)
        stderrlower = stderrdata.lower()
        ind = stderrlower.find("importerror")
        if ind != -1:
            if stderrlower.find("pep8", ind) != -1:
                return ([(u"No Pep8", self.nopep8error, u"NA")], u"None")

        # The parseable line format is:
        #       '%(path)s:%(line)s: [%(sigle)s%(obj)s] %(msg)s'
        regex = re.compile(r"(.*):(.*):(.*): ([A-Z])[0-9]* (.*)%s" % os.linesep)
        rows = []
        # TODO: returned messages need to be translatable
        if self.pythonpath:
            rows.append((u"***", u"Using PYTHONPATH + %s"\
                          % u", ".join(self.pythonpath), u"NA"))
        rows.append((u"***", u"Pep8 command line: %s" % " ".join(pep8_cmd), u"NA"))
        rowsdict = {}
        for matcher in regex.finditer(stdoutdata):
            if matcher is None:
                continue
            mtypeabr = matcher.group(4)
            linenostr = matcher.group(2)
            colnostr = matcher.group(3)
            mtext = matcher.group(5)
            if mtypeabr in (u"E", u"F"):
                mtype = u"Error"
            else: #TODO: add more specific filtering? / do translations on display
                mtype = u"Warning"

            outtext = "%s: %s" % (colnostr, mtext)
            try:
                lineno = int(linenostr)
                mtyperows = rowsdict.get(mtype)
                if not mtyperows:
                    mtyperows = {}
                    rowsdict[mtype] = mtyperows
                linenorows = mtyperows.get(lineno)
                if not linenorows:
                    linenorows = set()
                    mtyperows[lineno] = linenorows
                linenorows.add(outtext)
            except:
                rows.append((mtype, outtext, linenostr))

        for mtype in sorted(rowsdict):
            mtyperows = rowsdict[mtype]
            for lineno in sorted(mtyperows):
                linenorows = mtyperows[lineno]
                for outtext in sorted(linenorows):
                    rows.append((mtype, outtext, lineno))
        
        util.Log("[Pep8][info] Pep8 command finished running")
        return (rows, stdoutdata)
コード例 #8
0
 def __init__(self, parent, textfn, info, parentPath, cmdline, pythonpath=None):
     eclib.ProcessThreadBase.__init__(self, parent)
     ProcessCreator.__init__(self, info, parentPath, cmdline, pythonpath)
     self.AddText = textfn
コード例 #9
0
    def RunSyntaxCheck(self):
        """Run pylint"""

        flag, localpythonpath = ToolConfig.GetPythonExecutablePath("PyLint")

        if not flag:
            # No configured Python
            return ([(u"No Python", localpythonpath, u"NA")], u"None")

        childPath, parentPath = PyStudioUtils.get_packageroot(self.filename)

        # Start pylint
        modpath = PyStudioUtils.get_modulepath(childPath)
        allargs = self.pylintargs + [
            modpath,
        ]
        pythoncode = "from pylint import lint;lint.Run(%s)" % repr(allargs)
        plint_cmd = [localpythonpath, "-c", pythoncode]
        processcreator = ProcessCreator("Pylint", parentPath, plint_cmd,
                                        self.pythonpath)
        process = processcreator.createprocess()
        stdoutdata, stderrdata = process.communicate()
        processcreator.restorepath()

        util.Log("[Pylint][info] stdout %s" % stdoutdata)
        util.Log("[Pylint][info] stderr %s" % stderrdata)
        stderrlower = stderrdata.lower()
        ind = stderrlower.find("importerror")
        if ind != -1:
            if stderrlower.find("pylint", ind) != -1:
                return ([(u"No Pylint", self.nopylinterror, u"NA")], u"None")

        # The parseable line format is:
        #       '%(path)s:%(line)s: [%(sigle)s%(obj)s] %(msg)s'
        regex = re.compile(r"(.*):(.*): \[([A-Z])[, ]*(.*)\] (.*)%s" %
                           os.linesep)
        rows = []
        # TODO: returned messages need to be translatable
        if self.pythonpath:
            rows.append((u"***", u"Using PYTHONPATH + %s"\
                          % u", ".join(self.pythonpath), u"NA"))
        rows.append(
            (u"***", u"Pylint command line: %s" % " ".join(plint_cmd), u"NA"))
        rows.append(
            (u"***", u"Directory Variables file: %s" % self.dirvarfile, u"NA"))
        rowsdict = {}
        lastmatchindex = 0
        for matcher in regex.finditer(stdoutdata):
            if matcher is None:
                continue
            mtypeabr = matcher.group(3)
            linenostr = matcher.group(2)
            classmeth = matcher.group(4)
            mtext = matcher.group(5)
            lastmatchindex = matcher.end(5)
            if mtypeabr in (u"E", u"F"):
                mtype = u"Error"
            elif mtypeabr == u"C":
                mtype = u"Convention"
            elif mtypeabr == u"R":
                mtype = u"Refactor"
            else:  # TODO: add more specific filtering? / do translations on display
                mtype = u"Warning"

            outtext = mtext
            if classmeth:
                outtext = u"[%s] %s" % (classmeth, outtext)

            try:
                lineno = int(linenostr)
                mtyperows = rowsdict.get(mtype)
                if not mtyperows:
                    mtyperows = {}
                    rowsdict[mtype] = mtyperows
                linenorows = mtyperows.get(lineno)
                if not linenorows:
                    linenorows = set()
                    mtyperows[lineno] = linenorows
                linenorows.add(outtext)
            except:
                rows.append((mtype, outtext, linenostr))

        for mtype in sorted(rowsdict):
            mtyperows = rowsdict[mtype]
            for lineno in sorted(mtyperows):
                linenorows = mtyperows[lineno]
                for outtext in sorted(linenorows):
                    rows.append((mtype, outtext, lineno))

        index = stdoutdata.find("Report", lastmatchindex)
        util.Log("[PyLint][info] Pylint command finished running")
        if index == -1:
            return (rows, "")
        return (rows, stdoutdata[index:].replace("\r", ""))