当前位置: 首页>>代码示例>>Python>>正文


Python legacy.get_style_guide方法代码示例

本文整理汇总了Python中flake8.api.legacy.get_style_guide方法的典型用法代码示例。如果您正苦于以下问题:Python legacy.get_style_guide方法的具体用法?Python legacy.get_style_guide怎么用?Python legacy.get_style_guide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flake8.api.legacy的用法示例。


在下文中一共展示了legacy.get_style_guide方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def run():
    """
    Runs flake8 lint

    :return:
        A bool - if flake8 did not find any errors
    """

    print('Running flake8 %s' % flake8.__version__)

    flake8_style = get_style_guide(config_file=os.path.join(package_root, 'tox.ini'))

    paths = []
    for _dir in [package_name, 'dev', 'tests']:
        for root, _, filenames in os.walk(_dir):
            for filename in filenames:
                if not filename.endswith('.py'):
                    continue
                paths.append(os.path.join(root, filename))
    report = flake8_style.check_files(paths)
    success = report.total_errors == 0
    if success:
        print('OK')
    return success 
开发者ID:wbond,项目名称:oscrypto,代码行数:26,代码来源:lint.py

示例2: check_flake8

# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def check_flake8(filename):
    style_guide = flake8.get_style_guide()
    report = style_guide.check_files([filename])
    score = 0
    if report.get_statistics('E') == []:
        score += 3
    else:
        logger.info(report.get_statistics('E'))
    if report.get_statistics('W') == []:
        score += 2
    else:
        logger.info(report.get_statistics('W'))
    if report.get_statistics('F') == []:
        score += 5
    else:
        logger.info(report.get_statistics('F'))
    return score 
开发者ID:amjltc295,项目名称:PythonHomework,代码行数:19,代码来源:autograder.py

示例3: assert_conforms_to_style

# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def assert_conforms_to_style(python_files):
    checker = flake8.get_style_guide(max_complexity=MAX_COMPLEXITY)

    checker.options.jobs = 1
    checker.options.verbose = True
    report = checker.check_files(python_files)

    warnings = report.get_statistics("W")
    errors = report.get_statistics("E")

    assert not (warnings or errors), "\n" + "\n".join([
        "Warnings:",
        "\n".join(warnings),
        "Errors:",
        "\n".join(errors),
    ]) 
开发者ID:wglass,项目名称:collectd-haproxy,代码行数:18,代码来源:test_style.py

示例4: test_flake8

# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_flake8():
    test_dir = os.path.dirname(os.path.abspath(inspect.getfile(
        inspect.currentframe())))
    dispel4py_dir = os.path.dirname(os.path.dirname(test_dir))

    # Possibility to ignore some files and paths.
    ignore_paths = [
        os.path.join(dispel4py_dir, "doc"),
        os.path.join(dispel4py_dir, ".git")]
    files = []
    for dirpath, _, filenames in os.walk(dispel4py_dir):
        ignore = False
        for path in ignore_paths:
            if dirpath.startswith(path):
                ignore = True
                break
        if ignore:
            continue
        filenames = [_i for _i in filenames if
                     os.path.splitext(_i)[-1] == os.path.extsep + "py"]
        if not filenames:
            continue
        for py_file in filenames:
            full_path = os.path.join(dirpath, py_file)
            files.append(full_path)

    # Get the style checker with the default style.
    flake8_style = flake8.get_style_guide(
        parse_argv=False, config_file=flake8.main.DEFAULT_CONFIG)
    flake8_style.options.ignore = tuple(set(
            flake8_style.options.ignore).union(set(FLAKE8_IGNORE_CODES)))

    report = flake8_style.check_files(files)

    # Make sure at least 10 files are tested.
    assert report.counters["files"] > 10
    # And no errors occured.
    assert report.get_count() == 0 
开发者ID:dispel4py,项目名称:dispel4py,代码行数:40,代码来源:test_code_formatting.py

示例5: test_regular_files

# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_regular_files():

    style_guide = flake8.get_style_guide(
        filename=['*.py'],
        exclude=['doc', '.eggs', '*.egg', 'build', 'benchmark.py'],
        select=['E', 'W', 'F'],
        max_line_length=88
    )

    report = style_guide.check_files()

    # CI is complaining so whatevs...
    # assert report.get_statistics('E') == []
    # assert report.get_statistics('W') == []
    # assert report.get_statistics('F') == [] 
开发者ID:NicolasHug,项目名称:Surprise,代码行数:17,代码来源:test_pep8.py

示例6: test_cython_files

# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_cython_files():

    style_guide = flake8.get_style_guide(
        filename=['*.pyx', '*.px'],
        exclude=['doc', '.eggs', '*.egg', 'build', 'setup.py'],
        select=['E', 'W', 'F'],
        ignore=['E225'],
        max_line_length=88
    )

    report = style_guide.check_files()

    # assert report.get_statistics('E') == []
    # assert report.get_statistics('W') == []
    # assert report.get_statistics('F') == [] 
开发者ID:NicolasHug,项目名称:Surprise,代码行数:17,代码来源:test_pep8.py

示例7: test_flake8

# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_flake8():
    style_guide = get_style_guide(extend_ignore=['D100', 'D104'],
                                  show_source=True)
    style_guide_tests = get_style_guide(
        extend_ignore=[
            'D100', 'D101', 'D102', 'D103', 'D104', 'D105', 'D107'],
        show_source=True, )

    stdout = sys.stdout
    sys.stdout = sys.stderr
    # implicitly calls report_errors()
    report = style_guide.check_files(
        [str(Path(__file__).parents[1] / 'colcon_bundle')])
    report_tests = style_guide_tests.check_files(
        [str(Path(__file__).parents[1] / 'tests')])
    sys.stdout = stdout

    total_errors = report.total_errors + report_tests.total_errors
    if total_errors:  # pragma: no cover
        # output summary with per-category counts
        print()
        report._application.formatter.show_statistics(report._stats)
        print('flake8 reported {total_errors} errors'.format_map(locals()),
              file=sys.stderr)

    assert not report.total_errors, 'flake8 reported {total_errors} ' \
                                    'errors'.format_map(locals()) 
