import { existsSync } from 'node:fs'; import path from 'node:path'; /** * Python used by the local dev-server tools (ground engine, quantity workbook, DWG export). * Order: Windows venv → POSIX venv (WSL/Linux) → PIERZAINER_PYTHON → python3/python on PATH. */ export function resolvePython(root:string,platform:NodeJS.Platform=process.platform,exists:(file:string)=>boolean=existsSync,env:NodeJS.ProcessEnv=process.env):string{ const venv=path.join(root,'pierzainer_ground','.venv'); const candidates=platform==='win32'?[path.join(venv,'Scripts','python.exe')]:[path.join(venv,'bin','python'),path.join(venv,'Scripts','python.exe')]; const found=candidates.find(file=>exists(file));if(found)return found; if(env.PIERZAINER_PYTHON)return env.PIERZAINER_PYTHON; return platform==='win32'?'python':'python3'; } /** Human-readable reason for a failed spawn (ENOENT otherwise shows only "spawn python ENOENT"). */ export function describeSpawnError(error:NodeJS.ErrnoException,python:string):string{ if(error.code==='ENOENT')return `Python 실행 파일을 찾지 못했습니다(${python}). pierzainer_ground/.venv를 만들고 requirements.txt를 설치하거나 PIERZAINER_PYTHON을 지정하세요.`; return error.message; }