import { existsSync } from "node:fs";
import { join } from "node:path";
import { getConfig } from "./config.js";
import { binaryInPath } from "./cli/tui/detect-helpers.js";
function venvBinPath(dataDir, name, platform = process.platform) {
  if (platform === "win32") {
    return join(dataDir, "searxng", "venv", "Scripts", `${name}.exe`);
  }
  return join(dataDir, "searxng", "venv", "bin", name);
}
let _resolvedPythonExe = null;
function resolvePythonExe() {
  if (_resolvedPythonExe !== null) return _resolvedPythonExe;
  if (binaryInPath("python3") !== null) return _resolvedPythonExe = "python3";
  if (binaryInPath("python") !== null) return _resolvedPythonExe = "python";
  return _resolvedPythonExe = "python3";
}
function __resetResolvedPythonExe() {
  _resolvedPythonExe = null;
}
function getPythonBin(dataDir) {
  const dir = dataDir ?? getConfig().dataDir;
  if (!dir) return "python3";
  const venvPython = venvBinPath(dir, "python");
  return existsSync(venvPython) ? venvPython : "python3";
}
export {
  __resetResolvedPythonExe,
  getPythonBin,
  resolvePythonExe,
  venvBinPath
};
//# sourceMappingURL=python-env.js.map