]>
Commit | Line | Data |
---|---|---|
53e6db90 DC |
1 | """Functions for constructing the requested report plugin.""" |
2 | from __future__ import annotations | |
3 | ||
4 | import argparse | |
5 | import logging | |
6 | ||
7 | from flake8.formatting.base import BaseFormatter | |
8 | from flake8.plugins.finder import LoadedPlugin | |
9 | ||
10 | LOG = logging.getLogger(__name__) | |
11 | ||
12 | ||
13 | def make( | |
14 | reporters: dict[str, LoadedPlugin], | |
15 | options: argparse.Namespace, | |
16 | ) -> BaseFormatter: | |
17 | """Make the formatter from the requested user options. | |
18 | ||
19 | - if :option:`flake8 --quiet` is specified, return the ``quiet-filename`` | |
20 | formatter. | |
21 | - if :option:`flake8 --quiet` is specified at least twice, return the | |
22 | ``quiet-nothing`` formatter. | |
23 | - otherwise attempt to return the formatter by name. | |
24 | - failing that, assume it is a format string and return the ``default`` | |
25 | formatter. | |
26 | """ | |
27 | format_name = options.format | |
28 | if options.quiet == 1: | |
29 | format_name = "quiet-filename" | |
30 | elif options.quiet >= 2: | |
31 | format_name = "quiet-nothing" | |
32 | ||
33 | try: | |
34 | format_plugin = reporters[format_name] | |
35 | except KeyError: | |
36 | LOG.warning( | |
37 | "%r is an unknown formatter. Falling back to default.", | |
38 | format_name, | |
39 | ) | |
40 | format_plugin = reporters["default"] | |
41 | ||
42 | return format_plugin.obj(options) |