Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pylint and pre-commit hook unable to import

My project structure looks like this:

project/
   app/
      main.py
   venv/
   .pylintrc
   .pre-commit-config.yaml

When I am trying to edit project/app/main.py and it fails with

Unable to import 'psycopg2' (import-error)

But when I am trying to pylint this file directly, it works.

.pre-commit-config.yaml looks like this:

-   repo: https://github.com/PyCQA/pylint
    rev: pylint-2.4.2
    hooks:
    -   id: pylint
like image 288
palkan Avatar asked Apr 15 '20 20:04

palkan


1 Answers

not sure if this made it into pylint proper but there's a disclaimer on the bottom of pre-commit/mirrors-pylint

pre-commit runs pylint from an isolated virtualenv. Many of pylint's checks perform dynamic analysis which will fail there. You may find configuring pylint as a local hook more useful.

if you have very few dependencies, additional_dependencies might be enough to make it work, but using local hooks for things which need to (~essentially) import your code is probably your best bet


disclaimer: I'm the author of pre-commit

like image 63
Anthony Sottile Avatar answered Nov 10 '22 16:11

Anthony Sottile