Handle pyenv Windows shims

This commit is contained in:
2026-05-02 20:52:52 +09:00
parent dca5b2c9c4
commit 6a4fb067cd

View File

@@ -12,6 +12,15 @@ export interface PythonCommandSpec {
viaCmdShell?: boolean;
}
function shouldUseCmdShell(command: string): boolean {
if (process.platform !== "win32") {
return false;
}
const lower = command.toLowerCase();
return !path.isAbsolute(command) || lower.endsWith(".bat") || lower.endsWith(".cmd");
}
function splitCommand(command: string): string[] {
const parts = command.match(/(?:[^\s"]+|"[^"]*")+/g) ?? [];
return parts.map((part) => part.replace(/^"(.*)"$/, "$1"));
@@ -138,7 +147,7 @@ export async function resolveBasePythonCommand(config: AppConfig): Promise<Pytho
return {
command,
args,
viaCmdShell: process.platform === "win32" && !path.isAbsolute(command),
viaCmdShell: shouldUseCmdShell(command),
};
}
@@ -156,8 +165,11 @@ export async function resolveBasePythonCommand(config: AppConfig): Promise<Pytho
for (const candidate of candidates) {
const absolute = await resolveWindowsExecutable(candidate.command);
if (absolute && (await canRun(absolute, candidate.args))) {
return { command: absolute, args: candidate.args };
if (absolute) {
const absoluteViaCmd = shouldUseCmdShell(absolute);
if (await canRun(absolute, candidate.args, absoluteViaCmd)) {
return { command: absolute, args: candidate.args, viaCmdShell: absoluteViaCmd };
}
}
if (await canRun(candidate.command, candidate.args, true)) {
@@ -184,7 +196,7 @@ export async function resolveBasePythonCommand(config: AppConfig): Promise<Pytho
throw new Error("사용 가능한 Python 실행기를 찾지 못했습니다. `python3 --version` 또는 `python --version` 이 먼저 동작해야 합니다.");
}
export async function resolveWorkerPythonCommand(config: AppConfig): Promise<{ command: string; args: string[] }> {
export async function resolveWorkerPythonCommand(config: AppConfig): Promise<PythonCommandSpec> {
const venvPath = resolveVenvPythonPath(config);
if (await fileExists(venvPath)) {
return { command: venvPath, args: [] };