vscode-flake8 icon indicating copy to clipboard operation
vscode-flake8 copied to clipboard

Add `VIRTUENV_BIN` to the list of supported predefined variables to resolve linter settings

Open jnoortheen opened this issue 5 years ago • 11 comments

I am using flakehell as the runner for flake8 . I am able to configure it using

"python.linting.flake8Path": "~/.local/share/virtualenvs/proj/bin/flake8helled",

But I had to give the full path. It would be nice to have this variable to the list of predefined-variables. So it will work with different venvs and no need to change it every time.

So the above setting can be simplified like

"python.linting.flake8Path": "${VIRTUENV_BIN}/flake8helled",

jnoortheen avatar Jun 30 '20 12:06 jnoortheen

@jnoortheen Can you try "python.linting.flake8Path": "${env:VIRTUENV_BIN}/flake8helled", ? Notice the "env" prefix. Let me know if that works.

karthiknadig avatar Jul 07 '20 03:07 karthiknadig

@jnoortheen Can you try "python.linting.flake8Path": "${env:VIRTUENV_BIN}/flake8helled", ? Notice the "env" prefix. Let me know if that works.

Yes it is working if I launch it from terminal after setting the environment variable. But it would be nice to have a variable pointing to the current venv path selected from the Python extension automatically.

jnoortheen avatar Jul 07 '20 08:07 jnoortheen

That is a bit odd. Does vscode-python special-case the name "flake8" or something? Shouldn't it just look it up on the path regardless... I think I encountered a similar issue trying to configure darker for black. I didn't necessarily want it to look in the venv in that case (black only runs on Py3), but I did want it to look in the PATH, lol.

DylanYoung avatar Jul 10 '20 17:07 DylanYoung

@karthiknadig Do you need any other info?

jnoortheen avatar Jul 11 '20 15:07 jnoortheen

@jnoortheen We have all the information we need. We have marked this issue as "needs decision" to make sure we have a conversation about your idea. We plan to leave this feature request open for at least a month to see how many 👍 votes the opening comment gets to help us make our decision.

@DylanYoung Can you file a separate bug for the issue?

@karrtikr Does ${command:python.interpreterPath} work in this scenario? I don't remember if settings resolves command.

karthiknadig avatar Jul 11 '20 18:07 karthiknadig

Unfortunately no, command variables are only supported for launch.json and tasks.json file. See this.

VSCode doesn't automatically resolve command variables when we fetch settings using API, and probably can't as launching commands is an async operation but fetching settings is not. (Opened feature request https://github.com/microsoft/vscode/issues/102414 to confirm)

karrtikr avatar Jul 13 '20 18:07 karrtikr

It's not a separate issue, lol. It just doesn't look in PATH, same as this issue (since VENV should be in PATH).

DylanYoung avatar Jul 17 '20 20:07 DylanYoung

@DylanYoung There are two things. 1) Accessing a relative location based on the selected interpreter. 2) Running tools in an activated environment. In your case we should be running flake8 from an activated environment. We should not be searching PATH for flake8. Calling flake8 should run the the binary/script they have under /scripts directory. The fact that we are not running from linter from an activated environment is a separate issue.

karthiknadig avatar Jul 17 '20 20:07 karthiknadig

any update on this?

with settings: "python.linting.flake8Path": "flake8helled"

and with environment activated and the binary present in /scripts director, vscode complains saying flake8 is not installed.

codekoriko avatar Apr 05 '21 12:04 codekoriko

I have to disagree, though perhaps I'm missing something about the design. If you're skipping my path, then you don't integrate with my dev environment. I have tools that aren't part of my virtualenv that i need to access in my projects.

I think you misunderstand as well. Flake 8 (darker/black) isn't in my virtualenv. It's on my PATH.

In any case, my only point is that fixing the PATH resolution, fixes a lot of related issues. No one should have to be explicitly selecting their virtualenv to run a tool, as the venv should be the first location in PATH. The feature request here is an X Y problem.

DylanYoung avatar Apr 05 '21 17:04 DylanYoung

add VIRTUENV_BIN to the list of supported predefined variables

The premise of this issue states we support a list of predefined variables already, can you name a few we support? I could not find any. Supporting this scenario would require us to resolve VIRTUENV_BIN differently for each different workspace folder in workspace, as each folder can have its own virtual env.

Now that we've our own flake8 extension moving this over to https://github.com/microsoft/vscode-flake8 as this will needed to be supported there. Checkout the settings for that extension.

karrtikr avatar Dec 15 '22 11:12 karrtikr