Skip to content

Use pylint config parser for pyproject.toml and setup.cfg support#14

Open
kevinoid wants to merge 4 commits into
MasterOdin:masterfrom
kevinoid:use-pylinter-config-parser
Open

Use pylint config parser for pyproject.toml and setup.cfg support#14
kevinoid wants to merge 4 commits into
MasterOdin:masterfrom
kevinoid:use-pylinter-config-parser

Conversation

@kevinoid
Copy link
Copy Markdown

Pylint 2.5.0 and later support reading configuration from pyproject.toml or setup.cfg if pylintrc and .pylintrc do not exist. (pylint-dev/pylint#3169) In order to support these configuration files, this PR changes pylint_runner to use pylint.lint.pylinter.PyLinter#read_config_file() instead of configparser.ConfigParser#read() to read the pylint configuration.

It also adds a check to avoid configparser.NoOptionError if ignore is not configured and to strip whitespace from ignore values as pylint does. If you would prefer these to be moved to a separate PR, let me know.

Thanks,
Kevin

@kevinoid
Copy link
Copy Markdown
Author

For reference, the test failures don't appear to be related to this PR (since it doesn't change setup.py or tests/test_runner.py which are causing the pylint check to fail). I'd be happy to rebase this PR once those issues are fixed.

@MasterOdin MasterOdin force-pushed the master branch 4 times, most recently from 833123c to 360b261 Compare August 26, 2021 04:17
@MasterOdin
Copy link
Copy Markdown
Owner

Sorry about that @kevinoid. Master has been fixed and tests are passing once again.

@kevinoid kevinoid force-pushed the use-pylinter-config-parser branch from 11115e5 to 8431ded Compare August 26, 2021 10:22
Copy `Runner.DEFAULT_ARGS` to `self.args` so that if/when `self.args` is
modified it will not affect `Runner.DEFAULT_ARGS`.

Fix the tests as a result of the change:
1. Increase `max-line-length` in `tests/tests/good_rc_file` so that when
   it is used in `test_rcparser_success` the lint succeeds.
2. Fix `expected` in `test_passthrough_args` to not expect args to have
   been modified by previous tests.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Pylint 2.5.0 and later support reading configuration from
`pyproject.toml` or `setup.cfg` if `pylintrc` and `.pylintrc` do not
exist.  (pylint-dev/pylint#3169)  In order to support these configuration
files, use `pylint.lint.pylinter.PyLinter#read_config_file()` instead of
`configparser.ConfigParser#read()` to read the pylint configuration.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
If the `ignore` option is not configured, pylint_runner dies with:

    configparser.NoOptionError: No option 'ignore' in section: 'MASTER'

Avoid this by checking that the option is present using `#has_option()`
before `#get()`.  (Note: It is not necessary to check that the `MASTER`
section exists, since `#has_option()` returns `False` in that case.)

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
`pylint.lint.pylinter.PyLinter#set_option()` ultimately calls
`pylint.utils.utils._splitstrip()` to parse options of type `csv`, such
as `ignore`.  In addition to removing empty values, `_splitstrip()`
strips whitespace from values.  Update `ignore` parsing to behave the
same as pylint.

Note: Since `_splitstrip()` is private and has a simple implementation,
it is inlined here.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
@kevinoid kevinoid force-pushed the use-pylinter-config-parser branch from 8431ded to 7bcd439 Compare August 26, 2021 11:18
@kevinoid
Copy link
Copy Markdown
Author

No worries. Thanks for the quick fix @MasterOdin! It should pass the CI tests now.

I added an additional commit to avoid modifying Runner.DEFAULT_ARGS (4cb3cee) which was causing the changes to fail the test unnecessarily. If you'd like to consider that as a separate PR first, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants