Skip to content

Commit

Permalink
fix: Conda venv is not used (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfcherng authored Aug 12, 2024
1 parent c32d464 commit 5756ca1
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,14 +21,15 @@
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


@dataclass
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 @@ -272,7 +273,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 5756ca1

Please sign in to comment.