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

API Documentation

flake8.main.cli.main(argv=None)[source]

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 (Sequence[str] | None) – The arguments to be passed to the application for parsing.

Return type:

int

class flake8.main.application.Application[source]

Abstract our application into a class.

catastrophic_failure

Whether or not something catastrophic happened and we should exit with a non-zero status code

end_time: float | None

The timestamp when the Application finished reported errors.

exit_code()[source]

Return the program exit code.

Return type:

int

file_checker_manager: Manager | None

The flake8.checker.Manager that will handle running all of the checks selected by the user.

formatter: BaseFormatter | None

The user-selected formatter from formatting_plugins

guide: StyleGuideManager | None

The flake8.style_guide.StyleGuideManager built from the user’s options

initialize(argv)[source]

Initialize the application to be run.

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

Parameters:

argv (Sequence[str]) –

Return type:

None

make_file_checker_manager(argv)[source]

Initialize our FileChecker Manager.

Parameters:

argv (Sequence[str]) –

Return type:

None

make_formatter()[source]

Initialize a formatter based on the parsed options.

Return type:

None

make_guide()[source]

Initialize our StyleGuide.

Return type:

None

options: Namespace | None

The user-supplied options parsed into an instance of argparse.Namespace

report()[source]

Report errors, statistics, and benchmarks.

Return type:

None

report_benchmarks()[source]

Aggregate, calculate, and report benchmarks for this run.

Return type:

None

report_errors()[source]

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.

Return type:

None

report_statistics()[source]

Aggregate and report statistics from this run.

Return type:

None

result_count

The number of errors, warnings, and other messages after running flake8 and taking into account ignored errors and lines.

run(argv)[source]

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.

Parameters:

argv (Sequence[str]) –

Return type:

None

run_checks()[source]

Run the actual checks with the FileChecker Manager.

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

Return type:

None

start_time

The timestamp when the Application instance was instantiated.

total_result_count

The total number of errors before accounting for ignored errors and lines.

flake8.main.options.register_default_options(option_manager)[source]

Register the default options on our OptionManager.

The default options include:

  • -q/--quiet

  • --color

  • --count

  • --exclude

  • --extend-exclude

  • --filename

  • --format

  • --hang-closing

  • --ignore

  • --extend-ignore

  • --per-file-ignores

  • --max-line-length

  • --max-doc-length

  • --indent-size

  • --select

  • --extend-select

  • --disable-noqa

  • --show-source

  • --statistics

  • --exit-zero

  • -j/--jobs

  • --tee

  • --benchmark

  • --bug-report

Parameters:

option_manager (OptionManager) –

Return type:

None