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

utils: Use shelljs.which to get the path for an executable #755

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
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
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);
};

});
});
Loading