4

Looking to find a way, if possible, to disable specific PEP8 warnings for a Python project loaded in PyCharm at the repository level (i.e. saving a repository-committed configuration file which can apply PEP8 configuration hints to any user loading a project in PyCharm).


In a situation where other developers may contribute to a project using PyCharm. I personally do not use PyCharm myself (just a text editor) and building/linting is performed through various tox environments. There are select PEP8 rules that I am particularly not fond of, such as the promotion on injecting two blank lines in specific areas of the code (e.g. E305). While linters can be configured to ignore specific PEP8 rules and developers can invoke a command (like tox) with the same linter configuration, developers using PyCharm will still see these warnings in their environment. For example:

PyCharm show E305 warning

The problem I experience is developers will make (undesired) adjustments to the implementation and submit them for changes in pull requests. While developers can dismiss warnings themselves, I do not want developers to have to assume/interpret which PEP8 rules the project follows (aside from what may be mentioned in a CONTRIBUTING document). In addition, while source files can be modified with a # noqa comment to hint to the IDE to ignore an issue on that line, I am looking for an alternative way to ignore specific PEP8 rules without peppering various # noqa hints throughout the implementation.

For example, looking for a way to disable all E305 warnings in a theoretical .pycharm file such as follows:

[pycharm]
ignore = E305
jdknight
  • 1,801
  • 32
  • 52
  • Maybe [this](https://www.jetbrains.com/help/pycharm/sharing-your-ide-settings.html) could be an option? – Olvin Roght Sep 20 '20 at 19:27
  • @OlvinRoght, thanks for the hint. However, it seems like that capability requires having a user configure their IDE. That would work for companies/groups trying to synchronize settings; but the use case I have, the repository and prospect PyCharm users not independent parties. – jdknight Sep 26 '20 at 19:51
  • How about finding the pycodestyle file that comes bundled with PyCharm and editing it? With the right macro you can switch the file with a keystroke, it's a hack and not ideal but it would get the job done. What's the path to the config file in the IDE installation? – bad_coder May 07 '22 at 20:11

2 Answers2

4

After some additional investigation, there does not appear to be support (as of 2020-09-23; v2020.2) for repository-specific PEP8 warning customization.

The IDE uses pycodestyle for PEP8 processing. Testing out options from pycodestyle's configuration has shown that user-specific configurations will disable various PEP8 hints in the IDE; however, the goal is avoid having the user to configure anything in this case. While pycodestyle indicates that it will also look at setup.cfg and tox.ini, the IDE does not invoke pycodestyle in a way to use them. Examining how the IDE invokes pycodestyle shows that it will feed a source's contents through stdin for information. pycodestyle only implicitly loads supported project-specific configurations (i.e. setup.cfg or tox.ini) based on a common prefix of provided input files (if provided) on the existing working directory pycodestyle is invoked on -- unfortunately, since PyCharm does not change the working directory when invoking pycodestyle to a project's root, project-specific configurations cannot be implicitly loaded.

An issue has been created on their issue tracker:

PY-44684 | support pycodestyle project-specific configuration settings (pep8) https://youtrack.jetbrains.com/issue/PY-44684

jdknight
  • 1,801
  • 32
  • 52
1

There is way to do it, but at the moment it requires the corresponding PyCharm's project settings to be kept in VCS. For every reported pycodestyle.py error there is a dedicated quick fix "Ignore errors like this" that includes the respective error code in the settings of "PEP 8 coding style violation" inspection (these codes are then passed directly to pycodestyle.py via its --ignore option).

Ignore errors like this quickfix

You can then find and edit these codes in the inspection settings.

Inspection settings

If a per-project inspection profile was configured, these settings are saved in .idea/inspectionProfiles/Your_Profile_Name.xml and this way can be shared with the team or external contributors.

Obviously, it won't work if you don't want to expose IDE-specific config files in the repository, especially when there is a better, tool-independent place for such preferences. The reported PY-44684 is a legitimate issue, I agree.

east825
  • 909
  • 1
  • 8
  • 20