Skip to content

Commit

Permalink
conda running
Browse files Browse the repository at this point in the history
  • Loading branch information
TakenPilot committed Nov 25, 2016
1 parent 4d44966 commit 90dc646
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ BETA.md
.vagrant
*.swp
npm-debug.log*
.tmp

app
dist
Expand Down
4 changes: 0 additions & 4 deletions config/default.yml

This file was deleted.

32 changes: 2 additions & 30 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,6 @@ gulp.task('images', function () {
]).pipe(gulp.dest(outputMap.images));
});

/**
* Copy the config-specific code over to the temp directory that will be distributed with a deployed app
*/
gulp.task('config', function () {
// copy node program
return gulp.src([
'config/**/*'
]).pipe(gulp.dest(outputMap.config));
});

/**
* Copy the node-specific code over to the temp directory that will be distributed with a deployed app
*/
Expand All @@ -139,30 +129,12 @@ gulp.task('package.json', function () {

pkg.main = 'node/index.js';

return JSON.stringify(_.omit(pkg, ['devDependencies', 'build', 'bin']), null, 2);
return JSON.stringify(_.omit(pkg, ['devDependencies', 'build', 'bin', 'scripts', 'jest']), null, 2);
}))
.pipe(gulp.dest(outputMap.app));
});

/**
* Installs only the dependencies need to the run the app (not build the app) to the tmpAppDirectory
* @returns {Promise}
*/
gulp.task('npm-install', function () {
const path = tmpAppDirectory,
args = ['--production'];

return new Promise(function (resolve, reject) {
require('npm-i')({path, args}, function (err) {
if (err) {
return reject(err);
}
resolve();
});
});
});

gulp.task('test', ['lint']);
gulp.task('build', ['themes', 'external', 'images', 'ace', 'jsx', 'html', 'config', 'node', 'package.json']);
gulp.task('build', ['themes', 'external', 'images', 'ace', 'jsx', 'html', 'node', 'package.json']);
gulp.task('dist', ['dist:all']);
gulp.task('default', ['test', 'build']);
21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,29 @@
"build": {
"appId": "com.yhat.rodeo",
"helper-bundle-id": "com.yhat.rodeo.helper",
"asar": false,
"asar": true,
"publish": [
{
"provider": "generic",
"url": "https://s3.amazonaws.com/bucket_name",
"url": "http://rodeo-nsis.yhat.com/asdf",
"channel": "latest"
}
],
"win": {
"target": [
"squirrel",
"nsis",
"zip"
"squirrel"
],
"extraResources": [
{
"from": ".tmp/conda/",
"to": "conda",
"filter": "**/*"
},
{
"from": "app/node/kernels/python/",
"to": "kernels/python",
"filter": "**/*.py"
}
]
},
"linux": {
Expand Down Expand Up @@ -127,6 +137,7 @@
"chalk": "^1.1.3",
"chokidar": "^1.6.0",
"colors": "^1.1.2",
"copy": "^0.3.0",
"cuid": "^1.3.8",
"eventify": "^2.0.0",
"express": "^4.13.4",
Expand Down
2 changes: 1 addition & 1 deletion scripts/osx/dist-win.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ source $(brew --prefix nvm)/nvm.sh
nvm use

#build distributable
./node_modules/.bin/gulp dist:win
DEBUG=electron-windows-installer:* node_modules/.bin/build --win --x64

#list created files
echo '#list created files'
Expand Down
4 changes: 4 additions & 0 deletions scripts/win/setup_conda.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// install script to set windows right

pip install jupyter_client ipykernel matplotlib numpy pandas
jupyter install --user
9 changes: 9 additions & 0 deletions src/browser/jsx/services/jupyter/conda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import api from '../api';

function copyCondaToHome() {
return api.send('copyCondaToHome');
}

export default {
copyCondaToHome
};
7 changes: 4 additions & 3 deletions src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function getPkg() {

while (dir.length > 1) {
dir = path.resolve(dir, '..');
pkg = files.getJSONFileSafeSync(path.join(dir, 'package.json'));
pkg = files.getInternalJSONFileSafeSync(path.join(dir, 'package.json'));
if (pkg) {
return pkg;
}
Expand Down Expand Up @@ -566,8 +566,8 @@ function onCreateKernelInstance(options) {
subscribeWindowToKernelEvents('mainWindow', client, instanceId);

return kernelClients[instanceId];
}).catch(function () {
log('error', 'failed to create instance', instanceId);
}).catch(function (ex) {
log('error', 'failed to create instance', instanceId, ex);
delete kernelClients[instanceId];
});
});
Expand Down Expand Up @@ -941,6 +941,7 @@ function attachIpcMainEvents() {
onCheckForUpdates,
onCheckKernel,
onCloseWindow,
onCopyCondaToHome,
onCreateKernelInstance,
onCreateWindow,
onDatabaseConnect,
Expand Down
38 changes: 33 additions & 5 deletions src/node/kernels/python/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const _ = require('lodash'),
bluebird = require('bluebird'),
clientResponse = require('./client-response'),
EventEmitter = require('events'),
environment = require('../../services/env'),
StreamSplitter = require('stream-splitter'),
log = require('../../services/log').asInternal(__filename),
path = require('path'),
Expand Down Expand Up @@ -422,17 +421,46 @@ function createPythonScriptProcess(targetFile, options) {
});
}

