Skip to content
Open
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ function App() {
export default App;
```
This is a **good practice** as it allows you to have full control of the Pyodide instance whilst also being able to leverage the component's capabilities. Consider using this when developing applications that use a [singleton model for Pyodide](https://adamemery.dev/articles/pyodide-react) functionality.

## Using Libraries

In order to import any libraries, the folder at the url specified at `indexURL` when creating the pyodide instance (using `loadPyodide`) must contain the required `.whl` files for each library you are using. In order to get all of the libraries that pyodide has to offer, you can use `indexURL='https://cdn.jsdelivr.net/pyodide/v0.23.4/full/'` (This is the default if no instance is given), or you can [Download all packages from here](https://github.com/pyodide/pyodide/releases) (Make sure to use download
the right version).


## Guide to Contributing 🫶
To get started with contributing, fork this repository and then run the following once you have cloned the forked repo:
```
Expand Down
Binary file removed public/pyodide/setuptools-67.6.1-py3-none-any.whl
Binary file not shown.
4 changes: 3 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ function App() {
console.log(consoleOutputs);
}, [consoleOutputs])

// pyodideInstance={myPyodideInstance}

return (
<div>
<div className="w-screen h-screen grid place-content-center">
<PythonEditor width="90vw" height="80vh" consoleOutputSetter={setConsoleOutputs}
pyodideInstance={myPyodideInstance} />
pyodideInstance={myPyodideInstance}/>
</div>
</div>
);
Expand Down
14 changes: 12 additions & 2 deletions src/lib/PythonEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import CodeIcon from '@mui/icons-material/Code';
import DownloadIcon from '@mui/icons-material/Download';
import './build.css';


async function runPyodideExecution(codeString, pyodideInstance) {
let execData = {
logs: [],
}
}

pyodideInstance.setStdout({
batched: (msg) => {
Expand All @@ -32,6 +33,15 @@ async function runPyodideExecution(codeString, pyodideInstance) {
}
});

try{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style: Needs space between try and opening curly brace

// load from specific URL from Pyodide - if integrity issues check that correct version and correct URL
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style: Capitalise first word of comments

await pyodideInstance.loadPackagesFromImports(codeString);
} catch (e) {
let outputLine = e.message; // if fails do not run the code, output the error
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style: Capitalise first word of comments

execData.logs.push(outputLine);
return execData;
}

try {
await pyodideInstance.runPythonAsync(codeString);
} catch (e) {
Expand All @@ -57,7 +67,7 @@ function PythonEditor(props) {
setPyodideInstance(props.pyodideInstance);
} else {
let pyodide = await loadPyodide({
indexURL: "https://cdn.jsdelivr.net/npm/pyodide@0.23.4/"
indexURL: `https://cdn.jsdelivr.net/pyodide/v0.23.4/full/`
});

setPyodideInstance(pyodide);
Expand Down