fnando / vscode-linter

Extension for code linting, all in one package. New linters can be easily added through an extension framework.
https://marketplace.visualstudio.com/items?itemName=fnando.linter
MIT License
63 stars 16 forks source link

Add support for venv #25

Open Aplietexe opened 1 year ago

Aplietexe commented 1 year ago

Currently, linters such as yamllint that are installed using Python require them to be installed globally. When they are installed in a venv, they work normally, but aren't seen by the linter extension.

Searched for any of yamllint; couldn't be found within $PATH: [
...
]

This is a problem as not only it requires polluting the $PATH, but can be hard to do in systems with multiple Python versions, where installed packages don't get added to the $PATH.

Startouf commented 1 year ago

I have the same problem with sqlfluff that I install in a venv folder using poetry. My sqlfluff executable is not available globally, and installed when I run poetry install. It can even be located outside the workspace directory but I activate

poetry config virtualenvs.in-project true

to have them in the project directory which should make things easier.

Note that the python extension picks up virtual environments Screenshot 2023-03-20 at 13 50 33

And When I open my terminal, the sqlfluff binary exists

# Command ran automatically by VS Code
source /Users/cyrilduchon-doris/dev/MyJobGlasses/dbt-transformations/.venv/bin/activate

# When I try to lookup for sqlfluff
(dbt-transformations-py3.11) which sqlfluff
/Users/me/dev/project/dbt-transformations/.venv/bin/sqlfluff

Note that the .venv could have an arbitrary name. With poetry I can run poetry env info to get the following (because I install my tools with asdf)

poetry env info

Virtualenv
Python:         3.11.2
Implementation: CPython
Path:           /Users/me/dev/project/dbt-transformations/.venv
Executable:     /Users/me/dev/project/dbt-transformations/.venv/bin/python
Valid:          True

System
Platform:   darwin
OS:         posix
Python:     3.11.2
Path:       /Users/me/.asdf/installs/python/3.11.2
Executable: /Users/me/.asdf/installs/python/3.11.2/bin/python3.11
skwde commented 1 year ago

Same issue here. At least for me, not being able to use dedicated linter environments is a nogo.

Since not all applications are possibly in the same environment I propose to use a configuration setting which prepends the PATH variable solely for use within the extension.

Something like

linter.prependPath: ["<path to bin1>", "<path to bin2>", ...]

in case linter.prependPath is empty the current behavior is used.