Using pyproject.toml to define inspection rules of PyCharm

265 Views Asked by At

I use PyCharm and have a pyproject.toml, currently configured for flake8.

Can I make PyCharm use the ignore list for its own inspections too?

My pyproject.toml:

[tool.flake8]
ignore = [
   "I101",  # Imported names are in the wrong order
   "I201",  # Missing newline between import groups
]

I am not looking for a suggestion to configure flake8 as external tool in PyCharm, I am looking to alter/configure the live inspection of PyCharm, as shown e.g. its Problems tab.

2

There are 2 best solutions below

5
On

I believe PyCharm's native inspections and flake8 inspections are different, and PyCharm does not natively support importing flake8 configurations directly into its own inspection settings.

As a workaround, you can try and manually configure PyCharm's inspections to mirror the ignore list in pyproject.toml. Go to File > Settings > Editor > Inspections in PyCharm, and adjust the inspection settings to reflect the rules you want to ignore, as specified in your pyproject.toml.

Since PyCharm's inspections are not directly compatible with flake8, some rules might not have a one-to-one correspondence, and this process might involve some approximation.

If you often change your flake8 settings and want a more automated way to keep PyCharm in sync, consider writing a custom script or a PyCharm plugin that reads your pyproject.toml and adjusts PyCharm's inspection settings accordingly.

0
On

Can I make PyCharm use the ignore list for its own inspections too?

The way JetBrains offers to integrate 3rd party tool inspection functionalities into PyCharm is by using their Qodana tool.

This is still separate from the PyCharm linter per se. PyCharm's linter integrates PEP8, with some Flake8 checks and other niceties like spellchecking and refactoring suggestions but it's never been a complete substitute for popular 3rd party code-quality tools (like mypy, Flake8 or python-black) and PyCharm keeps it's own configuration files that are proprietary and not meant to be compatible with pyproject.toml settings.

At the time of this writing you shouldn't expect complete integration of 3rd party tools with the native PyCharm linter warning system and instead consider the PyCharm linter as its own separate tool geared towards giving you some limited assistance while writing the code.

There have been very few attempts at publishing Flake8 integration plugins for PyCharm, there are for example Flake8 support and flake8-for-pycharm but these plugins seem to have been limited and abandoned in the meanwhile.