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


Python pep8.StyleGuide方法代码示例

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


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

示例1: test_pep8

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def test_pep8(self):
        """Test method to check PEP8 compliance over the entire project."""
        self.file_structure = dirname(dirname(abspath(__file__)))
        print("Testing for PEP8 compliance of python files in {}".format(
            self.file_structure))
        style = pep8.StyleGuide()
        style.options.max_line_length = 100  # Set this to desired maximum line length
        filenames = []
        # Set this to desired folder location
        for root, _, files in os.walk(self.file_structure):
            python_files = [f for f in files if f.endswith(
                '.py') and "examples" not in root]
            for file in python_files:
                if len(root.split('samples')) != 2:     # Ignore samples directory
                    filename = '{0}/{1}'.format(root, file)
                    filenames.append(filename)
        check = style.check_files(filenames)
        self.assertEqual(check.total_errors, 0, 'PEP8 style errors: %d' %
                         check.total_errors) 
开发者ID:HTTP-APIs,项目名称:hydrus,代码行数:21,代码来源:test_pep8.py

示例2: count_pep8_violations

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def count_pep8_violations(repository_info, max_line_length=79, path_whitelist=None):
    path_whitelist = path_whitelist or []
    pep8style = pep8.StyleGuide(
        paths=['--max-line-length', str(max_line_length)],
        quiet=True
    )
    python_file_paths = [parsed_file.path for parsed_file in repository_info.get_parsed_py_files()]
    validatable_paths = []
    for python_file_path in python_file_paths:
        for whitelisted_path_part in path_whitelist:
            if whitelisted_path_part in python_file_path:
                break
        else:
            validatable_paths.append(python_file_path)
    result = pep8style.check_files(validatable_paths)
    return result.total_errors 
开发者ID:devmanorg,项目名称:fiasko_bro,代码行数:18,代码来源:code_helpers.py

示例3: test_pep8_conformance

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def test_pep8_conformance():

    dirs = []
    dirname = os.path.dirname(emva1288.__file__)
    dirs.append(dirname)
    examplesdir = os.path.join(dirname, '..', 'examples')
    examplesdir = os.path.abspath(examplesdir)
    dirs.append(examplesdir)

    pep8style = pep8.StyleGuide()

    # Extend the number of PEP8 guidelines which are not checked.
    pep8style.options.ignore = (pep8style.options.ignore +
                                tuple(PEP8_ADDITIONAL_IGNORE))
    pep8style.options.exclude.extend(EXCLUDE_FILES)

    result = pep8style.check_files(dirs)
    msg = "Found code syntax errors (and warnings)."
    assert_equal(result.total_errors, 0, msg) 
开发者ID:EMVA1288,项目名称:emva1288,代码行数:21,代码来源:test_coding_standards.py

示例4: test_pep8_conformance

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def test_pep8_conformance(self):
        # Tests the nc-time-axis code base against the "pep8" tool.
        #
        # Users can add their own excluded files (should files exist in the
        # local directory which is not in the repository) by adding a
        # ".pep8_test_exclude.txt" file in the same directory as this test.
        # The file should be a line separated list of filenames/directories
        # as can be passed to the "pep8" tool's exclude list.

        pep8style = pep8.StyleGuide(quiet=False)
        pep8style.options.exclude.extend(['*/_version.py'])

        # Allow users to add their own exclude list.
        extra_exclude_file = os.path.join(os.path.dirname(__file__),
                                          '.pep8_test_exclude.txt')
        if os.path.exists(extra_exclude_file):
            with open(extra_exclude_file, 'r') as fhandle:
                extra_exclude = [line.strip()
                                 for line in fhandle if line.strip()]
            pep8style.options.exclude.extend(extra_exclude)

        root = os.path.abspath(nc_time_axis.__file__)
        result = pep8style.check_files([os.path.dirname(root)])
        self.assertEqual(result.total_errors, 0, "Found code syntax "
                                                 "errors (and warnings).") 
开发者ID:SciTools,项目名称:nc-time-axis,代码行数:27,代码来源:test_pep8.py

