invert order of legacy to make it easier to type

This commit is contained in:
Anthony Sottile 2022-01-05 12:08:16 -05:00
parent 0d4128db48
commit 1c3fef6cda

View file

@ -19,43 +19,50 @@ LOG = logging.getLogger(__name__)
__all__ = ("get_style_guide",) __all__ = ("get_style_guide",)
def get_style_guide(**kwargs): class Report:
r"""Provision a StyleGuide for use. """Public facing object that mimic's Flake8 2.0's API.
:param \*\*kwargs: .. note::
Keyword arguments that provide some options for the StyleGuide.
:returns: There are important changes in how this object behaves compared to
An initialized StyleGuide the object provided in Flake8 2.x.
:rtype:
:class:`StyleGuide` .. warning::
This should not be instantiated by users.
.. versionchanged:: 3.0.0
""" """
application = app.Application()
prelim_opts, remaining_args = application.parse_preliminary_options([])
flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
cfg, cfg_dir = config.load_config( def __init__(self, application: app.Application) -> None:
config=prelim_opts.config, """Initialize the Report for the user.
extra=prelim_opts.append_config,
isolated=prelim_opts.isolated,
)
application.find_plugins(cfg, cfg_dir, prelim_opts.enable_extensions) .. warning:: This should not be instantiated by users.
application.register_plugin_options() """
application.parse_configuration_and_cli(cfg, cfg_dir, remaining_args) assert application.guide is not None
# We basically want application.initialize to be called but with these self._application = application
# options set instead before we make our formatter, notifier, internal self._style_guide = application.guide
# style guide and file checker manager. self._stats = self._style_guide.stats
options = application.options
for key, value in kwargs.items(): @property
try: def total_errors(self) -> int:
getattr(options, key) """Return the total number of errors."""
setattr(options, key, value) return self._application.result_count
except AttributeError:
LOG.error('Could not update option "%s"', key) def get_statistics(self, violation: str) -> List[str]:
application.make_formatter() """Get the list of occurrences of a violation.
application.make_guide()
application.make_file_checker_manager() :returns:
return StyleGuide(application) List of occurrences of a violation formatted as:
{Count} {Error Code} {Message}, e.g.,
``8 E531 Some error message about the error``
:rtype:
list
"""
return [
f"{s.count} {s.error_code} {s.message}"
for s in self._stats.statistics_for(violation)
]
class StyleGuide: class StyleGuide:
@ -169,47 +176,40 @@ class StyleGuide:
return self.check_files([filename]) return self.check_files([filename])
class Report: def get_style_guide(**kwargs):
"""Public facing object that mimic's Flake8 2.0's API. r"""Provision a StyleGuide for use.
.. note:: :param \*\*kwargs:
Keyword arguments that provide some options for the StyleGuide.
There are important changes in how this object behaves compared to :returns:
the object provided in Flake8 2.x. An initialized StyleGuide
:rtype:
.. warning:: :class:`StyleGuide`
This should not be instantiated by users.
.. versionchanged:: 3.0.0
""" """
application = app.Application()
prelim_opts, remaining_args = application.parse_preliminary_options([])
flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
def __init__(self, application: app.Application) -> None: cfg, cfg_dir = config.load_config(
"""Initialize the Report for the user. config=prelim_opts.config,
extra=prelim_opts.append_config,
isolated=prelim_opts.isolated,
)
.. warning:: This should not be instantiated by users. application.find_plugins(cfg, cfg_dir, prelim_opts.enable_extensions)
""" application.register_plugin_options()
assert application.guide is not None application.parse_configuration_and_cli(cfg, cfg_dir, remaining_args)
self._application = application # We basically want application.initialize to be called but with these
self._style_guide = application.guide # options set instead before we make our formatter, notifier, internal
self._stats = self._style_guide.stats # style guide and file checker manager.
options = application.options
@property for key, value in kwargs.items():
def total_errors(self) -> int: try:
"""Return the total number of errors.""" getattr(options, key)
return self._application.result_count setattr(options, key, value)
except AttributeError:
def get_statistics(self, violation: str) -> List[str]: LOG.error('Could not update option "%s"', key)
"""Get the list of occurrences of a violation. application.make_formatter()
application.make_guide()
:returns: application.make_file_checker_manager()
List of occurrences of a violation formatted as: return StyleGuide(application)
{Count} {Error Code} {Message}, e.g.,
``8 E531 Some error message about the error``
:rtype:
list
"""
return [
f"{s.count} {s.error_code} {s.message}"
for s in self._stats.statistics_for(violation)
]