开发者ID:colcon,项目名称:colcon-bundle,代码行数:29,代码来源:test_flake8.py

示例8: test_flake8

# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_flake8():
    test_dir = os.path.dirname(os.path.abspath(inspect.getfile(
        inspect.currentframe())))

    basedir = os.path.dirname(test_dir)

    # Possibility to ignore some files and paths.
    ignore_paths = [
        os.path.join(basedir, "doc"),
        os.path.join(basedir, ".git"),
        os.path.join(basedir, "scripts")]
    files = []

    for dirpath, _, filenames in os.walk(basedir):
        ignore = False
        for path in ignore_paths:
            if dirpath.startswith(path):
                ignore = True
                break
        if ignore:
            continue
        filenames = [_i for _i in filenames if
                     os.path.splitext(_i)[-1] == os.path.extsep + "py"]
        if not filenames:
            continue
        for py_file in filenames:
            full_path = os.path.join(dirpath, py_file)
            files.append(full_path)

    style_guide = flake8.get_style_guide(ignore=['E24', 'W503', 'E226'])
    report = style_guide.check_files(files)
    assert report.get_statistics('E') == [], 'Flake8 found violations'
    assert report.total_errors == 0 
开发者ID:computational-seismology,项目名称:pytomo3d,代码行数:35,代码来源:test_code_formatting.py

示例9: test_flake8

# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_flake8():
    style_guide = legacy.get_style_guide()
    report = style_guide.check_files(['lavalink'])
    statistics = report.get_statistics('E')
    failed = bool(statistics)

    if not failed:
        print('OK') 
开发者ID:Devoxin,项目名称:Lavalink.py,代码行数:10,代码来源:run_tests.py

示例10: test_flake8

# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_flake8():
    # for some reason the pydocstyle logger changes to an effective level of 1
    # set higher level to prevent the output to be flooded with debug messages
    log.setLevel(logging.WARNING)

    style_guide = get_style_guide(
        extend_ignore=['D100', 'D104'],
        show_source=True,
    )
    style_guide_tests = get_style_guide(
        extend_ignore=['D100', 'D101', 'D102', 'D103', 'D104', 'D105', 'D107'],
        show_source=True,
    )

    stdout = sys.stdout
    sys.stdout = sys.stderr
    # implicitly calls report_errors()
    report = style_guide.check_files([
        str(Path(__file__).parents[1] / 'bin' / 'colcon'),
        str(Path(__file__).parents[1] / 'colcon_core'),
    ])
    report_tests = style_guide_tests.check_files([
        str(Path(__file__).parents[1] / 'test'),
    ])
    sys.stdout = stdout

    total_errors = report.total_errors + report_tests.total_errors
    if total_errors:  # pragma: no cover
        # output summary with per-category counts
        print()
        if report.total_errors:
            report._application.formatter.show_statistics(report._stats)
        if report_tests.total_errors:
            report_tests._application.formatter.show_statistics(
                report_tests._stats)
        print(
            'flake8 reported {total_errors} errors'
            .format_map(locals()), file=sys.stderr)

    assert not total_errors, \
        'flake8 reported {total_errors} errors'.format_map(locals()) 
开发者ID:colcon,项目名称:colcon-core,代码行数:43,代码来源:test_flake8.py

示例11: test_flake8_pytest

# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_flake8_pytest(mocker):
    python_filepaths = get_python_filepaths(FLAKE8_ROOTS)
    style_guide = get_style_guide(**FLAKE8_OPTIONS)
    fake_stdout = io.StringIO()
    mocker.patch('sys.stdout', fake_stdout)
    report = style_guide.check_files(python_filepaths)
    assert report.total_errors == 0, "There are issues!\n" + fake_stdout.getvalue() 
开发者ID:PyAr,项目名称:fades,代码行数:9,代码来源:test_infra.py

示例12: test_pep8

# 需要导入模块: from flake8.api import legacy [as 别名]
# 或者: from flake8.api.legacy import get_style_guide [as 别名]
def test_pep8(self):
        # verify all files are nicely styled
        python_filepaths = get_python_filepaths()
        style_guide = get_style_guide()
        fake_stdout = io.StringIO()
        with patch('sys.stdout', fake_stdout):
            report = style_guide.check_files(python_filepaths)

        # if flake8 didnt' report anything, we're done
        if report.total_errors == 0:
            return

        # grab on which files we have issues
        flake8_issues = fake_stdout.getvalue().split('\n')
        broken_filepaths = {item.split(':')[0] for item in flake8_issues if item}

        # give hints to the developer on how files' style could be improved
        options = autopep8.parse_args([''])
        options.aggressive = 1
        options.diff = True
        options.max_line_length = 99

        issues = []
        for filepath in broken_filepaths:
            diff = autopep8.fix_file(filepath, options=options)
            if diff:
                issues.append(diff)

        report = ["Please fix files as suggested by autopep8:"] + issues
        report += ["\n-- Original flake8 reports:"] + flake8_issues
        self.fail("\n".join(report)) 
开发者ID:canonical,项目名称:operator,代码行数:33,代码来源:test_infra.py


注:本文中的flake8.api.legacy.get_style_guide方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。