'use strict' const path = require('path') /** * Python 可执行文件路径:只认根目录 config.js 的导出(pythonExePath / pythonDir / pythonPath.path)。 * 禁止在业务代码里拼接 python/x64、venv、py/python.exe 等路径。 * * @param {object} config - require(项目根/config.js) 的结果 * @returns {string} */ function getPythonExeFromConfig (config) { if (!config || typeof config !== 'object') return 'python' const explicit = config.pythonExePath != null && String(config.pythonExePath).trim() if (explicit) { const p = String(config.pythonExePath).trim() return path.isAbsolute(p) ? p : path.join(config.projectRoot || '', p) } const dir = config.pythonDir || (config.pythonPath && config.pythonPath.path) if (!dir) return 'python' const base = path.isAbsolute(dir) ? dir : path.join(config.projectRoot || '', dir) return path.join(base, process.platform === 'win32' ? 'python.exe' : 'python') } module.exports = { getPythonExeFromConfig }