UNPKG

@vercel/fun

Version:

Local Lambda development environment

31 lines 1.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.generatePythonTarballUrl = generatePythonTarballUrl; exports.installPython = installPython; const tar_1 = require("tar"); const node_fetch_1 = __importDefault(require("node-fetch")); const debug_1 = __importDefault(require("debug")); const node_zlib_1 = require("node:zlib"); const promises_1 = require("node:stream/promises"); const debug = (0, debug_1.default)('@vercel/fun:install-python'); function generatePythonTarballUrl(version, platform = process.platform, arch = process.arch) { return `https://python-binaries.zeit.sh/python-${version}-${platform}-${arch}.tar.gz`; } async function installPython(dest, version, platform = process.platform, arch = process.arch) { // For Apple M1 use the x64 binaries if (platform === 'darwin' && arch === 'arm64') { arch = 'x64'; } const tarballUrl = generatePythonTarballUrl(version, platform, arch); debug('Downloading Python %s tarball %o', version, tarballUrl); const res = await (0, node_fetch_1.default)(tarballUrl); if (!res.ok) { throw new Error(`HTTP request ${tarballUrl} failed: ${res.status}`); } debug('Extracting Python %s tarball to %o', version, dest); await (0, promises_1.pipeline)(res.body, (0, node_zlib_1.createGunzip)(), (0, tar_1.extract)({ strip: 1, C: dest })); } //# sourceMappingURL=install-python.js.map