UNPKG

boajs

Version:

Use Python modules seamlessly in Node.js

55 lines (43 loc) 1.53 kB
#!/usr/bin/env node 'use strict'; const utils = require('./utils'); const fs = require('fs'); const run = utils.run.bind(utils); const py = utils.py.bind(utils); if (!utils.shouldInstallConda()) { console.info('skip installing the python from conda.'); return process.exit(0); } // download and install conda const remoteURL = utils.getCondaRemote(); const installDir = utils.resolveAndUpdateCondaPath(); const downloader = utils.getCondaDownloaderName(); // fetch the downloader file if that doesn't exist. if (!fs.existsSync(downloader)) { run('curl', `${remoteURL}/${downloader}`, '>', downloader); } // check if the python is installed correctly, we will skip the installation // when it's installed before. if (!utils.shouldPythonInstalledOn(installDir)) { // clean the install dir. run('rm', '-rf', installDir); // install run('sh', downloader, `-f -b -p ${installDir}`); } const removeLibararyOnLinux = (libname) => { run('rm', '-rf', `${installDir}/lib/${libname}`); if (fs.existsSync(`${installDir}/x86_64-conda_cos6-linux-gnu/sysroot`)) { run('rm', '-rf', `${installDir}/x86_64-conda_cos6-linux-gnu/sysroot/lib/${libname}`); } }; // cleanup the standard libs. if (utils.PLATFORM === 'darwin') { run('rm', '-rf', `${installDir}/lib/libc++*`); } else if (utils.PLATFORM === 'linux') { removeLibararyOnLinux('libstdc++.so*'); removeLibararyOnLinux('libgcc_s.so*'); } // dump info py(`${installDir}/bin/conda`, 'info -a'); // install python packages utils.installPythonPackages();