示例5: pep8

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def pep8(args):
    """Check code for PEP8 violations"""
    try:
        import pep8
    except:
        error('pep8 not found! Run "paver install_devtools".')
        sys.exit(1)

    # Errors to ignore
    ignore = ['E203', 'E121', 'E122', 'E123', 'E124', 'E125', 'E126', 'E127',
        'E128', 'E402']
    styleguide = pep8.StyleGuide(ignore=ignore,
                                 exclude=['*/extlibs/*', '*/ext-src/*'],
                                 repeat=True, max_line_length=79,
                                 parse_argv=args)
    styleguide.input_dir(options.plugin.source_dir)
    info('===== PEP8 SUMMARY =====')
    styleguide.options.report.print_statistics() 
开发者ID:planetfederal,项目名称:qgis-geoserver-plugin,代码行数:20,代码来源:pavement.py

示例6: test_pep8

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def test_pep8(self):
        """ Tests that all files in this, directory, the parent directory, and test
        sub-directories are PEP8 compliant.

        Notes
        -----
        max_line_length has been set to 100 for this test.
        """
        dymos_path = os.path.split(dymos.__file__)[0]
        pyfiles = _discover_python_files(dymos_path)

        style = pep8.StyleGuide(ignore=['E201', 'E226', 'E241', 'E402'])
        style.options.max_line_length = 120

        save = sys.stdout
        sys.stdout = msg = StringIO()
        try:
            report = style.check_files(pyfiles)
        finally:
            sys.stdout = save

        if report.total_errors > 0:
            self.fail("Found pep8 errors:\n%s" % msg.getvalue()) 
开发者ID:OpenMDAO,项目名称:dymos,代码行数:25,代码来源:test_pep8.py

示例7: check_style

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def check_style(filename):
    '''check style of filename.
    '''

    p = pep8.StyleGuide(quiet=True)
    report = p.check_files([filename])

    # count errors/warning excluding
    # those to ignore
    take = [y for x, y
            in report.counters.items() if x not in IGNORE]
    found = ['%s:%i' % (x, y) for x, y
             in report.counters.items() if x not in IGNORE]
    total = sum(take)
    ok_(total == 0,
        'pep8 style violations in %s: %s' % (filename, ','.join(found))) 
开发者ID:CGATOxford,项目名称:UMI-tools,代码行数:18,代码来源:test_style.py

示例8: check_style

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def check_style(filename):
    '''check style of filename.
    '''

    p = pep8.StyleGuide(quiet=True)
    report = p.check_files([filename])

    # count errors/warning excluding
    # those to ignore
    take = [y for x, y
            in list(report.counters.items()) if x not in IGNORE]
    found = ['%s:%i' % (x, y) for x, y
             in list(report.counters.items()) if x not in IGNORE]
    total = sum(take)
    ok_(total == 0,
        'pep8 style violations: %s' % ','.join(found)) 
开发者ID:CGATOxford,项目名称:CGATPipelines,代码行数:18,代码来源:test_style.py

示例9: test_pep8

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def test_pep8(self):
        pep8style = pep8.StyleGuide(
            [
                ["statistics", True],
                ["show-sources", True],
                ["repeat", True],
                ["ignore", "E501"],
                ["paths", [os.path.dirname(os.path.abspath(__file__))]],
            ],
            parse_argv=False,
        )
        report = pep8style.check_files()
        assert report.total_errors == 0 
开发者ID:skorokithakis,项目名称:tbvaccine,代码行数:15,代码来源:tests.py

示例10: test_pep8

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def test_pep8(self):
        pep8style = pep8.StyleGuide([['statistics', True],
                                     ['show-sources', True],
                                     ['repeat', True],
                                     ['ignore', "E501"],
                                     ['paths', [os.path.dirname(
                                         os.path.abspath(__file__))]]],
                                    parse_argv=False)
        report = pep8style.check_files()
        assert report.total_errors == 0 
开发者ID:skorokithakis,项目名称:jsane,代码行数:12,代码来源:test_jsane.py

