Skip to content
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

Prefer interpreter's Ruff to environment's Ruff #83

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,31 +794,30 @@ def _executable_path(settings: dict[str, Any]) -> str:
)

path = os.path.join(INTERPRETER_PATHS[settings["interpreter"][0]], TOOL_MODULE)
if bundle and not os.path.exists(path):
log_to_output(
f"External interpreter executable ({path}) not found; "
f"falling back to bundled executable: {bundle}"
)
path = bundle
else:
log_to_output(f"Using external interpreter executable: {path}")
else:
path = os.path.join(sysconfig.get_path("scripts"), TOOL_MODULE)

# First choice: the executable in the current interpreter's scripts directory.
if os.path.exists(path):
log_to_output(f"Using interpreter executable: {path}")
return path

# If the interpreter is same as the interpreter running this process, get the
# script path directly.
path = os.path.join(sysconfig.get_path("scripts"), TOOL_MODULE)
# Second choice: the executable in the global environment.
environment_path = shutil.which("ruff")
if environment_path:
log_to_output(f"Using environment executable: {environment_path}")
path = environment_path
elif bundle and not os.path.exists(path):
return environment_path

# Third choice: bundled executable.
if bundle:
log_to_output(
f"Interpreter executable ({path}) not found; "
f"falling back to bundled executable: {bundle}"
)
path = bundle
else:
log_to_output(f"Using interpreter executable: {path}")
return bundle

# Last choice: just return the expected path for the current interpreter.
log_to_output(f"Unable to find interpreter executable: {path}")
return path


Expand Down