-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep Python script limited to sysconfig
usage
#511
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thank you!
9173f37
to
0043fcc
Compare
src/common/server.ts
Outdated
try { | ||
const stdout = await executeCommand( | ||
`${settings.interpreter[0]} ${FIND_RUFF_BINARY_SCRIPT_PATH}`, | ||
); | ||
ruffBinaryPath = stdout.trim(); | ||
} catch (err) { | ||
traceError(`Error while trying to find the Ruff binary: ${err}`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit torn on whether we should notify the user or not. The script itself doesn't raise any error so the failure should come from any external means. If it does, we'll log the failure and continue ahead by checking the PATH
variable and falling back to using the bundled executable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems fine to notify if the error seems rare and indicative of an unexpected situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
traceError(`Error while trying to find the Ruff binary: ${err}`); | ||
} | ||
|
||
if (ruffBinaryPath && ruffBinaryPath.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (ruffBinaryPath && ruffBinaryPath.length > 0) { | |
if (ruffBinaryPath?.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it's giving me:
typescript: 'ruffBinaryPath.length' is possibly 'undefined'. [18048]
I'm going to leave it as is for now
bundled/tool/ruff_server.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably a dumb question and I think I saw a related PR today.
Are we now checking the ruff version in the typescript code for both the native and legacy LSP?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We check whether the Ruff executable we found supports the native server (ruff server
) by looking at the version. This is removed here from the Python script and added in TypeScript in #512. I'm not sure what you mean by "version check in legacy LSP"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where / when do we validate the Ruff version?
0043fcc
to
90d4358
Compare
I'm assuming you mean by the validation for the native server which is in #512 in TypeScript code. |
## Summary This PR adds back the message to suggest the user that the current Ruff binary doesn't support the native server. This was removed from the Python script in #511. fixes: #476 ## Test Plan Install an older Ruff version to test this out using `pipx install --force "ruff==0.3.3"`. <img width="1432" alt="Screenshot 2024-07-03 at 14 50 41" src="https://github.com/astral-sh/ruff-vscode/assets/67177269/267e2bab-e050-4cdf-98ff-fb140b7d63ee"> And, we've another log message which displays the Ruff version similar to `ruff-lsp`: ``` 2024-07-03 16:00:03.089 [info] Using the Ruff binary: /Users/dhruv/work/astral/ruff-lsp/.venv/bin/ruff 2024-07-03 16:00:03.094 [info] Found Ruff 0.4.10 at /Users/dhruv/work/astral/ruff-lsp/.venv/bin/ruff 2024-07-03 16:00:03.095 [info] Server run command: /Users/dhruv/work/astral/ruff-lsp/.venv/bin/ruff server --preview ```
Summary
This PR makes progress towards #476 and #479 by making the following changes:
ruff_server.py
script to limit itself to just getting the Ruff binary path usingsysconfig
which
dependency and move the logic of locating the Ruff binary fromPATH
to TypeScriptruff-lsp
Test Plan
1
Or
Logs:
When the
ruff
binary is installed in the current virtual environment:If there's no
ruff
binary in the current virtual environment:If the
ruff
binary is only available viaPATH
:And, if there's no
ruff
binary anywhere on the system, use the bundled binary:2
Logs:
3
Logs:
4
Logs:
5
What if the script failed? I modified the script path in TypeScript code and we get the following logs: