Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to add env variables for running python files #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions lib/atom-python-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
'command': atom.config.get(`atom-python-run.${key}Command`),
'pause': atom.config.get(`atom-python-run.${key}Pause`),
});
}
}
} catch(error) {
// the promise failed and the exception was caught
console.log(`atom-python-run: saveAndRun: ${error}`);
Expand All @@ -48,14 +48,32 @@ module.exports = {
let args = config.command.split(' ');

// load configuration settings in to 'config' object

config = Object.assign(config, {
'terminal': atom.config.get('atom-python-run.terminal'),
'pipeFile': atom.config.get('atom-python-run.pipeFile'),
'pipePath': atom.config.get('atom-python-run.pipePath'),
'extensions': atom.config.get('atom-python-run.extensionFilter'),
'consoleLog': atom.config.get('atom-python-run.consoleLog')
'consoleLog': atom.config.get('atom-python-run.consoleLog'),
'f5envVariables': atom.config.get('atom-python-run.f5envVariables') // Environment Variables
});

let tmpEnv = {};
var tmpArr = []

// Extracting the env Variables from array format

for (var i = 0; i < config.f5envVariables.length; i++) {
if(config.f5envVariables[i].includes(":")){
tmpArr = config.f5envVariables[i].split(":")
if(tmpArr.length==2){
tmpEnv[tmpArr[0]] = tmpArr[1];
}
}
}

// console.log(tmpEnv);

function format(string, object) {
return string.replace(/{.*?}/g, (element) =>
object[element.substring(1, element.length - 1)]
Expand Down Expand Up @@ -118,7 +136,8 @@ module.exports = {
'args': args,
'options': {
cwd: info.dir,
detached: true
detached: true,
env: tmpEnv // Passing Environment variables to the shell instance
}
});

Expand Down Expand Up @@ -160,6 +179,16 @@ module.exports = {
type: 'string',
default: 'python {file}'
},
/////// Env Variables option
f5envVariables: {
title: 'Environment Variables',
description: 'format [key:pair, key:pair ...]',
type: 'array',
default: [],
items:{
type: "string"
}
},
f6Command: {
title: 'F6 Command',
description: 'Same as above',
Expand Down