示例11: test_pep8

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def test_pep8(self):
        """
        verify our codebase complies with code style guidelines
        """
        style = pep8.StyleGuide(quiet=False)
        # accepted pep8 guideline deviances
        style.options.max_line_length = 122  # generally accepted limit
        style.options.ignore = ('W503', 'E402')  # operator at start of line

        errors = 0
        # check main project directory
        for root, _not_used, files in os.walk(os.path.join(os.getcwd(), 'linux_thermaltake_riing')):
            if not isinstance(files, list):
                files = [files]
            for f in files:
                if not str(f).endswith('.py'):
                    continue
                file_path = ['{}/{}'.format(root, f)]
                result = style.check_files(file_path)  # type: pep8.BaseReport
                errors = result.total_errors

        # check tests directory
        for root, _not_used, files in os.walk(os.path.join(os.getcwd(), 'tests')):
            if not isinstance(files, list):
                files = [files]
            for f in files:
                if not str(f).endswith('.py'):
                    continue
                file_path = ['{}/{}'.format(root, f)]
                result = style.check_files(file_path)  # type: pep8.BaseReport
                errors = result.total_errors

        self.assertEqual(0, errors, 'PEP8 style errors: {}'.format(errors)) 
开发者ID:chestm007,项目名称:linux_thermaltake_riing,代码行数:35,代码来源:test_pep8.py

示例12: analyze

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def analyze(self,file_revision):
        pep8style = pep8.StyleGuide(quiet = True)
        try:
            handle,temp_filename = tempfile.mkstemp()
            fh = os.fdopen(handle,"wb")
            fh.write(file_revision.get_file_content())
            fh.close()
            pep8style.init_report(Reporter)
            result = pep8style.check_files([temp_filename])
        finally:
            os.unlink(temp_filename)
        #we add the fingerprints...
        for issue in result.issues:
            issue['fingerprint'] = self.get_fingerprint_from_code(file_revision, issue['location'], extra_data=issue['data'])
        return {'issues' : result.issues} 
开发者ID:quantifiedcode,项目名称:checkmate,代码行数:17,代码来源:analyzer.py

示例13: check_files

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def check_files(dir):
    style = pep8.StyleGuide()
    style.options.max_line_length = 120
    style.options.ignore = 'E402'
    python_files = []
    for root, _, files in os.walk(dir):
        python_files += [os.path.join(root, f) for f in files if f.endswith('.py')]

    for file in python_files:
        report = style.check_files([os.path.join(BASE_PATH, file)])
        report.print_statistics()
        nose.tools.assert_equal(report.total_errors, 0, "File %s has some PEP8 errors: %d" % (file, report.total_errors)) 
开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:14,代码来源:test_pep8.py

示例14: process_items

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def process_items(reporter, items, tester):
    """Process list of modules or packages.
    """
    test_pylint = tester in ("pylint", "all",)
    test_pep8 = tester in ("pep8", "all",)

    if test_pep8:
        # PEP8 report instance setup
        pep8style = StyleGuide(parse_argv=False, config_file=False)
        if reporter.name == "csv":
            pep8style.options.report = CsvPep8Report(pep8style.options,
                                                     reporter.writer)
        else:
            colorized = (reporter.name == "colorized")
            pep8style.options.report = Pep8Report(pep8style.options,
                                                  reporter.line_format,
                                                  reporter.out,
                                                  colorized)

    pylint_rc_path = os.path.join(_CURRENT_PATH, "pylint.rc")
    for item in items:
        path = os.path.join(_BASE_PATH, item)
        if test_pylint:
            # Pylint tests
            lint.Run([path, "--rcfile={0}".format(pylint_rc_path)],
                     reporter=reporter, exit=False)
        if test_pep8:
            # Pep8 tests
            if item.endswith(".py"):
                pep8style.input_file(path)
            else:
                pep8style.input_dir(path) 
开发者ID:mysql,项目名称:mysql-utilities,代码行数:34,代码来源:pylint_tests.py

示例15: test_pep8_conformance

# 需要导入模块: import pep8 [as 别名]
# 或者: from pep8 import StyleGuide [as 别名]
def test_pep8_conformance(self):
        """
        Tests pep8 conformence.
        """
        pep8style = pep8.StyleGuide(quiet=False, ignore=IGNORE_PEP8, max_line_length=100)
        result = pep8style.check_files(['datacats'])
        self.assertEqual(result.total_errors, 0, 'Found code style errors.') 
开发者ID:datacats,项目名称:datacats,代码行数:9,代码来源:test_style.py


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