Skip to content

Commit

Permalink
Merge pull request #755 from kiike/pr/use_path_to_find_executables
Browse files Browse the repository at this point in the history
utils: Use shelljs.which to get the path for an executable
  • Loading branch information
cavearr authored Jul 10, 2024
2 parents 2651865 + 6bae3b1 commit 2b31cd3
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 13 deletions.
173 changes: 173 additions & 0 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"rsyncwrapper": "~2.0.1",
"select2": "~4.1.0-rc.0",
"sha1": "~1.1.1",
"shelljs": "^0.8.5",
"snapsvg": "~0.5.1",
"spark-md5": "^3.0.1",
"ssh-exec": "~2.0.0",
Expand Down
3 changes: 3 additions & 0 deletions app/scripts/factories/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ angular.module('icestudio')
.factory('nodeDebounce', function() {
return require('lodash.debounce');
})
.factory('shelljs', function() {
return require('shelljs');
})
.factory('SVGO', function() {
var config = {
full: true,
Expand Down
20 changes: 7 additions & 13 deletions app/scripts/services/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ angular.module('icestudio')
nodeLangInfo,
SVGO,
fastCopy,
shelljs,
sparkMD5) {

let _pythonExecutableCached = null;
Expand Down Expand Up @@ -112,24 +113,17 @@ angular.module('icestudio')
}

//---------------------------------------------------------
//-- Get the path of an executable using the `which` utility
//-- Get the path of an executable using the `which` shelljs module
//--
//-- INPUTS:
//-- -executable: string for an executable
//-- OUTPUTS:
//-- string: the path to the executable
//-- null: `which` is unavailable or execution error
//-- null: executable not found
function getExecutablePath(executable) {
const command = `which ${executable}`;
try {
const result = nodeChildProcess.execSync(command);
if (result !== false && result !== null) {
return result.toString();
}
} catch (e) {
console.error(e);
}
return null;
// split executable at first space to account for e.g. `python.exe -3`
executable = executable.split(" ")[0]
return shelljs.which(executable)
}


Expand Down Expand Up @@ -1683,4 +1677,4 @@ angular.module('icestudio')
}, 50);
};

});
});

0 comments on commit 2b31cd3

Please sign in to comment.