Skip to content

Commit

Permalink
fix: local venv is not used under some circumstances
Browse files Browse the repository at this point in the history
E.g.,

1. There is an ".python-version" file but no "pyenv" is installed.
2. "pyenv which python" will raises an exception.
3. `python_path` is an empty string and `None` is returned.

But actually we want to test all direct subdirs later and shouldn't
return `None` here.

Signed-off-by: Jun-Fei Cherng <jfcherng@realtek.com>
  • Loading branch information
jfcherng committed Jun 5, 2024
1 parent bbe0291 commit bd77fef
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,25 @@ def binary_from_python_path(path: str | Path) -> Path | None:
continue
print(f"{cls.name()}: INFO: {config_file} detected. Run subprocess command: {command}")
try:
stdout, stderr = subprocess.Popen(
command,
cwd=workspace_folder,
shell=True,
startupinfo=get_default_startupinfo(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
).communicate()
stdout, stderr = map(
str.rstrip,
subprocess.Popen(
command,
cwd=workspace_folder,
shell=True,
startupinfo=get_default_startupinfo(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
).communicate(),
)
if stderr:
print(f"{cls.name()}: INFO: subprocess stderr: {stderr.strip()}")
python_path = stdout.strip()
print(f"{cls.name()}: INFO: subprocess stderr: {stderr}")
python_path = stdout
if post_processing:
python_path = post_processing(python_path)
return Path(python_path) if python_path else None
if python_path:
return Path(python_path)
except FileNotFoundError:
print(f"{cls.name()}: WARN: subprocess failed with file not found: {command[0]}")
except PermissionError as e:
Expand Down

0 comments on commit bd77fef

Please sign in to comment.