Closed ni-co-la closed 3 months ago
Neither does the following setting work:
"ruff.interpreter": [
"${workspaceFolder}/.venv/bin/python"
],
Thanks, will fix!
I am surprised that "${workspaceFolder}/.venv/bin/python"
doesn't work.
Can you tell me which language server are you using? Are you using the native server or ruff-lsp
i.e., have you set the ruff.nativeServer
setting?
I'm asking because there shouldn't be any change if you're using ruff-lsp
. The meaning of the setting is only changed for the native server where it's only used to find out the ruff
binary.
If it's the native server then I think it might be related to https://github.com/astral-sh/ruff-vscode/commit/e1777e138865453199626bb51cc6b2842e16360c or https://github.com/astral-sh/ruff-vscode/commit/564a37a0128cf8e55b79e260bb12f74d470eeb0d because earlier we would just pass the interpreter path as ServerOptions
to create the LanguageClient
in VS Code, as is still being done for ruff-lsp
:
We have to expand settings.interpreter[0]
.
I am surprised that "${workspaceFolder}/.venv/bin/python" doesn't work.
Me too. I expected that this should not make a difference for ruff, if I enter the absolute path or if I use the ${workspaceFolder}.
Can you tell me which language server are you using? Are you using the native server or ruff-lsp i.e., have you set the ruff.nativeServer setting?
ruff.nativeServer
is not set.
For the VS Code extension I have the following settings:
"ruff.importStrategy": "fromEnvironment",
"ruff.path": [
"${workspaceFolder}/.venv/bin/ruff"
],
"ruff.lint.args": [
"--config=${workspaceFolder}/config/ruff.toml"
],
"ruff.format.args": [
"--config=${workspaceFolder}/config/ruff.toml"
],
I think I see at least the non-expansion issue.
@dhruvmanila - Do you want to take it? getInterpreterFromSetting
just calls config.get<string[]>("interpreter")
, but we need to run resolveVariables
on it like we do in getWorkspaceSettings
.
Yeah, I can take it on.
Thanks. We probably need to expand relative paths too before passing to execFile
.
I think there might be a bigger issue here. We do resolve the variables but only when it's a workspace setting:
And, we don't resolve any variables for the global settings:
Which, I guess, makes sense because it's not tied to any specific workspace.
Black doesn't seem to be resolving the variables from global settings either:
Ok, I can reproduce this, let me check what's actually going on.
I found the problem, it's bug I introduced in https://github.com/astral-sh/ruff-vscode/commit/4b03f7c4266a8b6d2f0047c7fbe231ec0cd408a4
Hi @ni-co-la, can you try out the pre-release version which contains the bug fix. You can go to the Ruff extension page and click on "Switch to Pre-Release Version":
I just tested it with the pre-release version and it is working fine with "ruff.interpreter": [ "${workspaceFolder}/.venv/bin/python" ]
.
"ruff.interpreter": [ "./.venv/bin/python" ]
is still not working, which was working in a previous version.
Which is fine for me, as it is more explicit to use the ${workspaceFolder}
.
Thanks a lot for the fix.
Thanks for testing it!
"ruff.interpreter": [ "./.venv/bin/python" ]
is still not working, which was working in a previous version.
Yes, I explicitly decided not to support this. It wasn't working before either, and you'll probably get the same log messages as in the PR description for earlier versions. It's just that a recent change (https://github.com/astral-sh/ruff-vscode/commit/e665ec7be83b72f7586b30387cd87c8faf62b9e1) made it explicitly visible by removing an unintended fall back mechanism.
I'll make a stable release later today.
With the latest version of the VS Code extension (v2024.34.0 and v2024.32.0), relative paths for "ruff.interpreter" are no longer accepted (in .vscode/settings.json).
In our repository, this settings file is shared between for all developers and it points to the venv Python installation inside the repository. For example:
This was working just fine in previous versions and is still working fine with other extension like pylint and flake8.
Output:
Setup: