From 6a2ad045fa3aeff24fbcf11b2abf8ae27035b9f1 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Thu, 30 Jun 2016 08:27:32 -0500 Subject: [PATCH] Add the skeleton for the LegacyStyleGuide --- src/flake8/api/style_guide.py | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/flake8/api/style_guide.py diff --git a/src/flake8/api/style_guide.py b/src/flake8/api/style_guide.py new file mode 100644 index 0000000..4e8595c --- /dev/null +++ b/src/flake8/api/style_guide.py @@ -0,0 +1,47 @@ +"""Module containing shims around Flake8 2.0 behaviour.""" +import os.path + +from flake8.formatting import base as formatter + + +class LegacyStyleGuide(object): + """Public facing object that mimic's Flake8 2.0's StyleGuide.""" + + def __init__(self, application): + self._application = application + self._file_checker_manager = application.file_checker_manager + + @property + def options(self): + """The parsed options. + + An instance of :class:`optparse.Values` containing parsed options. + """ + return self._application.options + + @property + def paths(self): + """The extra arguments passed as paths.""" + return self._application.paths + + def check_files(self, paths=None): + raise NotImplementedError('This should be easy') + + def excluded(self, filename, parent=None): + return (self._file_checker_manager.is_path_excluded(filename) or + (parent and + self._file_checker_manager.is_path_excluded( + os.path.join(parent, filename)))) + + def init_report(self, reporter=None): + if (reporter is not None and + isinstance(reporter, formatter.BaseFormatter)): + self._application.formatter = reporter + self._application.guide = None + # NOTE(sigmavirus24): This isn't the intended use of + # Application#make_guide but it works pretty well. + # Stop cringing... I know it's gross. + self._application.make_guide() + + def input_file(self, filename, lines=None, expected=None, line_offset=0): + raise NotImplementedError('This should be a pain')