Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Verify we update the version string idempotently."""
assert optmanager.version == TEST_VERSION
assert optmanager.version_action.version == TEST_VERSION
optmanager.registered_plugins = [
manager.PluginVersion('Testing 100', '0.0.0', False),
manager.PluginVersion('Testing 101', '0.0.0', False),
manager.PluginVersion('Testing 300', '0.0.0', False),
]
optmanager.update_version_string()
assert optmanager.version == TEST_VERSION
assert (optmanager.version_action.version == TEST_VERSION
+ ' (Testing 100: 0.0.0, Testing 101: 0.0.0, Testing 300: 0.0.0) '
+ utils.get_python_version())
def test_parse_comma_separated_list(value, expected):
"""Verify that similar inputs produce identical outputs."""
assert utils.parse_comma_separated_list(value) == expected
def parse_configuration_and_cli(self, argv=None):
# type: (Union[NoneType, List[str]]) -> NoneType
"""Parse configuration files and the CLI options.
:param list argv:
Command-line arguments passed in directly.
"""
if self.options is None and self.args is None:
self.options, self.args = aggregator.aggregate_options(
self.option_manager, self.config_finder, argv
)
self.running_against_diff = self.options.diff
if self.running_against_diff:
self.parsed_diff = utils.parse_unified_diff()
if not self.parsed_diff:
self.exit()
self.options._running_from_vcs = False
self.check_plugins.provide_options(self.option_manager, self.options,
self.args)
self.listening_plugins.provide_options(self.option_manager,
self.options,
self.args)
self.formatting_plugins.provide_options(self.option_manager,
self.options,
self.args)
def parse_configuration_and_cli(self, argv=None):
# type: (Optional[List[str]]) -> None
"""Parse configuration files and the CLI options.
:param list argv:
Command-line arguments passed in directly.
"""
if self.options is None and self.args is None:
self.options, self.args = aggregator.aggregate_options(
self.option_manager, self.config_finder, argv
)
self.running_against_diff = self.options.diff
if self.running_against_diff:
self.parsed_diff = utils.parse_unified_diff()
if not self.parsed_diff:
self.exit()
self.options._running_from_vcs = False
self.check_plugins.provide_options(
self.option_manager, self.options, self.args
)
self.formatting_plugins.provide_options(
self.option_manager, self.options, self.args
)
def parse_options(cls, options):
"""Parse option values from Flake8's OptionManager."""
if options.builtins:
cls.builtIns = cls.builtIns.union(options.builtins)
cls.with_doctest = options.doctests
included_files = []
for included_file in options.include_in_doctest:
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 = utils.normalize_paths(included_files)
excluded_files = []
for excluded_file in options.exclude_from_doctest:
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 = utils.normalize_paths(excluded_files)
inc_exc = set(cls.include_in_doctest).intersection(
cls.exclude_from_doctest
)
if inc_exc:
raise ValueError(
def normalize(self, value, *normalize_args):
"""Normalize the value based on the option configuration."""
if self.normalize_paths:
# Decide whether to parse a list of paths or a single path
normalize = utils.normalize_path
if self.comma_separated_list:
normalize = utils.normalize_paths
return normalize(value, *normalize_args)
elif self.comma_separated_list:
return utils.parse_comma_separated_list(value)
return value
def applies_to(self, filename): # type: (str) -> bool
"""Check if this StyleGuide applies to the file.
:param str filename:
The name of the file with violations that we're potentially
applying this StyleGuide to.
:returns:
True if this applies, False otherwise
:rtype:
bool
"""
if self.filename is None:
return True
return utils.matches_filename(
filename,
patterns=[self.filename],
log_message='{!r} does %(whether)smatch "%(path)s"'.format(self),
logger=LOG,
)
def normalize(self, value, *normalize_args):
# type: (Any, *str) -> Any
"""Normalize the value based on the option configuration."""
if self.comma_separated_list and isinstance(
value, utils.string_types
):
value = utils.parse_comma_separated_list(value)
if self.normalize_paths:
if isinstance(value, list):
value = utils.normalize_paths(value, *normalize_args)
else:
value = utils.normalize_path(value, *normalize_args)
return value
import optparse
import tokenize
import warnings
# Polyfill stdin loading/reading lines
# https://gitlab.com/pycqa/flake8-polyfill/blob/1.0.1/src/flake8_polyfill/stdin.py#L52-57
try:
from flake8.engine import pep8
stdin_get_value = pep8.stdin_get_value
readlines = pep8.readlines
except ImportError:
from flake8 import utils
import pycodestyle
stdin_get_value = utils.stdin_get_value
readlines = pycodestyle.readlines
from flake8_quotes.__about__ import __version__
from flake8_quotes.docstring_detection import get_docstring_tokens
class QuoteChecker(object):
name = __name__
version = __version__
INLINE_QUOTES = {
# When user wants only single quotes
"'": {
'good_single': "'",
'bad_single': '"',
},