PyCQA / PyCQA/flake8

Unclear how plugins should indicate a configuration failure

Open
#1,108 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
3.8k
Forks
356
PR merge metrics
No merged PRs in 30d

Description

In GitLab by @pjacock on Aug 6, 2019, 02:42

I have read http://flake8.pycqa.org/en/latest/plugin-development/plugin-parameters.html#accessing-parsed-options

I am working on a plugin which successfully sets and receives additional configuration values. However, I wish to validate the configuration once (as early as possible), and may need to indicate an error to flake8 signalling it to abort. The simple option of raising a ValueError within parse_options does not work gracefully:

...

    @classmethod
    def add_options(cls, parser):
        ...
        # Define option "--our_config_file"

    @classmethod
    def parse_options(cls, options):
        ...
        if not os.path.isfile(options.our_config_file):
            raise ValueError("Could not find specified file: %r" % options.our_config_file)

...

This has the desired effect of aborting flake8 early, but with an ugly traceback.

Is there an expected approach I have overlooked, or would documenting this with a try/except in flake8 be preferred?

I think the change would be in the provide_options method here:

https://gitlab.com/pycqa/flake8/blob/3.7.8/src/flake8/plugins/manager.py#L186

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/flake8/plugins/manager.py at the provide_options method referenced by the issue, and trace how plugin parse_options exceptions reach the command-line interface. Determine the existing error-handling path before deciding how configuration failures should be reported. Done means an invalid plugin configuration aborts flake8 early without an ugly traceback.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.