0

I'm developing a python project, using PyCharm on Windows, and running it on a Raspberry Pi. I'm a heavy user of PyCharm inspections and also use Pylint as part of my integration tests. In addition, I have 2 different requirements.txt: dev and prod.

There is a linux only library I'm using (picamera), and it can't be install in my development environment. PyCharm will alert me that the package isn't installed, and that it isn't in the requierment.txt file, and Pylint will alert on import-error.

Now I need this in my code:

from sys import platform
if platform == "linux":
  # noinspection PyUnresolvedReferences,PyPackageRequirements
  # pylint: disable=import-error
  from picamera import PiCamera

And I find it ugly. I saw here (Suppress warning for both pycharm and pylint) that there is no way to merge those comments, but it made me think that maybe there is a better best practice for that scenario? It feels like it shouldn't be that rare...

Na ama
  • 1
  • You can disable the error globally? https://stackoverflow.com/q/23201968/5767109 – yogupta May 25 '20 at 06:37
  • Not a Python or PyCharm user and cannot say about Pylint (how does it work) .. but please check the actual Pylint: it may have scopes or whitelist/blacklist functionality where you may be able to have different rules for different files/folders (for example: if it sees a pylint config file in the same folder, it will take it instead of the global one; or it may have different sections in one config...) – LazyOne May 25 '20 at 08:43
  • Same idea with PyCharm: inspections can be configured (enabled/disabled) based on a Scope (file/folder based) so you can have it enabled everywhere except those few selected files/folders. That is configured in IDE settings so no `#noinspection` comments in a file. This is, of course, applies to the whole file (which assumes that such platform specific code is in a separate file(s)). – LazyOne May 25 '20 at 08:44

0 Answers0