Extension that executes shell or python code
See original GitHub issueProblem
I’d like to create an extension that runs some shell or python code. From what I’ve been able to find (mainly this: https://github.com/enlznep/jupyterlab-shell-file/blob/master/src/index.ts) and a failed attempt at using child_process
or zx
from the src/index.ts
file I have not managed to execute any shell code from an extension. I am trying to replicate the toolbar button example but executing some shell code (could be python too - but ideally shell) when the button is clicked
Proposed Solution
I have also tried adding the following (to no success):
const { exec } = require("child_process");
exec("ls -la", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
Any help is appreciated, also I’d love to see an example of this feature if it’s possible at all
Issue Analytics
- State:
- Created a year ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Python Shell
A Python shell for Chrome. You can use Python Shell to test Python code or as a learning tool. It is a complete...
Read more >5 Must-have Chrome Extensions for Python - TechBeamers
1- Python Shell Extension by Sam Clegg · 2- QuickPy Python Interpreter · 3- Python Fiddle by PythonFiddle.com · 4- Python Shell by...
Read more >Python in Visual Studio Code
Working with Python in Visual Studio Code, using the Microsoft Python extension, is simple, fun, and productive. The extension makes VS Code an...
Read more >Python Interpreter: Shell/REPL - TutorialsTeacher
It means it executes the code line by line. Python provides a Python Shell, which is used to execute a single Python command...
Read more >Run Python Script – How to Execute Python Shell Commands ...
py extension, typically called Python scripts. Then you execute them from the terminal using the Python command. All the commands we executed ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Where possible, you’ll want to use existing
jupyterlab_server
orjupyter_server
REST API endpoints. These cover a lot of cases… indeed everything you see in JupyterLab!To get really custom behavior, you’d extend the REST API with a python serverextension, and you can distribute both the static assets of the labextension and the handler in the same pip-installable package.
Of note: when the things you are calling are possible to be called directly from python, it can be useful to call them there, as you don’t have to worry as much about cross-platform concerns.
nbconvert
is such an example… but doesn’t have an asynchronous API. However, any time your code “blocks”, e.g. withsubrocess.check_output
it will block the whole system, and no other server methods will fire. For a while now, we’ve hadanyio
at our disposal, which has good support for cross-platform, async processes .Hey @bollwyvl and @jasongrout, thanks for your replies!
After some digging I’ve gone down the server extension way. I still have some issues though, regarding how to get the current notebook path as @paugier is asking in #203. I’ll write another issue for clarity