Skip to content

Commit

Permalink
Don't error out when parsing unknown command-line arguments.
Browse files Browse the repository at this point in the history
Given who we are, we don't want to parse command-line arguments on
Flake8's behalf. It will do that later in the call chain and report
errors accordingly. We only care if `--toml-config` is present, the
one argument that is "known" to us, but want to defer error reporting
for anything else.
  • Loading branch information
john-hen committed Mar 21, 2023
1 parent 182eb8e commit 636b978
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions flake8p/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# Remember original Flake8 objects.
flake8_aggregate_options = flake8.options.aggregator.aggregate_options
flake8_parse_config = flake8.options.config.parse_config

# Global variable pointing to TOML config.
toml_config = Path('pyproject.toml')

Expand All @@ -36,12 +37,12 @@ def aggregate_options(manager, cfg, cfg_dir, argv):
command-line option, its value is stored in a global variable for
later consumption in parse_config().
Finally, Flake8's aggregate_options() is called as usual.
Finally, Flake8's `aggregate_options()` is called as usual.
"""
arguments = manager.parse_args(argv)
global toml_config
arguments = manager.parser.parse_known_args(argv)[0]
if arguments.toml_config:
toml_config = Path(arguments.toml_config).resolve()
toml_config = Path(arguments.toml_config)
if not toml_config.exists():
raise FileNotFoundError(
f'Plug-in {meta.title} could not find '
Expand Down Expand Up @@ -71,7 +72,7 @@ def parse_config(option_manager, cfg, cfg_dir):
if isinstance(value, (bool, int, float)):
value = str(value)
parser.set(section, key, value)
(cfg, cfg_dir) = (parser, str(toml_config.parent))
(cfg, cfg_dir) = (parser, str(toml_config.resolve().parent))

return flake8_parse_config(option_manager, cfg, cfg_dir)

Expand Down

0 comments on commit 636b978

Please sign in to comment.