Skip to content

Commit

Permalink
Merge pull request #577 from yhat/only-set-path-on-builtin
Browse files Browse the repository at this point in the history
only set path on builtin
  • Loading branch information
TakenPilot authored Jan 3, 2017
2 parents 01a9e32 + 10b0fbf commit f200f00
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 42 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
],
"win": {
"target": [
"squirrel"
"squirrel",
"zip"
],
"extraResources": [
{
Expand Down
4 changes: 3 additions & 1 deletion src/browser/containers/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export default React.createClass({
store.dispatch(dialogActions.showRegisterRodeo());

// no visual for this please
applicationControl.checkForUpdates();
if (local.get('enableAutoupdate') !== false) {
applicationControl.checkForUpdates();
}

// try and start an instance of the python client
client.guaranteeInstance();
Expand Down
6 changes: 6 additions & 0 deletions src/browser/containers/preferences-viewer/layout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@
label: alwaysAskBeforeQuiting
type: checkbox
value: true
-
id: enableAutoupdate
key: enableAutoupdate
label: enableAutoupdate
type: checkbox
value: true
-
id: preferences-project
label: project
Expand Down
1 change: 1 addition & 0 deletions src/browser/containers/text.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ editingEnvironmentVariableExplanation: |
Add or override environment variables
editor: Editor
emacs: Emacs
enableAutoupdate: Enable Autoupdates
enableStartingTutorial: Enable the Starting Tutorial
environmentVariables: Environment Variables
environmentVariableExplanation: |
Expand Down
28 changes: 23 additions & 5 deletions src/node/kernels/python/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ class JupyterClient extends EventEmitter {
* @returns {object}
*/
function getPythonCommandOptions(options) {
log('info', 'getPythonCommandOptions', options);

return {
cwd: options.cwd,
env: pythonLanguage.setDefaultEnvVars(options.env),
Expand All @@ -418,12 +420,18 @@ function getPythonCommandOptions(options) {
};
}

function getPythonCmd(options) {
if (options.cmd === '<rodeo-builtin-miniconda>') {
return pythonLanguage.getPythonPath();
function containsResourcesPath(str) {
return _.isString(str) && str.indexOf(process.resourcesPath) > -1;
}

function applyPythonCmd(options) {
if (options.cmd === '<rodeo-builtin-miniconda>' || containsResourcesPath(options.cmd)) {
options = _.cloneDeep(options);
options.env = pythonLanguage.setBuiltinDefaultEnvVars(options.env);
options.cmd = pythonLanguage.getPythonPath();
}

return options.cmd;
return options;
}

/**
Expand All @@ -435,11 +443,21 @@ function getPythonCmd(options) {
* @returns {ChildProcess}
*/
function createPythonScriptProcess(options) {
log('info', 'createPythonScriptProcess', options);

options = resolveHomeDirectoryOptions(options);

log('info', 'createPythonScriptProcess1', options);

options = applyPythonCmd(options);

log('info', 'createPythonScriptProcess2', options);


const args = ['-c', listenScript, options.kernelName],
cmdOptions = getPythonCommandOptions(options);

return processes.create(getPythonCmd(options), args, cmdOptions);
return processes.create(options.cmd, args, cmdOptions);
}

/**
Expand Down
80 changes: 45 additions & 35 deletions src/node/kernels/python/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*/

import _ from 'lodash';
import fs from 'fs';
import path from 'path';
import envService from '../../services/env';

const resourcesPath = process.resourcesPath;
const resourcesPath = process.resourcesPath,
log = require('../../services/log').asInternal(__filename);

/**
* @param {object} args
Expand All @@ -21,12 +21,6 @@ function toPythonArgs(args) {
}, {});
}

function addPath(envs, path) {
if (!_.includes(envs, path) && fs.existsSync(path)) {
envs.push(path);
}
}

function getCondaPath() {
return path.join(resourcesPath, 'conda');
}
Expand All @@ -40,35 +34,56 @@ function getStartKernelPath() {
}

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

addPath(envs, '/sbin');
addPath(envs, '/usr/sbin');
addPath(envs, '/usr/local/bin');
log('info', 'setDefaultEnvVars', env);

env.PATH = envs.join(splitter);
if (process.platform === 'darwin') {
envService.appendToPath(env, '/sbin');
envService.appendToPath(env, '/usr/sbin');
envService.appendToPath(env, '/usr/local/bin');
}

return _.assign({
PYTHONUNBUFFERED: '1',
PYTHONIOENCODING: 'utf-8'
}, env);
return setPythonConstants(env);
}

function setBuiltinDefaultEnvVars(env) {
if (process.resourcesPath) {
log('info', 'setBuiltinDefaultEnvVars', env);

if (!env.PATH && !env.Path) {
throw new Error('MISSING PATH in setBuiltinDefaultEnvVars');
}

envService.appendToPath(env, path.join(process.resourcesPath, 'conda'));
envService.appendToPath(env, path.join(process.resourcesPath, 'conda', 'bin'));
envService.appendToPath(env, path.join(process.resourcesPath, 'conda', 'Lib'));
envService.appendToPath(env, path.join(process.resourcesPath, 'conda', 'Lib', 'bin'));
envService.appendToPath(env, path.join(process.resourcesPath, 'conda', 'Scripts'));
envService.appendToPath(env, path.join(process.resourcesPath, 'conda', 'Scripts', 'bin'));

envService.appendToPath(env, path.join(process.resourcesPath, 'conda', 'DLLs'), 'pythonPath');
envService.appendToPath(env, path.join(process.resourcesPath, 'conda', 'Lib'), 'pythonPath');
envService.appendToPath(env, path.join(process.resourcesPath, 'conda', 'Lib', 'site-packages'), 'pythonPath');
}

return env;
}

function setPythonConstants(env) {
if (!env.PYTHONUNBUFFERED) {
env.PYTHONUNBUFFERED = '1';
}

if (!env.PYTHONIOENCODING) {
env.PYTHONIOENCODING = 'utf-8';
}

return env;
}

function extendOwnEnv() {
if (process.resourcesPath) {
envService.appendToPath(process.env, path.join(process.resourcesPath, 'conda'));
envService.appendToPath(process.env, path.join(process.resourcesPath, 'conda', 'bin'));
envService.appendToPath(process.env, path.join(process.resourcesPath, 'conda', 'Lib'));
envService.appendToPath(process.env, path.join(process.resourcesPath, 'conda', 'Lib', 'bin'));
envService.appendToPath(process.env, path.join(process.resourcesPath, 'conda', 'Scripts'));
envService.appendToPath(process.env, path.join(process.resourcesPath, 'conda', 'Scripts', 'bin'));

envService.appendToPath(process.env, path.join(process.resourcesPath, 'conda', 'DLLs'), 'pythonPath');
envService.appendToPath(process.env, path.join(process.resourcesPath, 'conda', 'Lib'), 'pythonPath');
envService.appendToPath(process.env, path.join(process.resourcesPath, 'conda', 'Lib', 'site-packages'), 'pythonPath');
}

if (process.platform !== 'win32') {
Expand All @@ -77,20 +92,15 @@ function extendOwnEnv() {
envService.appendToPath(process.env, '/usr/local/bin');
}

if (!process.env.PYTHONUNBUFFERED) {
process.env.PYTHONUNBUFFERED = '1';
}

if (!process.env.PYTHONIOENCODING) {
process.env.PYTHONIOENCODING = 'utf-8';
}
return setPythonConstants(process.env);
}

export default {
extendOwnEnv,
getStartKernelPath,
getPythonPath,
getCondaPath,
setBuiltinDefaultEnvVars,
setDefaultEnvVars,
toPythonArgs
};

0 comments on commit f200f00

Please sign in to comment.