Exemplo n.º 1
0
    def parse_options(cls, options):
        if options.builtins:
            cls.builtIns = cls.builtIns.union(options.builtins.split(','))
        cls.withDoctest = options.doctests

        included_files = []
        for included_file in options.include_in_doctest.split(','):
            if included_file == '':
                continue
            if not included_file.startswith((os.sep, './', '~/')):
                included_files.append('./' + included_file)
            else:
                included_files.append(included_file)
        cls.include_in_doctest = pep8.normalize_paths(','.join(included_files))

        excluded_files = []
        for excluded_file in options.exclude_from_doctest.split(','):
            if excluded_file == '':
                continue
            if not excluded_file.startswith((os.sep, './', '~/')):
                excluded_files.append('./' + excluded_file)
            else:
                excluded_files.append(excluded_file)
        cls.exclude_from_doctest = pep8.normalize_paths(
            ','.join(excluded_files))

        inc_exc = set(cls.include_in_doctest).intersection(
            set(cls.exclude_from_doctest))
        if inc_exc:
            raise ValueError('"%s" was specified in both the '
                             'include-in-doctest and exclude-from-doctest '
                             'options. You are not allowed to specify it in '
                             'both for doctesting.' % inc_exc)
Exemplo n.º 2
0
    def parse_options(cls, options):
        if options.builtins:
            cls.builtIns = cls.builtIns.union(options.builtins.split(','))
        cls.withDoctest = options.doctests

        included_files = []
        for included_file in options.include_in_doctest.split(','):
            if included_file == '':
                continue
            if not included_file.startswith((os.sep, './', '~/')):
                included_files.append('./' + included_file)
            else:
                included_files.append(included_file)
        cls.include_in_doctest = pep8.normalize_paths(','.join(included_files))

        excluded_files = []
        for excluded_file in options.exclude_from_doctest.split(','):
            if excluded_file == '':
                continue
            if not excluded_file.startswith((os.sep, './', '~/')):
                excluded_files.append('./' + excluded_file)
            else:
                excluded_files.append(excluded_file)
        cls.exclude_from_doctest = pep8.normalize_paths(
            ','.join(excluded_files))

        inc_exc = set(cls.include_in_doctest).intersection(
            set(cls.exclude_from_doctest))
        if inc_exc:
            raise ValueError('"%s" was specified in both the '
                             'include-in-doctest and exclude-from-doctest '
                             'options. You are not allowed to specify it in '
                             'both for doctesting.' % inc_exc)
Exemplo n.º 3
0
def get_style_guide(**kwargs):
    """Parse the options and configure the checker. This returns a sub-class
    of ``pep8.StyleGuide``."""
    kwargs['parser'], options_hooks = get_parser()
    styleguide = StyleGuide(**kwargs)
    options = styleguide.options
    _disable_extensions(kwargs['parser'], options)

    if options.exclude and not isinstance(options.exclude, list):
        options.exclude = pep8.normalize_paths(options.exclude)
    elif not options.exclude:
        options.exclude = []

    # Add patterns in EXTRA_EXCLUDE to the list of excluded patterns
    options.exclude.extend(pep8.normalize_paths(EXTRA_EXCLUDE))

    for options_hook in options_hooks:
        options_hook(options)

    if util.warn_when_using_jobs(options):
        if not multiprocessing:
            warnings.warn("The multiprocessing module is not available. "
                          "Ignoring --jobs arguments.")
        if util.is_windows():
            warnings.warn("The --jobs option is not available on Windows. "
                          "Ignoring --jobs arguments.")
        if util.is_using_stdin(styleguide.paths):
            warnings.warn("The --jobs option is not compatible with supplying "
                          "input using - . Ignoring --jobs arguments.")
        if options.diff:
            warnings.warn("The --diff option was specified with --jobs but "
                          "they are not compatible. Ignoring --jobs arguments."
                          )

    if options.diff:
        options.jobs = None

    force_disable_jobs = util.force_disable_jobs(styleguide)

    if multiprocessing and options.jobs and not force_disable_jobs:
        if options.jobs.isdigit():
            n_jobs = int(options.jobs)
        else:
            try:
                n_jobs = multiprocessing.cpu_count()
            except NotImplementedError:
                n_jobs = 1
        if n_jobs > 1:
            options.jobs = n_jobs
            reporter = QueueReport
            if options.quiet:
                reporter = BaseQReport
                if options.quiet == 1:
                    reporter = FileQReport
            report = styleguide.init_report(reporter)
            report.input_file = styleguide.input_file
            styleguide.runner = report.task_queue.put

    return styleguide
