Skip to content

Commit

Permalink
Merge pull request #1576 from PyCQA/simplify-decisions
Browse files Browse the repository at this point in the history
simplify decision engine
  • Loading branch information
asottile committed Mar 23, 2022
2 parents dba40df + c5225db commit ddb04f7
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 350 deletions.
56 changes: 29 additions & 27 deletions src/flake8/main/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def stage1_arg_parser() -> argparse.ArgumentParser:
"--verbose",
default=0,
action="count",
help="Print more information about what is happening in flake8."
" This option is repeatable and will increase verbosity each "
help="Print more information about what is happening in flake8. "
"This option is repeatable and will increase verbosity each "
"time it is repeated.",
)

Expand Down Expand Up @@ -157,8 +157,8 @@ def register_default_options(option_manager: OptionManager) -> None:
"--count",
action="store_true",
parse_from_config=True,
help="Print total number of errors and warnings to standard output and"
" set the exit code to 1 if total is not empty.",
help="Print total number of errors to standard output and "
"set the exit code to 1 if total is not empty.",
)

add_option(
Expand All @@ -175,8 +175,8 @@ def register_default_options(option_manager: OptionManager) -> None:
comma_separated_list=True,
parse_from_config=True,
normalize_paths=True,
help="Comma-separated list of files or directories to exclude."
" (Default: %(default)s)",
help="Comma-separated list of files or directories to exclude. "
"(Default: %(default)s)",
)

add_option(
Expand All @@ -186,8 +186,8 @@ def register_default_options(option_manager: OptionManager) -> None:
parse_from_config=True,
comma_separated_list=True,
normalize_paths=True,
help="Comma-separated list of files or directories to add to the list"
" of excluded ones.",
help="Comma-separated list of files or directories to add to the list "
"of excluded ones.",
)

add_option(
Expand All @@ -203,9 +203,9 @@ def register_default_options(option_manager: OptionManager) -> None:
add_option(
"--stdin-display-name",
default="stdin",
help="The name used when reporting errors from code passed via stdin."
" This is useful for editors piping the file contents to flake8."
" (Default: %(default)s)",
help="The name used when reporting errors from code passed via stdin. "
"This is useful for editors piping the file contents to flake8. "
"(Default: %(default)s)",
)

# TODO(sigmavirus24): Figure out --first/--repeat
Expand All @@ -225,28 +225,29 @@ def register_default_options(option_manager: OptionManager) -> None:
"--hang-closing",
action="store_true",
parse_from_config=True,
help="Hang closing bracket instead of matching indentation of opening"
" bracket's line.",
help="Hang closing bracket instead of matching indentation of opening "
"bracket's line.",
)

add_option(
"--ignore",
metavar="errors",
default=",".join(defaults.IGNORE),
parse_from_config=True,
comma_separated_list=True,
help="Comma-separated list of errors and warnings to ignore (or skip)."
" For example, ``--ignore=E4,E51,W234``. (Default: %(default)s)",
help=(
f"Comma-separated list of error codes to ignore (or skip). "
f"For example, ``--ignore=E4,E51,W234``. "
f"(Default: {','.join(defaults.IGNORE)})"
),
)

add_option(
"--extend-ignore",
metavar="errors",
default="",
parse_from_config=True,
comma_separated_list=True,
help="Comma-separated list of errors and warnings to add to the list"
" of ignored ones. For example, ``--extend-ignore=E4,E51,W234``.",
help="Comma-separated list of error codes to add to the list of "
"ignored ones. For example, ``--extend-ignore=E4,E51,W234``.",
)

add_option(
Expand Down Expand Up @@ -291,21 +292,22 @@ def register_default_options(option_manager: OptionManager) -> None:
add_option(
"--select",
metavar="errors",
default=",".join(defaults.SELECT),
parse_from_config=True,
comma_separated_list=True,
help="Comma-separated list of errors and warnings to enable."
" For example, ``--select=E4,E51,W234``. (Default: %(default)s)",
help=(
f"Comma-separated list of error codes to enable. "
f"For example, ``--select=E4,E51,W234``. "
f"(Default: {','.join(defaults.SELECT)})"
),
)

add_option(
"--extend-select",
metavar="errors",
default="",
parse_from_config=True,
comma_separated_list=True,
help=(
"Comma-separated list of errors and warnings to add to the list "
"Comma-separated list of error codes to add to the list "
"of selected ones. For example, ``--extend-select=E4,E51,W234``."
),
)
Expand Down Expand Up @@ -339,7 +341,7 @@ def register_default_options(option_manager: OptionManager) -> None:
"--statistics",
action="store_true",
parse_from_config=True,
help="Count errors and warnings.",
help="Count errors.",
)

# Flake8 options
Expand All @@ -358,8 +360,8 @@ def register_default_options(option_manager: OptionManager) -> None:
type=JobsArgument,
help="Number of subprocesses to use to run checks in parallel. "
'This is ignored on Windows. The default, "auto", will '
"auto-detect the number of processors available to use."
" (Default: %(default)s)",
"auto-detect the number of processors available to use. "
"(Default: %(default)s)",
)

add_option(
Expand Down
20 changes: 3 additions & 17 deletions src/flake8/options/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,9 @@ def aggregate_options(
# Get the parsed config
parsed_config = config.parse_config(manager, cfg, cfg_dir)

# Extend the default ignore value with the extended default ignore list,
# registered by plugins.
extended_default_ignore = manager.extended_default_ignore.copy()
# Let's store our extended default ignore for use by the decision engine
default_values.extended_default_ignore = (
manager.extended_default_ignore.copy()
)
LOG.debug("Extended default ignore list: %s", extended_default_ignore)
extended_default_ignore.extend(default_values.ignore)
default_values.ignore = extended_default_ignore
LOG.debug("Merged default ignore list: %s", default_values.ignore)

extended_default_select = manager.extended_default_select.copy()
LOG.debug(
"Extended default select list: %s", list(extended_default_select)
)
default_values.extended_default_select = extended_default_select
# store the plugin-set extended default ignore / select
default_values.extended_default_ignore = manager.extended_default_ignore
default_values.extended_default_select = manager.extended_default_select

# Merge values parsed from config onto the default values returned
for config_name, value in parsed_config.items():
Expand Down

0 comments on commit ddb04f7

Please sign in to comment.