Skip to content

Commit

Permalink
fix: Conda venv is not used
Browse files Browse the repository at this point in the history
sublimelsp/LSP-pyright#348

Signed-off-by: Jun-Fei Cherng <jfcherng@realtek.com>
  • Loading branch information
jfcherng committed Aug 12, 2024
1 parent 5b6a278 commit 9f0f978
Show file tree
Hide file tree
Showing 7 changed files with 545 additions and 428 deletions.
7 changes: 4 additions & 3 deletions plugin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from .constants import PACKAGE_NAME
from .log import log_info, log_warning
from .template import load_string_template
from .venv_finder import VenvInfo, find_venv_by_finder_names, get_finder_name_mapping
from .virtual_env.helpers import find_venv_by_finder_names, find_venv_by_python_executable
from .virtual_env.venv_finder import BaseVenvInfo, get_finder_name_mapping

WindowId = int

Expand All @@ -30,7 +31,7 @@
class WindowAttr:
simple_python_executable: Path | None = None
"""The path to the Python executable found by the `PATH` env variable."""
venv_info: VenvInfo | None = None
venv_info: BaseVenvInfo | None = None
"""The information of the virtual environment."""

@property
Expand Down Expand Up @@ -274,7 +275,7 @@ def _update_venv_info() -> None:
window_attr.venv_info = None

if python_path := settings.get("python.pythonPath"):
window_attr.venv_info = VenvInfo.from_python_executable(python_path)
window_attr.venv_info = find_venv_by_python_executable(python_path)
return

supported_finder_names = tuple(get_finder_name_mapping().keys())
Expand Down
25 changes: 25 additions & 0 deletions plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import subprocess
import sys
from collections.abc import Generator, Iterable
from pathlib import Path
from typing import Any, TypeVar

from .log import log_error

_T = TypeVar("_T")


Expand Down Expand Up @@ -55,3 +58,25 @@ def get_default_startupinfo() -> Any:
STARTUPINFO.wShowWindow = subprocess.SW_HIDE # type: ignore
return STARTUPINFO
return None


def run_shell_command(command: str, *, cwd: str | Path | None = None) -> tuple[str, str, int] | None:
try:
proc = subprocess.Popen(
command,
cwd=cwd,
shell=True,
startupinfo=get_default_startupinfo(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
stdout, stderr = map(str.rstrip, proc.communicate())
except Exception as e:
log_error(f"Failed running command ({command}): {e}")
return None

if stderr:
log_error(f"Failed running command ({command}): {stderr}")

return stdout, stderr, proc.returncode or 0
Loading

0 comments on commit 9f0f978

Please sign in to comment.