Open ginsburgnm opened 4 years ago
As you discovered, by default ALE runs pylint
from the project root directory. From your log, it appears that ALE determined the project root to be /home/n0g/git/copacetic/libcopacetic/plugins/fleet
and running pylint
in that directory produces import errors. Is that correct?
What do you think ALE should do differently?
@ginsburgnm as @kevinoid has said this is most likely a problem with the structure of your project that makes it difficult for ALE to determine the correct root directory. You can check what root path ALE is configuring by opening a file in the project and running this command:
:echo ale#python#FindProjectRoot("")
If the output is not the correct root path for your project you can try overriding it by setting the g:ale_lsp_root
variable:
let g:ale_lsp_root = {
\ 'python': '/path/to/project/root'
\}
Note that above will set that root path as the project root of every python project you work on. Instead you can either use buffer variables instead b:ale_lsp_root
or set a function that determines and properly sets the root path for that particular project.
@kevinoid @hsanson So, I open up vim and run
echo ale#python#FindProjectRoot("")
on the __init__.py
file in the fleet directory and I get the appropriate project root /home/n0g/git/copacetic/
in the same vim instance, if I open up any other file in the fleet directory, that file assumes the project root is /home/n0g/git/copacetic/libcopacetic/plugins/fleet
So same vim instance, same directory, different results. That''s likely some wonky python thing because I opened the __init__.py
.
My error reporting is resolved by telling ALE to not change directory.
The piece that I believe to be a bug is: ALE should be able to utilize a project's pylintrc file if you disable changing directory. Just look at the current working directory that vim was opened in. Your help at least suggests that this is not the cas.
It's not a huge deal for me, as all of my projects currently use the same rc file so defaulting back to my global rc file is fine; but I can foresee a situation where someone has multiple rc files for different python projects.
Information
VIM version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 18 2020 18:29:15) Included patches: 1-1453
Operating System: Linux nginsburg-desktop 4.15.0-91-generic #92-Ubuntu SMP Fri Feb 28 11:09:48 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
What went wrong
As I filled out this bug report I kinda figured out what's wrong
Project structure
Opening a file in the
plugins
directory results in an import error in ALE. Running pylint directly against that file does not result in any errors reported Opening a file with ALE disabled, and using syntastic instead results in no errors reported So there's some logical difference between the syntastic pylint linter and the ale pylint linter.Opening a file outside of the
plugins
directory works as expectedI'm not good at vim scripts, so I'm not really sure exactly what's happening here or how to reasonably debug it. But it feels like pylint is being called from the wrong directory.
So I tried setting
let g:ale_python_pylint_change_directory = 1
explicitly but there was no difference (which I guess is expected)I then set it to
0
and it no longer reports the import error, what appears to be happening is that the pylint change directory is assuming the incorrect project root.I think this is actually a bug because in your help
This suggests ale cannot utilize the projects pylintrc file.
Also, both pylint and syntastic are able to determine the correct output for these files.
Are you having trouble configuring ALE? Try asking for help on Stack Exchange or perhaps on Reddit instead. The GitHub issue tracker should be used for reporting bugs or asking for new features.
Reproducing the bug
:ALEInfo
Called
vim libcopacetic/plugins/fleet/models/__init__.py
from vim calledALEInfo
Got this: From the output it does look like Ale is calling pylint from the wrong directory.