function getStartKernelPath() {
log('info', 'getStartKernelPath', {'process.platform': process.platform});
if (process.platform === 'win32') {
log('info', 'is-windows');

let testPath = path.join(__dirname.split('app.asar')[0], 'kernels', 'python', 'start_kernel.py');

log('info', {testPath});

if (testPath) {
log('info', 'existence?');
return files.exists(testPath).then(function (exists) {
log('info', {testPath, exists});

if (exists) {
return testPath;
}

throw new Error('Could not find start_kernel.py on Windows ');
});
}

throw new Error('Could not find test_path on Windows');
}

return bluebird.resolve(path.resolve(path.join(__dirname, 'start_kernel.py')));
}

/**
* @param {object} options
* @returns {Promise<JupyterClient>}
*/
function create(options) {
assertValidOptions(options);
const targetFile = path.resolve(path.join(__dirname, 'start_kernel.py'));

return createPythonScriptProcess(targetFile, options).then(function (child) {
return new JupyterClient(child);
});
return getStartKernelPath()
.then(targetFile => createPythonScriptProcess(targetFile, options))
.then(function (child) {
return new JupyterClient(child);
});
}

/**
Expand Down
67 changes: 52 additions & 15 deletions src/node/kernels/python/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
'use strict';

const _ = require('lodash'),
fs = require('fs'),
fs = require('original-fs'),
os = require('os'),
log = require('../../services/log').asInternal(__filename);
log = require('../../services/log').asInternal(__filename),
path = require('path');

/**
* @param {object} args
Expand All @@ -27,36 +28,72 @@ function addPath(envs, path) {
}
}

function getCondaPath() {
return path.join(__dirname.split('app.asar')[0], 'conda');
}

function getPythonPath() {
return path.join(__dirname.split('app.asar')[0], 'conda');
}

function getLibPath() {
return path.join(__dirname.split('app.asar')[0], 'conda', 'Lib');
}

function getScriptsPath() {
return path.join(__dirname.split('app.asar')[0], 'conda', 'Scripts');
}

function getStartKernelPath() {
return path.join(__dirname.split('app.asar')[0], 'kernels', 'python', 'start_kernel.py');
}

function setDefaultEnvVars(env) {
if (process.platform === 'darwin' && _.isString(env.PATH)) {
if (_.isString(env.PATH)) {
const envs = env.PATH.split(':');
if (_.isString(env.PATH)) {
if (process.platform === 'darwin') {
const splitter = ':',
envs = env.PATH.split(splitter);

addPath(envs, '/sbin');
addPath(envs, '/usr/sbin');
addPath(envs, '/usr/local/bin');

env.PATH = envs.join(':');
env.PATH = envs.join(splitter);
} else if (process.platform === 'win32') {
const splitter = ';',
envs = env.PATH.split(splitter);

addPath(envs, getPythonPath());
addPath(envs, getLibPath());
addPath(envs, getScriptsPath());

env.PATH = envs.join(splitter);
}
}

// we support colors
if (process.platform !== '32' && env.CLICOLOR === undefined) {
env.CLICOLOR = 1;
}
if (process.platform === 'win32') {
env.CONDA = getCondaPath();
env.IPYTHONDIR = getPythonPath();

if (process.platform === 'win32' && !env.NUMBER_OF_PROCESSORS) {
try {
env.NUMBER_OF_PROCESSORS = os.cpus().length;
} catch (ex) {
log('warn', 'failed to set NUMBER_OF_PROCESSORS', ex);
if (!env.NUMBER_OF_PROCESSORS) {
try {
env.NUMBER_OF_PROCESSORS = os.cpus().length;
} catch (ex) {
log('warn', 'failed to set NUMBER_OF_PROCESSORS', ex);
}
}
}

// we support colors
if (process.platform !== 'win32' && env.CLICOLOR === undefined) {
env.CLICOLOR = 1;
}

return _.assign({
PYTHONUNBUFFERED: '1'
}, env);
}

module.exports.toPythonArgs = toPythonArgs;
module.exports.setDefaultEnvVars = setDefaultEnvVars;
module.exports.getStartKernelPath = getStartKernelPath;
7 changes: 3 additions & 4 deletions src/node/services/browser-windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const _ = require('lodash'),
bluebird = require('bluebird'),
cuid = require('cuid'),
electron = require('electron'),
fs = require('fs'),
path = require('path'),
files = require('./files'),
yaml = require('js-yaml'),
log = require('./log').asInternal(__filename),
util = require('util'),
Expand All @@ -19,11 +19,10 @@ const _ = require('lodash'),

function getCommonErrors() {
const targetFile = path.resolve(path.join(__dirname, 'chromium-errors.yml'));
let contents, commonErrors;
let commonErrors;

try {
contents = fs.readFileSync(targetFile, 'utf8');
commonErrors = contents && yaml.safeLoad(contents);
commonErrors = files.getInternalYAMLFileSafeSync(targetFile, 'utf8');
} catch (ex) {
log('warn', 'could not read', targetFile, ex);
commonErrors = {};
Expand Down
Loading

0 comments on commit 90dc646

Please sign in to comment.