Exemplo n.º 4
0
def get_style_guide(**kwargs):
    """Parse the options and configure the checker. This returns a sub-class
    of ``pep8.StyleGuide``."""
    kwargs['parser'], options_hooks = get_parser()
    styleguide = StyleGuide(**kwargs)
    options = styleguide.options
    _disable_extensions(kwargs['parser'], options)

    if options.exclude and not isinstance(options.exclude, list):
        options.exclude = pep8.normalize_paths(options.exclude)
    elif not options.exclude:
        options.exclude = []

    # Add patterns in EXTRA_EXCLUDE to the list of excluded patterns
    options.exclude.extend(pep8.normalize_paths(EXTRA_EXCLUDE))

    for options_hook in options_hooks:
        options_hook(options)

    if util.warn_when_using_jobs(options):
        if not multiprocessing:
            warnings.warn("The multiprocessing module is not available. "
                          "Ignoring --jobs arguments.")
        if util.is_windows():
            warnings.warn("The --jobs option is not available on Windows. "
                          "Ignoring --jobs arguments.")
        if util.is_using_stdin(styleguide.paths):
            warnings.warn("The --jobs option is not compatible with supplying "
                          "input using - . Ignoring --jobs arguments.")
        if options.diff:
            warnings.warn("The --diff option was specified with --jobs but "
                          "they are not compatible. Ignoring --jobs arguments."
                          )

    if options.diff:
        options.jobs = None

    force_disable_jobs = util.force_disable_jobs(styleguide)

    if multiprocessing and options.jobs and not force_disable_jobs:
        if options.jobs.isdigit():
            n_jobs = int(options.jobs)
        else:
            try:
                n_jobs = multiprocessing.cpu_count()
            except NotImplementedError:
                n_jobs = 1
        if n_jobs > 1:
            options.jobs = n_jobs
            reporter = QueueReport
            if options.quiet:
                reporter = BaseQReport
                if options.quiet == 1:
                    reporter = FileQReport
            report = styleguide.init_report(reporter)
            report.input_file = styleguide.input_file
            styleguide.runner = report.task_queue.put

    return styleguide
Exemplo n.º 5
0
    def run(self):
        import pylint.lint
        import pycodestyle

        files = ["setup.py", "virt-install", "virt-clone",
                 "virt-convert", "virt-xml", "virt-manager",
                 "virtcli", "virtinst", "virtconv", "virtManager",
                 "tests"]

        output_format = sys.stdout.isatty() and "colorized" or "text"
        exclude = ["virtinst/progress.py"]

        print("running pycodestyle")
        style_guide = pycodestyle.StyleGuide(
            config_file='tests/pycodestyle.cfg',
            paths=files
        )
        style_guide.options.exclude = pycodestyle.normalize_paths(
            ','.join(exclude)
        )
        report = style_guide.check_files()
        if style_guide.options.count:
            sys.stderr.write(str(report.total_errors) + '\n')

        print("running pylint")
        pylint_opts = [
            "--rcfile", "tests/pylint.cfg",
            "--output-format=%s" % output_format,
        ] + ["--ignore"] + [os.path.basename(p) for p in exclude]
        if self.jobs:
            pylint_opts += ["--jobs=%d" % self.jobs]

        pylint.lint.Run(files + pylint_opts)
Exemplo n.º 6
0
    def run(self):
        import pylint.lint
        import pycodestyle

        files = (["bugzilla-cli", "bugzilla"] +
            glob.glob("examples/*.py") +
            glob.glob("tests/*.py"))
        output_format = sys.stdout.isatty() and "colorized" or "text"

        print("running pycodestyle")
        style_guide = pycodestyle.StyleGuide(
            config_file='tests/pycodestyle.cfg',
            paths=files,
        )
        style_guide.options.exclude = pycodestyle.normalize_paths(
            "bugzilla/oldclasses.py",
        )
        report = style_guide.check_files()
        if style_guide.options.count:
            sys.stderr.write(str(report.total_errors) + '\n')

        print("running pylint")
        pylint_opts = [
            "--rcfile", "tests/pylint.cfg",
            "--output-format=%s" % output_format,
        ]
        pylint.lint.Run(files + pylint_opts)
