def processText(ctagsLang, text, sortAlphabetically): ctagsPath = core.config()['Navigator']['CtagsPath'] langArg = '--language-force={}'.format(ctagsLang) # \t is used as separator in ctags output. Avoid \t in tags text to simplify parsing # encode to utf8 data = text.replace('\t', ' ').encode('utf8') with _namedTemp() as tempFile: tempFile.write(data) tempFile.close() # Windows compatibility try: stdout = gco.get_console_output([ctagsPath, '-f', '-', '-u', '--fields=nKs', langArg, tempFile.name])[0] except OSError as ex: raise FailedException('Failed to execute ctags console utility "{}": {}\n' .format(ctagsPath, str(ex)) + 'Go to Settings -> Settings -> Navigator to set path to ctags') tags = _parseTags(ctagsLang, stdout) if sortAlphabetically: return _sortTagsAlphabetically(tags) else: return tags
def _processSync(self, language, filePath): conf = core.config()['Lint']['Python'] ignored = ','.join(conf['IgnoredMessages'].split()) try: stdout = get_console_output([ conf['Path'], '--max-line-length={}'.format(conf['MaxLineLength']), '--ignore={}'.format(ignored), filePath ])[0] except OSError: return result = {} for line in stdout.splitlines(): match = self._PARSER_REG_EXP.match(line) if match: filePath = match.group(1) lineNumber = match.group(2) rest = match.group(4) msgId, msgText = rest.lstrip().split(' ', 1) lineIndex = int(lineNumber) - 1 msgType = self._msgType(msgId) if msgType is not None: # not ignored if lineIndex not in result: result[lineIndex] = (msgType, rest) return result
def _processSync(self, language, filePath): conf = core.config()['Lint']['Python'] ignored = ','.join(conf['IgnoredMessages'].split()) try: stdout = get_console_output([conf['Path'], '--max-line-length={}'.format(conf['MaxLineLength']), '--ignore={}'.format(ignored), filePath])[0] except OSError: return result = {} for line in stdout.splitlines(): match = self._PARSER_REG_EXP.match(line) if match: filePath = match.group(1) lineNumber = match.group(2) rest = match.group(4) msgId, msgText = rest.lstrip().split(' ', 1) lineIndex = int(lineNumber) - 1 msgType = self._msgType(msgId) if msgType is not None: # not ignored if lineIndex not in result: result[lineIndex] = (msgType, rest) return result
def _processSync(self, language, filePath): conf = core.config()['Lint']['Python'] ignored = ','.join(conf['IgnoredMessages'].split()) try: stdout = get_console_output([conf['Path'], '--max-line-length={}'.format(conf['MaxLineLength']), '--ignore={}'.format(ignored), filePath])[0] except OSError: return result = {} for line in stdout.splitlines(): match = self._PARSER_REG_EXP.match(line) if match: filePath = match.group(1) lineNumber = match.group(2) columnNumber = match.group(3) rest = match.group(4) msgId, msgText = rest.lstrip().split(' ', 1) lineIndex = int(lineNumber) - 1 # Per comments on _MSG_ID_CONVERTOR, mark PEP8 E9 errors as errors. All # other PEP8 errors are shown as warnings. if msgId.startswith('E9'): msgType = Qutepart.LINT_ERROR else: msgType = self._MSG_ID_CONVERTOR[msgId[0]] if msgType is not None: # not ignored if lineIndex not in result: result[lineIndex] = (msgType, rest) return result
def processText(ctagsLang, text, sortAlphabetically): ctagsPath = core.config()['Navigator']['CtagsPath'] langArg = '--language-force={}'.format(ctagsLang) # \t is used as separator in ctags output. Avoid \t in tags text to simplify parsing # encode to utf8 data = text.replace('\t', ' ').encode('utf8') with _namedTemp() as tempFile: tempFile.write(data) tempFile.close() # Windows compatibility try: stdout = gco.get_console_output([ ctagsPath, '-f', '-', '-u', '--fields=nKs', langArg, tempFile.name ])[0] except OSError as ex: raise FailedException( 'Failed to execute ctags console utility "{}": {}\n'.format( ctagsPath, str(ex)) + 'Go to Settings -> Settings -> Navigator to set path to ctags') tags = _parseTags(ctagsLang, stdout) if sortAlphabetically: return _sortTagsAlphabetically(tags) else: return tags
def _processSync(self, language, filePath): conf = core.config()['Lint']['Python'] ignored = ','.join(conf['IgnoredMessages'].split()) try: stdout = get_console_output([ conf['Path'], '--max-line-length={}'.format(conf['MaxLineLength']), '--ignore={}'.format(ignored), filePath ])[0] except OSError: return result = {} for line in stdout.splitlines(): match = self._PARSER_REG_EXP.match(line) if match: filePath = match.group(1) lineNumber = match.group(2) columnNumber = match.group(3) rest = match.group(4) msgId, msgText = rest.lstrip().split(' ', 1) lineIndex = int(lineNumber) - 1 # Per comments on _MSG_ID_CONVERTOR, mark PEP8 E9 errors as errors. All other PEP8 errors are shown as warnings. if msgId.startswith('E9'): msgType = Qutepart.LINT_ERROR else: msgType = self._MSG_ID_CONVERTOR[msgId[0]] if msgType is not None: # not ignored if lineIndex not in result: result[lineIndex] = (msgType, rest) return result
def _processSync(self, language, filePath): conf = core.config()["Lint"]["Python"] ignored = ",".join(conf["IgnoredMessages"].split()) try: stdout = get_console_output( [ conf["Path"], "--max-line-length={}".format(conf["MaxLineLength"]), "--ignore={}".format(ignored), filePath, ] )[0] except OSError: return result = {} for line in stdout.splitlines(): match = self._PARSER_REG_EXP.match(line) if match: filePath = match.group(1) lineNumber = match.group(2) columnNumber = match.group(3) rest = match.group(4) msgId, msgText = rest.lstrip().split(" ", 1) lineIndex = int(lineNumber) - 1 msgType = self._msgType(msgId) if msgType is not None: # not ignored if lineIndex not in result: result[lineIndex] = (msgType, rest) return result
def _getFlake8Version(path): """Get pylint version as tuple of integer items. Raise OSError if not found ValueError if failed to parse """ stdout = get_console_output([path, '--version'])[0] try: versionLine = stdout.splitlines()[0] except IndexError: # empty output raise ValueError() version = versionLine.split()[0] return [int(num) for num in version.split('.')]
def _updateExecuteError(self, path): """ Check if pylint is installed. Return None if OK or textual error """ try: stdout, stderr = gco.get_console_output(path, ['--version']) except OSError as ex: self.lExecuteError.setText('Failed to execute ctags: {}'.format(ex)) else: if 'Exuberant Ctags' in stdout: self.lExecuteError.setText('ctags is found!') elif 'GNU Emacs' in stdout: self.lExecuteError.setText('You are trying to use etags from the Emacs package, but it is not supported. Use Exuberant Ctags.')
def _getPylintVersion(path): """Get pylint version as tuple of integer items. Raise OSError if not found ValueError if failed to parse """ stdout, stderr = get_console_output(path, ['--version']) try: versionLine = [line \ for line in stdout.splitlines() \ if line.startswith('pylint')][0] version = versionLine.split()[1].rstrip(',') except IndexError: # incorrect version string raise ValueError() return [int(num) \ for num in version.split('.')]
def _updateExecuteError(self, path): """ Check if pylint is installed. Return None if OK or textual error """ try: stdout, stderr = gco.get_console_output([path, '--version']) except OSError as ex: self.lExecuteError.setText( 'Failed to execute ctags: {}'.format(ex)) else: if 'Exuberant Ctags' in stdout: self.lExecuteError.setText('ctags is found!') elif 'GNU Emacs' in stdout: self.lExecuteError.setText( 'You are trying to use etags from the Emacs package, but it is not supported. Use Exuberant Ctags.' )
def _processSync(self, language, filePath): try: stderr, stdout = get_console_output(core.config()['Lint']['Python']['Path'], ['--msg-template=enkilint:{line}:{msg_id}:{msg}', '--reports=no', '--output-format=text', filePath]) except OSError: return result = {} for line in stderr.splitlines(): if line.startswith('enkilint:'): _, lineNumber, msgId, msgText = line.split(':', 3) lineIndex = int(lineNumber) - 1 msgType = self._MSG_ID_CONVERTOR[msgId[0]] if msgType is not None: # not ignored result[lineIndex] = (msgType, msgText) return result
def _getSphinxVersion(path): """Return the Sphinx version as a list of integer items. Raise OSError if not found, or ValueError if failed to parse. """ stdout, stderr = get_console_output([path, "--version"]) # Command "Sphinx-build --version" will only output sphinx version info. # Typical output looks like: ``Sphinx (sphinx-build) 1.2.3`` or # ``Sphinx v1.2.3`` # But the problem is sometimes version info goes to stdout(version 1.2.3), # while sometimes it goes to stderr(version 1.1.3). Thus combining stdout # and stderr is necessary. out = stdout + "\n" + stderr for line in out.split("\n"): if line.startswith("Sphinx"): # Split on space, take the last segment, if it starts with character # 'v', strip the 'v'. Then split on dot. returning the version as a # tuple. version = line.split(" ")[-1] version = version[1:] if version.startswith("v") else version return [int(num) for num in version.split(".")] raise ValueError
def _getSphinxVersion(path): """Return the Sphinx version as a list of integer items. Raise OSError if not found, or ValueError if failed to parse. """ stdout, stderr = get_console_output([path, "--version"]) # Command "Sphinx-build --version" will only output sphinx version info. # Typical output looks like: ``Sphinx (sphinx-build) 1.2.3`` or # ``Sphinx v1.2.3`` # But the problem is sometimes version info goes to stdout(version 1.2.3), # while sometimes it goes to stderr(version 1.1.3). Thus combining stdout # and stderr is necessary. out = stdout + '\n' + stderr for line in out.split('\n'): if line.startswith("Sphinx"): # Split on space, take the last segment, if it starts with character # 'v', strip the 'v'. Then split on dot. returning the version as a # tuple. version = line.split(' ')[-1] version = version[1:] if version.startswith('v') else version return [int(num) for num in version.split('.')] raise ValueError
def _getSphinxVersion(path): """Return the Sphinx version as a list of integer items. Raise OSError if not found, or ValueError if failed to parse. """ stdout, stderr = get_console_output([path, "--version"]) # The command "sphinx-build --version" will only output sphinx version info. Typical output looks like: # # - ``Sphinx (sphinx-build) 1.2.3`` # - ``Sphinx v1.2.3`` # - ``sphinx-build 1.7.0``. # # Sometimes version info goes to stdout (version 1.2.3), while sometimes it goes to stderr (version 1.1.3). Thus combining stdout and stderr is necessary. out = stdout + '\n' + stderr for line in out.split('\n'): if line.lower().startswith("sphinx"): # Split on space, take the last segment, if it starts with character # 'v', strip the 'v'. Then split on a period, returning the version as a tuple. version = line.split(' ')[-1] version = version[1:] if version.startswith('v') else version return [int(num) for num in version.split('.')] raise ValueError