Command Line Interface

The command line interface of Flake8 is modeled as an application via Application. When a user runs flake8 at their command line, main() is run which handles management of the application.

User input is parsed twice to accomodate 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.

API Documentation

flake8.main.cli.main(argv=None)

Main entry-point for the flake8 command-line tool.

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.
class flake8.main.application.Application(program='flake8', version='3.0.1')

Abstract our application into a class.

exit()

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.

find_plugins()

Find and load the plugins for this application.

If check_plugins, listening_plugins, or formatting_plugins are None then this method will update them with the appropriate plugin manager instance. Given the expense of finding plugins (via pkg_resources) we want this to be idempotent and so only update those attributes if they are None.

initialize(argv)

Initialize the application to be run.

This finds the plugins, registers their options, and parses the command-line arguments.

make_file_checker_manager()

Initialize our FileChecker Manager.

make_formatter(formatter_class=None)

Initialize a formatter based on the parsed options.

make_guide()

Initialize our StyleGuide.

make_notifier()

Initialize our listener Notifier.

parse_configuration_and_cli(argv=None)

Parse configuration files and the CLI options.

Parameters:argv (list) – Command-line arguments passed in directly.
register_plugin_options()

Register options provided by plugins to our option manager.

report_benchmarks()

Aggregate, calculate, and report benchmarks for this run.

report_errors()

Report all the errors found by flake8 3.0.

This also updates the result_count attribute with the total number of errors, warnings, and other messages found.

report_statistics()

Aggregate and report statistics from this run.

run(argv=None)

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 Manager.

run_checks(files=None)

Run the actual checks with the FileChecker Manager.

This method encapsulates the logic to make a Manger instance run the checks it is managing.

Parameters:files (list) – List of filenames to process
flake8.main.options.register_default_options(option_manager)

Register the default options on our OptionManager.

The default options include:

  • -v/--verbose
  • -q/--quiet
  • --count
  • --diff
  • --exclude
  • --filename
  • --format
  • --hang-closing
  • --ignore
  • --max-line-length
  • --select
  • --disable-noqa
  • --show-source
  • --statistics
  • --enable-extensions
  • --exit-zero
  • -j/--jobs
  • --output-file
  • --append-config
  • --config
  • --isolated