Exemplo n.º 7
0
    def run(self):
        import pylint.lint
        import pycodestyle

        files = (["bugzilla-cli", "bugzilla"] + glob.glob("examples/*.py") +
                 glob.glob("tests/*.py"))
        output_format = sys.stdout.isatty() and "colorized" or "text"

        print("running pycodestyle")
        style_guide = pycodestyle.StyleGuide(
            config_file='tests/pycodestyle.cfg',
            paths=files,
        )
        style_guide.options.exclude = pycodestyle.normalize_paths(
            "bugzilla/oldclasses.py", )
        report = style_guide.check_files()
        if style_guide.options.count:
            sys.stderr.write(str(report.total_errors) + '\n')

        print("running pylint")
        pylint_opts = [
            "--rcfile",
            "tests/pylint.cfg",
            "--output-format=%s" % output_format,
        ]
        pylint.lint.Run(files + pylint_opts)
Exemplo n.º 8
0
    def test_normalize_paths(self):
        cwd = os.getcwd()

        self.assertEqual(normalize_paths(''), [])
        self.assertEqual(normalize_paths([]), [])
        self.assertEqual(normalize_paths(None), [])
        self.assertEqual(normalize_paths(['foo']), ['foo'])
        self.assertEqual(normalize_paths('foo'), ['foo'])
        self.assertEqual(normalize_paths('foo,bar'), ['foo', 'bar'])
        self.assertEqual(normalize_paths('foo,  bar  '), ['foo', 'bar'])
        self.assertEqual(normalize_paths('/foo/bar,baz/../bat'),
                         ['/foo/bar', cwd + '/bat'])
        self.assertEqual(normalize_paths(".pyc,\n   build/*"),
                         ['.pyc', cwd + '/build/*'])
Exemplo n.º 9
0
    def test_normalize_paths(self):
        cwd = os.getcwd()

        self.assertEqual(normalize_paths(''), [])
        self.assertEqual(normalize_paths([]), [])
        self.assertEqual(normalize_paths(None), [])
        self.assertEqual(normalize_paths(['foo']), ['foo'])
        self.assertEqual(normalize_paths('foo'), ['foo'])
        self.assertEqual(normalize_paths('foo,bar'), ['foo', 'bar'])
        self.assertEqual(normalize_paths('foo,  bar  '), ['foo', 'bar'])
        self.assertEqual(normalize_paths('/foo/bar,baz/../bat'),
                         ['/foo/bar', cwd + '/bat'])
        self.assertEqual(normalize_paths(".pyc,\n   build/*"),
                         ['.pyc', cwd + '/build/*'])
Exemplo n.º 10
0
 def test_normalize_paths(self):
     self.assertEqual(normalize_paths(''), [])
     self.assertEqual(normalize_paths([]), [])
     self.assertEqual(normalize_paths(None), [])
     self.assertEqual(normalize_paths(['foo']), ['foo'])
     self.assertEqual(normalize_paths('foo'), ['foo'])
     self.assertEqual(normalize_paths('foo,bar'), ['foo', 'bar'])
     self.assertEqual(normalize_paths('foo,  bar  '), ['foo', 'bar'])
     self.assertEqual(
         normalize_paths('/foo/bar,baz/../bat'),
         [os.path.realpath('/foo/bar'),
          os.path.abspath('bat')],
     )
     self.assertEqual(
         normalize_paths(".pyc,\n   build/*"),
         ['.pyc', os.path.abspath('build/*')],
     )
Exemplo n.º 11
0
    def __init__(self, tree, filename):
        filename = pep8.normalize_paths(filename)[0]
        withDoctest = self.withDoctest
        included_by = [include for include in self.include_in_doctest
                       if include != '' and filename.startswith(include)]
        if included_by:
            withDoctest = True

        for exclude in self.exclude_from_doctest:
            if exclude != '' and filename.startswith(exclude):
                withDoctest = False
                overlaped_by = [include for include in included_by
                                if include.startswith(exclude)]

                if overlaped_by:
                    withDoctest = True

        super(FlakesChecker, self).__init__(tree, filename,
                                            withDoctest=withDoctest)
Exemplo n.º 12
0
    def __init__(self, tree, filename):
        filename = pep8.normalize_paths(filename)[0]
        withDoctest = self.withDoctest
        included_by = [
            include for include in self.include_in_doctest
            if include != '' and filename.startswith(include)
        ]
        if included_by:
            withDoctest = True

        for exclude in self.exclude_from_doctest:
            if exclude != '' and filename.startswith(exclude):
                withDoctest = False
                overlaped_by = [
                    include for include in included_by
                    if include.startswith(exclude)
                ]

                if overlaped_by:
                    withDoctest = True

        super(FlakesChecker, self).__init__(tree,
                                            filename,
                                            withDoctest=withDoctest)
Exemplo n.º 13
0
# -*- coding: utf-8 -*-
Exemplo n.º 14
0
# -*- coding: utf-8 -*-