UNPKG

alwaysai

Version:

The alwaysAI command-line interface (CLI)

80 lines 3.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.installPythonReqs = exports.createPythonVenv = exports.getPythonVenvPaths = void 0; const path_1 = require("path"); const os_1 = require("os"); const paths_1 = require("../../paths"); const environment_1 = require("../../environment"); async function getPythonVenvPaths(props) { const { targetCfg } = props; switch (targetCfg.targetProtocol) { case 'native:': { if (environment_1.ALWAYSAI_OS_PLATFORM === 'win32') { return { pythonExe: (0, path_1.join)((0, os_1.homedir)(), '.alwaysai', 'python', 'python.exe'), pythonVenvExe: (0, path_1.join)(paths_1.VENV, 'Scripts', 'python.exe'), activatePath: paths_1.VENV_SCRIPTS_ACTIVATE }; } return { pythonExe: (0, path_1.join)((0, os_1.homedir)(), '.alwaysai', 'python', 'bin', 'python3'), pythonVenvExe: (0, path_1.join)(paths_1.VENV, 'bin', 'python'), activatePath: paths_1.VENV_BIN_ACTIVATE }; } case 'docker:': case 'ssh+docker:': { return { pythonExe: targetCfg.targetHardware.includes('jetson') ? 'python3' : 'python', pythonVenvExe: path_1.posix.join(paths_1.VENV, 'bin', 'python'), activatePath: paths_1.VENV_BIN_ACTIVATE }; } default: throw new Error(`Invalid target protocol!`); } } exports.getPythonVenvPaths = getPythonVenvPaths; async function createPythonVenv(props) { const { targetSpawner, pythonVenvPaths, logger } = props; if (await targetSpawner.exists(pythonVenvPaths.activatePath)) { return false; } logger.debug(await targetSpawner.run({ exe: pythonVenvPaths.pythonExe, args: ['-m', paths_1.VENV, '--system-site-packages', paths_1.VENV], cwd: '.' })); // Update pip and setuptools from the default version provided by venv logger.debug(await targetSpawner.run({ exe: pythonVenvPaths.pythonVenvExe, args: ['-m', 'pip', 'install', '--upgrade', 'pip', 'setuptools'], cwd: '.' })); return true; } exports.createPythonVenv = createPythonVenv; async function installPythonReqs(props) { const { reqFilePath, targetSpawner, pythonVenvPaths, logger } = props; logger.debug(await targetSpawner.run({ exe: pythonVenvPaths.pythonVenvExe, args: ['-m', 'pip', 'install', '--requirement', reqFilePath] })); // uninstall conflicting packages that may have been installed logger.debug(await targetSpawner.run({ exe: pythonVenvPaths.pythonVenvExe, args: [ '-m', 'pip', 'uninstall', '-y', 'opencv-python', 'opencv-python-headless', 'opencv-contrib-python-headless' ] })); } exports.installPythonReqs = installPythonReqs; //# sourceMappingURL=app-install-venv.js.map