diff --git a/README.md b/README.md index c25fba0..7606d42 100644 --- a/README.md +++ b/README.md @@ -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: ``` diff --git a/public/pyodide/setuptools-67.6.1-py3-none-any.whl b/public/pyodide/setuptools-67.6.1-py3-none-any.whl deleted file mode 100644 index 7ece02d..0000000 Binary files a/public/pyodide/setuptools-67.6.1-py3-none-any.whl and /dev/null differ diff --git a/src/App.js b/src/App.js index 278b9cf..0933f8a 100644 --- a/src/App.js +++ b/src/App.js @@ -25,11 +25,13 @@ function App() { console.log(consoleOutputs); }, [consoleOutputs]) + // pyodideInstance={myPyodideInstance} + return (
+ pyodideInstance={myPyodideInstance}/>
); diff --git a/src/lib/PythonEditor.js b/src/lib/PythonEditor.js index 17b173b..57c1e0c 100644 --- a/src/lib/PythonEditor.js +++ b/src/lib/PythonEditor.js @@ -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) => { @@ -32,6 +33,15 @@ async function runPyodideExecution(codeString, pyodideInstance) { } }); + try{ + // load from specific URL from Pyodide - if integrity issues check that correct version and correct URL + await pyodideInstance.loadPackagesFromImports(codeString); + } catch (e) { + let outputLine = e.message; // if fails do not run the code, output the error + execData.logs.push(outputLine); + return execData; + } + try { await pyodideInstance.runPythonAsync(codeString); } catch (e) { @@ -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);