astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
946 stars 45 forks source link

Environment variables are not expanded in "ruff.path" VSCode settings #448

Open erjac77 opened 2 months ago

erjac77 commented 2 months ago

Ruff: 0.3.7 VSCode: 1.88.0 OS: Ubuntu 22.04 Python: 3.11.8

If I specify a path to a custom ruff executable containing environment variables:

"ruff.path": [
  "${workspaceFolder}/dist/export/python/virtualenvs/ruff/${env:PYTHON_VERSION}/bin/ruff"
]

I get the following error message:

Interpreter executable (/workspace/dist/export/python/virtualenvs/ruff/${env:PYTHON_VERSION}/bin/ruff) not found

Seems like predefined variables are expanded, but not the environment variables.

Related to https://github.com/astral-sh/ruff-vscode/issues/413.

Thank you.

dhruvmanila commented 2 months ago

I'm unsure where VS Code retrieves the environment variables from. Is it possible that the environment variable isn't defined in the environment where VS Code is launched? Could you try opening VS Code via the shell in which the environment variable is defined (like code .)?

dhruvmanila commented 2 months ago

Ok, that actually doesn't work either.

dhruvmanila commented 2 months ago

I looked into this a bit more and it seems that the extension only substitutes certain variables which I assume is just a side effect of inheriting from the Python extension template:

https://github.com/astral-sh/ruff-vscode/blob/332b4def4fed463cc176f6371a970245f0f612e4/src/common/settings.ts#L59-L79