1

I'm setting up a project with Python 3.8.5 (in Visual Studio Code), pre-commit and pylint. In the project pylint is reporting on PyQt5 module imports since they are C based.

To not make Pylint report on this, the .pylintrc file can be configured with extension-pkg-whitelist=PyQt5. This works fine in the IDE. Additionally, I set up pre-commit with pylint like this, but pylint seems to ignore the value PyQt5 since pre-commit still reports on the import errors for pyqt5

  - repo: https://github.com/PyCQA/pylint
    rev: pylint-2.5.0
    hooks:
      - id: pylint
        args: [--extension-pkg-whitelist=PyQt5]

Main\main.py:1:0: E0401: Unable to import 'PyQt5.QtWidgets' (import-error)

Args reference from offical docs

Pylint does still accept parameters since e.g. passing --errors-only does work. Invoking pylint with these exact parameters in the cli works as expected: it doesn't report on PyQt5, but invoking through pre-commit doesn't seem to work. I know the argument is noticed since omitting the "PyQt5" as a value result in an error stating that an argument is missing. So somehow the value gets parsed differently than in the cli.

I tried the format given above, this format here, I tried splitting the args like this args: [--extension-pkg-whitelist, PyQt5], I tried adding single/double quotes. It doesn't seem to pick it up.

How do you pass args to the hook that require a key and value?

Thanks in advance

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
timv
  • 11
  • 1
  • 2
  • 2
    I'd suggest reading [the suggestions about using pylint with pre-commit](https://github.com/pre-commit/pre-commit-hooks/issues/157) -- might help you with the configuration aspect. pylint itself does _dynamic_ analysis and so pre-commit's isolated virtualenvs aren't always a good fit for it (some of its checks are static and are fine, but when pylint tries to follow imports you'll have a bad time!) (disclaimer: author of pre-commit) – anthony sottile Aug 16 '20 at 19:36
  • Does this answer your question? [pylint and pre-commit hook unable to import](https://stackoverflow.com/questions/61238318/pylint-and-pre-commit-hook-unable-to-import) – anthony sottile Sep 28 '21 at 14:41

1 Answers1

-1

I had a similar problem with the pydantic library. I had to add the library as a dependency:

-   repo: https://github.com/pycqa/pylint
    rev: v2.9.6
    hooks:
    - id: pylint
      additional_dependencies:
        - 'pydantic'
      args:
        ["--extension-pkg-whitelist=pydantic"]