This commit is contained in:
Tiago Koji Castro Shibata 2018-08-01 21:02:51 -07:00
Родитель 2ae54c451f
Коммит b6450aea04
2 изменённых файлов: 83 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,68 @@
const { execFile, execFileSync } = require('child_process');
const fs = require('fs');
const https = require('https');
const path = require('path');
const unzipper = require('unzipper');
const util = require('util');
const appData = process.env.APPDATA ||
path.join(process.env.HOME, process.platform == 'darwin' ? 'Library/Preferences' : '.local/share');
function mkdir(...directory) {
directory = path.join(...directory);
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory);
}
return directory;
}
function filterPythonBinaries(binaries) {
// Look for binaries with venv support
return binaries.filter((binary) => {
try {
execFileSync(binary, ['-c', 'import venv']);
return true;
} catch(_) {}
}, []);
}
function getPythonBinaries() {
const localPython = path.join(appData, 'WinML-Dashboard/python/python')
const binaries = filterPythonBinaries([localPython, 'python3', 'py', 'python'])
if (process.platform === 'win32' && binaries[0] !== localPython) {
binaries.push(null); // use null to represent local, embedded version
}
return binaries;
}
function downloadPython(success, error) {
if (process.platform !== 'win32') {
throw new Error('Unsupported platform');
}
const pythonUrl = 'https://www.python.org/ftp/python/3.7.0/python-3.7.0-embed-amd64.zip';
const appFolder = mkdir(appData, 'WinML-Dashboard');
const pythonFolder = mkdir(appFolder, 'python');
https.get(pythonUrl, response =>
response.pipe(unzipper.Extract({ path: pythonFolder }))
.on('finish', success)
.on('error', error));
}
async function installVenv(targetPython) {
const execFilePromisse = util.promisify(execFile);
const venv = path.join(mkdir(appData, 'WinML-Dashboard'), 'venv');
await execFilePromisse(targetPython, ['-m', 'venv', venv]);
const python = filterPythonBinaries([path.join(venv, 'bin/python'), path.join(venv, 'Scripts/python')])[0];
async function pip(...command) {
return await execFilePromisse(python, ['-m', 'pip', ...command]);
}
await pip('install', '-U', 'pip')
await pip('install', '-r', path.join(__dirname, 'requirements.txt'))
}
module.exports = {
downloadPython,
getPythonBinaries,
installVenv,
};

Просмотреть файл

@ -0,0 +1,15 @@
-e git+https://github.com/apple/coremltools@ad3e24d875972cd2242b531e80d99d92ae215dec#egg=coremltools
h5py==2.8.0
Keras==2.2.2
Keras-Applications==1.0.4
Keras-Preprocessing==1.0.2
numpy==1.15.0
onnx==1.2.2
-e git+https://github.com/onnx/onnxmltools@708d3091084da1acf42cf058161017e1152fa337#egg=onnxmltools
protobuf==3.6.0
PyYAML==3.13
scikit-learn==0.19.2
scipy==1.1.0
six==1.10.0
typing==3.6.4
typing-extensions==3.6.5