示例#1
0
def check_pep8(filename, **kwargs):
    """Perform static analysis on the given file.

    :param filename: path of file to check.
    :type filename: str
    :param ignore: codes to ignore, e.g. ``('E111', 'E123')``
    :type ignore: `list`
    :param select: codes to explicitly select.
    :type select: `list`
    :param pyflakes: run the pyflakes checks too (default ``True``)
    :type pyflakes: bool
    :return: errors
    :rtype: `list`

    .. seealso:: :py:class:`pycodestyle.Checker`
    """
    options = {
        "ignore": kwargs.get("ignore"),
        "select": kwargs.get("select"),
    }

    if not _registered_pyflakes_check and kwargs.get("pyflakes", True):
        _register_pyflakes_check()

    checker = pep8.Checker(filename, reporter=_Report, **options)
    checker.check_all()

    errors = []
    for error in sorted(checker.report.errors, key=lambda x: x[0]):
        errors.append("{0}:{1}: {3}".format(*error))
    return errors
示例#2
0
def check_pep8(filename, **kwargs):
    """Perform static analysis on the given file.

    Options:
    * pep8_ignore: e.g. ('E111', 'E123')
    * pep8_select: ditto
    * pep8_pyflakes: True
    """

    pep8options = {
        "ignore": kwargs.get("pep8_ignore"),
        "select": kwargs.get("pep8_select"),
    }

    if not _registered_pyflakes_check and kwargs.get("pep8_pyflakes", True):
        _register_pyflakes_check()

    checker = pep8.Checker(filename, reporter=_Report, **pep8options)
    checker.check_all()

    errors = []
    checker.report.errors.sort()
    for error in checker.report.errors:
        errors.append("{0}:{1}: {3}".format(*error))
    return errors
示例#3
0
def check_pep8(filename, **kwargs):
    """Perform static analysis on the given file.

    :param filename: path of file to check.
    :type filename: str
    :param ignore: codes to ignore, e.g. ``('E111', 'E123')``
    :type ignore: `list`
    :param select: codes to explicitly select.
    :type select: `list`
    :param pyflakes: run the pyflakes checks too (default ``True``)
    :type pyflakes: bool
    :return: errors
    :rtype: `list`

    .. seealso:: :py:class:`pycodestyle.Checker`
    """
    options = {
        "ignore": kwargs.get("ignore"),
        "select": kwargs.get("select"),
    }

    if not _registered_pyflakes_check and kwargs.get("pyflakes", True):
        _register_pyflakes_check()

    checker = pep8.Checker(filename, reporter=_Report, **options)
    checker.check_all()

    errors = []
    for error in sorted(checker.report.errors, key=lambda x: x[0]):
        errors.append("{0}:{1}: {3}".format(*error))
    return errors
示例#4
0
    def _check_pep8(self, path):
        if not install_flg['pep8']:
            return [{'line': 0, 'msg': 'no install pep8'}]

        return
        print(path)
        checker = pep8.Checker(path)
        t = tempfile.TemporaryFile()
        sys.stdout = t
        checker.check_all()
        t.seek(0)
        s = t.read()
        sys.stdout.close()
        sys.stdout = sys.__stdout__

        res = []
        arr = s.split('\n')
        for e in arr:
            if e.strip() == '':
                continue
            cols = e.split(':')
            res.append({
                'line': int(cols[1]),
                'msg': ':'.join(cols[3:])
            })
        return res
示例#5
0
def get_style_problems(source, filename):
    config, _args = pep8.process_options([filename], config_file=True)
    config = dict(config.__dict__, reporter=Pep8Report)
    guide = pep8.StyleGuide(**config)
    lines = source.splitlines(True)
    checker = pep8.Checker(filename, lines, guide.options)
    checker.check_all()
    return checker.report.problems
示例#6
0
def get_style_problems(source, filename):
    config, _args = pep8.process_options([filename], config_file=True)
    config = dict(config.__dict__, reporter=Pep8Report)
    guide = pep8.StyleGuide(**config)
    lines = source.splitlines(True)
    checker = pep8.Checker(filename, lines, guide.options)
    checker.check_all()
    return checker.report.problems
示例#7
0
 def check(self, path, lines):
     report = _Pep8Report()
     if len(lines) > 1 or (lines and lines[0]):
         checker = pep8.Checker(path, lines=lines, report=report)
         checker.check_all()
     return report.messages
示例#8
0
 def check(self, path, lines):
     report = _Pep8Report()
     if len(lines) > 1 or (lines and lines[0]):
         checker = pep8.Checker(path, lines=lines, report=report)
         checker.check_all()
     return report.messages