Shay
Shay

Reputation: 1499

False import errors running Pylint and MyPy from vim ALE in pipenv. -- :!pylint % works -- :!mypy % works

I have a project directory

project
    - code
        - code.py
    - tests
        - test_code.py

Things have worked in the past with virtualenv. I am now trying pipenv. I have this in my .vimrc

"python with virtualenv support
py << EOF
import os
import sys
if 'VIRTUAL_ENV' in os.environ:
    project_base_dir = os.environ['VIRTUAL_ENV']
    activate_this = os.path.join(project_base_dir, 'Scripts/activate_this.py')
    execfile(activate_this, dict(__file__=activate_this))
EOF

That seems to work. I get my virtual environment Python with :!python. I can run :!pylint and :!mypy, neither of which are installed in my global Python.

:!pylint tests\ shows no import errors, but ALE is showing import-error. A similar thing (and worse) happens with mypy. Mypy not only reports false import errors (only when run through ALE), but also misses errors that it catches through :!mypy tests\.

I'm stumped. Any ideas?

Upvotes: 0

Views: 2196

Answers (2)

Shay
Shay

Reputation: 1499

There is a setting in ALE:

let g:ale_python_pylint_change_directory=0
let g:ale_python_flake8_change_directory=0

If you do not set this, ALE will descend into project subdirectories before linting.

Upvotes: 1

w0rp
w0rp

Reputation: 686

Try using let g:ale_python_auto_pipenv = 1 if you are using pipenv for a project. If that doesn't work for you, you can set the paths to your tools with the various options in :help ale-python-options.

Upvotes: 3

Related Questions