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 for options_hook in options_hooks: options_hook(options) if options.diff: options.jobs = None force_disable_jobs = is_windows() or is_using_stdin(styleguide.paths) 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 = BaseQReport if options.quiet else QueueReport report = styleguide.init_report(reporter) report.input_file = styleguide.input_file styleguide.runner = report.task_queue.put return styleguide
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
def _job_tester(self, jobs): # mock stdout.flush so we can count the number of jobs created with mock.patch('sys.stdout.flush') as mocked: guide, report = self.check_files(arglist=['--jobs=%s' % jobs]) if is_windows(): # The code path where guide.options.jobs gets converted to an # int is not run on windows. So, do the int conversion here. self.assertEqual(int(guide.options.jobs), jobs) # On windows, call count is always zero. self.assertEqual(mocked.call_count, 0) else: self.assertEqual(guide.options.jobs, jobs) self.assertEqual(mocked.call_count, jobs)
def _job_tester(self, jobs, verbose=False): # mock stdout.flush so we can count the number of jobs created with mock.patch('sys.stdout.flush') as mocked: ( guide, report, collected_warnings, ) = self.check_files_collect_warnings(arglist=['--jobs=%s' % jobs], verbose=verbose) if is_windows(): # The code path where guide.options.jobs gets converted to an # int is not run on windows. So, do the int conversion here. self.assertEqual(int(guide.options.jobs), jobs) # On windows, call count is always zero. self.assertEqual(mocked.call_count, 0) else: self.assertEqual(guide.options.jobs, jobs) self.assertEqual(mocked.call_count, jobs) expected_warings = [] if verbose and is_windows(): expected_warings.append(self.windows_warning_text) self.verify_warnings(collected_warnings, expected_warings)
def _job_tester(self, jobs, verbose=False): # mock stdout.flush so we can count the number of jobs created with mock.patch('sys.stdout.flush') as mocked: (guide, report, collected_warnings, ) = self.check_files_collect_warnings( arglist=['--jobs=%s' % jobs], verbose=verbose) if is_windows(): # The code path where guide.options.jobs gets converted to an # int is not run on windows. So, do the int conversion here. self.assertEqual(int(guide.options.jobs), jobs) # On windows, call count is always zero. self.assertEqual(mocked.call_count, 0) else: self.assertEqual(guide.options.jobs, jobs) self.assertEqual(mocked.call_count, jobs) expected_warings = [] if verbose and is_windows(): expected_warings.append(self.windows_warning_text) self.verify_warnings(collected_warnings, expected_warings)
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 pattersn 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 options.diff: options.jobs = None force_disable_jobs = is_windows() or is_using_stdin(styleguide.paths) 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 = BaseQReport if options.quiet else QueueReport report = styleguide.init_report(reporter) report.input_file = styleguide.input_file styleguide.runner = report.task_queue.put return styleguide
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 pattersn 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 options.diff: options.jobs = None force_disable_jobs = is_windows() or is_using_stdin(styleguide.paths) 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 = BaseQReport if options.quiet else QueueReport report = styleguide.init_report(reporter) report.input_file = styleguide.input_file styleguide.runner = report.task_queue.put return styleguide
def test_stdin_jobs_warning(self, verbose=False): self.count = 0 def fake_stdin(): self.count += 1 with open(self.this_file(), "r") as f: return f.read() with mock.patch("pycodestyle.stdin_get_value", fake_stdin): (style_guide, report, collected_warnings, ) = self.check_files_collect_warnings(arglist=['--jobs=4'], explicit_stdin=True, verbose=verbose) expected_warings = [] if verbose: expected_warings.append(self.stdin_warning_text) if is_windows(): expected_warings.append(self.windows_warning_text) self.verify_warnings(collected_warnings, expected_warings) self.assertEqual(self.count, 1)
def test_stdin_jobs_warning(self, verbose=False): self.count = 0 def fake_stdin(): self.count += 1 with open(self.this_file(), "r") as f: return f.read() with mock.patch("pep8.stdin_get_value", fake_stdin): ( style_guide, report, collected_warnings, ) = self.check_files_collect_warnings(arglist=['--jobs=4'], explicit_stdin=True, verbose=verbose) expected_warings = [] if verbose: expected_warings.append(self.stdin_warning_text) if is_windows(): expected_warings.append(self.windows_warning_text) self.verify_warnings(collected_warnings, expected_warings) self.assertEqual(self.count, 1)
"""
# -*- coding: utf-8 -*-
from __future__ import with_statement