fix(terminal): 移除命令执行前的 python/pip 路径重写,按用户原始命令执行
run_command 与后台 run_command 此前会把命令中的 python/python3/pip/pip3 正则替换为解析出的容器或本地解释器路径,删除该重写逻辑后命令按原样执行。
This commit is contained in:
parent
0dd51c7b48
commit
bfc039a9a9
@ -3,7 +3,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import signal
|
||||
import subprocess
|
||||
@ -61,14 +60,7 @@ class BackgroundCommandManager:
|
||||
if not getattr(terminal_ops, "container_session", None):
|
||||
session_override = terminal_ops._resolve_active_container_session()
|
||||
|
||||
execution_in_container = terminal_ops._will_use_container(session_override)
|
||||
python_rewrite = terminal_ops.container_python_cmd if execution_in_container else terminal_ops.python_cmd
|
||||
pip_rewrite = terminal_ops._derive_pip_from_python(python_rewrite)
|
||||
final_command = command
|
||||
if re.search(r"\bpython3?\b", final_command):
|
||||
final_command = re.sub(r"\bpython3?\b", python_rewrite, final_command)
|
||||
if re.search(r"(?<![/.\w-])pip3?\b", final_command):
|
||||
final_command = re.sub(r"(?<![/.\w-])pip3?\b", pip_rewrite, final_command)
|
||||
|
||||
valid, error = terminal_ops._validate_command(final_command)
|
||||
if not valid:
|
||||
|
||||
@ -7,7 +7,6 @@ import subprocess
|
||||
import shutil
|
||||
import time
|
||||
import signal
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Dict, Optional, Tuple, TYPE_CHECKING
|
||||
from types import SimpleNamespace
|
||||
@ -410,20 +409,6 @@ class RunMixin:
|
||||
session_override = None
|
||||
if not self.container_session:
|
||||
session_override = self._resolve_active_container_session()
|
||||
# 判断本次应在容器中执行:已绑定容器会话、复用终端容器或将使用工具箱容器
|
||||
execution_in_container = self._will_use_container(session_override)
|
||||
python_rewrite = self.container_python_cmd if execution_in_container else self.python_cmd
|
||||
pip_rewrite = self._derive_pip_from_python(python_rewrite)
|
||||
# 命令通过 ssh 在远程主机执行时,本地 Python/pip 路径对远程不适用,跳过重写
|
||||
is_remote_ssh = command.lstrip().startswith("ssh ") or re.search(r"[;&|]\s*ssh\s", command) is not None
|
||||
if not is_remote_ssh:
|
||||
# 统一替换 python/python3,为保障虚拟环境命中只替换独立单词
|
||||
if re.search(r"\bpython3?\b", command):
|
||||
command = re.sub(r"\bpython3?\b", python_rewrite, command)
|
||||
# 同步替换 pip/pip3,确保指向同一环境
|
||||
if re.search(r"(?<![/.\w-])pip3?\b", command):
|
||||
command = re.sub(r"(?<![/.\w-])pip3?\b", pip_rewrite, command)
|
||||
|
||||
# 验证命令
|
||||
valid, error = self._validate_command(command)
|
||||
if not valid:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user