Flake8NbApplication

class Flake8NbApplication(program: str = 'flake8_nb', version: str = '0.5.3')[source]

Subclass of flake8.main.application.Application.

It overwrites the default options and an injection of intermediate parsed *.ipynb files to be checked.

Hacked initialization of flake8.Application.

Parameters:
  • program (str) – Application name, by default “flake8_nb”

  • version (str) – Application version, by default __version__

Attributes Summary

formatter

Generic output formatting.

Methods Summary

apply_hacks

Apply hacks to flake8 adding options and changing the application name + version.

exit

Handle finalization and exiting the program.

exit_code

Return the program exit code.

find_plugins

Find and load the plugins for this application.

hack_args

Update args with *.ipynb files.

hack_flake8_program_and_version

Hack to overwrite the program name and version of flake8.

hack_options

Overwrite flake8's default options, with flake8_nb defaults.

hacked_register_plugin_options

Register options provided by plugins to our option manager.

initialize

Initialize the application to be run.

make_file_checker_manager

Initialize our FileChecker Manager.

make_formatter

Initialize a formatter based on the parsed options.

make_guide

Initialize our StyleGuide.

parse_configuration_and_cli

Parse configuration files and the CLI options.

parse_configuration_and_cli_legacy

Parse configuration files and the CLI options.

parse_preliminary_options

Get preliminary options from the CLI, pre-plugin-loading.

register_plugin_options

Register options provided by plugins to our option manager.

report

Report errors, statistics, and benchmarks.

report_benchmarks

Aggregate, calculate, and report benchmarks for this run.

report_errors

Report all the errors found by flake8 3.0.

report_statistics

Aggregate and report statistics from this run.

run

Run our application.

run_checks

Run the actual checks with the FileChecker Manager.

set_flake8_option

Overwrite flake8 options.

Methods Documentation

apply_hacks() None[source]

Apply hacks to flake8 adding options and changing the application name + version.

exit() None[source]

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.

Raises:

SystemExit – For flake8>=5.0.0

exit_code() int

Return the program exit code.

find_plugins(cfg: RawConfigParser, cfg_dir: str, *, enable_extensions: str | None, require_plugins: str | None) None

Find and load the plugins for this application.

Set plugins based on loaded plugins.

static hack_args(args: list[str], exclude: list[str]) list[str][source]

Update args with *.ipynb files.

Checks the passed args if *.ipynb can be found and appends intermediate parsed files to the list of files, which should be checked.

Parameters:
  • args (list[str]) – List of commandline arguments provided to flake8_nb

  • exclude (list[str]) – File-/Folderpatterns that should be excluded

Returns:

The original args + intermediate parsed *.ipynb files.

Return type:

list[str]

hack_flake8_program_and_version(program: str, version: str) None[source]

Hack to overwrite the program name and version of flake8.

This is needed because those values are hard coded at creation of self.option_manager.

Parameters:
  • program (str) – Name of the program

  • version (str) – Version of the program

hack_options() None[source]

Overwrite flake8’s default options, with flake8_nb defaults.

hacked_register_plugin_options() None[source]

Register options provided by plugins to our option manager.

initialize(argv: Sequence[str]) None

Initialize the application to be run.

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

make_file_checker_manager() None

Initialize our FileChecker Manager.

make_formatter() None

Initialize a formatter based on the parsed options.

make_guide() None

Initialize our StyleGuide.

parse_configuration_and_cli(cfg: configparser.RawConfigParser, cfg_dir: str, argv: list[str]) None[source]

Parse configuration files and the CLI options.

Parameters:
  • cfg (configparser.RawConfigParser) – Config parser instance

  • cfg_dir (str) – Dir the the config is in.

  • argv (list[str]) – CLI args

Raises:

SystemExit – If --bug-report option is passed to the CLI.

parse_configuration_and_cli_legacy(config_finder: config.ConfigFileFinder, argv: list[str]) None[source]

Parse configuration files and the CLI options.

Parameters:
  • config_finder (config.ConfigFileFinder) – The finder for finding and reading configuration files.

  • argv (list[str]) – Command-line arguments passed in directly.

parse_preliminary_options(argv: Sequence[str]) Tuple[Namespace, List[str]]

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 – Command-line arguments passed in directly.

Returns:

Populated namespace and list of remaining argument strings.

register_plugin_options() None

Register options provided by plugins to our option manager.

report() None

Report errors, statistics, and benchmarks.

report_benchmarks() None

Aggregate, calculate, and report benchmarks for this run.

report_errors() None

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() None

Aggregate and report statistics from this run.

run(argv: Sequence[str]) 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() 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.

set_flake8_option(long_option_name: str, *args: Any, **kwargs: Any) None[source]

Overwrite flake8 options.

First deletes and than reads an option to flake8’s cli options, if it was present. If the option wasn’t present, it just adds it.

Parameters:
  • long_option_name (str) – Long name of the flake8 cli option.

  • args (Tuple[Any]) – Arbitrary args

  • kwargs (Dict[str, Any]) – Arbitrary kwargs