Command Line Interface¶
The command line interface of Flake8 is modeled as an application via
Application. When a user runs
flake8 at their
main() is run which handles
management of the application.
User input is parsed twice to accommodate logging and verbosity options passed by the user as early as possible. This is so as much logging can be produced as possible.
The default Flake8 options are registered by
register_default_options(). Trying to register
these options in plugins will result in errors.
Execute the main bit of the application.
This handles the creation of an instance of
Application, runs it, and then exits the application.
Parameters: argv (list) – The arguments to be passed to the application for parsing.
Abstract our application into a class.
The left over arguments that were not parsed by
Whether or not something catastrophic happened and we should exit with a non-zero status code
The instance of
The timestamp when the Application finished reported errors.
Handle finalization and exiting the program.
This should be the last thing called on the application instance. It will check certain options and exit appropriately.
flake8.checker.Managerthat will handle running all of the checks selected by the user.
Find and load the plugins for this application.
formatting_pluginsattributes based on the discovered plugins found.
Parameters: config_finder (config.ConfigFileFinder) – The finder for finding and reading configuration files.
The user-selected formatter from
The instance of
flake8.style_guide.StyleGuideManagerbuilt from the user’s options
Initialize the application to be run.
This finds the plugins, registers their options, and parses the command-line arguments.
The instance of
flake8.options.manager.OptionManagerused to parse and handle the options and arguments passed by the user
The user-supplied options parsed into an instance of
Parse configuration files and the CLI options.
- config_finder (config.ConfigFileFinder) – The finder for finding and reading configuration files.
- argv (list) – Command-line arguments passed in directly.
Get preliminary options from the CLI, pre-plugin-loading.
We need to know the values of a few standard options so that we can locate configuration files and configure logging.
Since plugins aren’t loaded yet, there may be some as-yet-unknown options; we ignore those for now, they’ll be parsed later when we do real option parsing.
Parameters: argv (list) – Command-line arguments passed in directly. Returns: Populated namespace and list of remaining argument strings. Return type: (argparse.Namespace, list)
The parsed diff information
The prelimary argument parser for handling options required for obtaining and parsing the configuration file.
The name of the program being run
Report all the errors found by flake8 3.0.
This also updates the
result_countattribute with the total number of errors, warnings, and other messages found.
The number of errors, warnings, and other messages after running flake8 and taking into account ignored errors and lines.
Run our application.
This method will also handle KeyboardInterrupt exceptions for the entirety of the flake8 application. If it sees a KeyboardInterrupt it will forcibly clean up the
Run the actual checks with the FileChecker Manager.
This method encapsulates the logic to make a
Mangerinstance run the checks it is managing.
Parameters: files (list) – List of filenames to process
Whether the program is processing a diff or not
The timestamp when the Application instance was instantiated.
The total number of errors before accounting for ignored errors and lines.
The version of the program being run
Register the default options on our OptionManager.
The default options include: