Skip to content

Commit 61ad66a

Browse files
committed
chore: init
0 parents  commit 61ad66a

8 files changed

Lines changed: 6888 additions & 0 deletions

File tree

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
.DS_Store
3+
dist
4+
*.local
5+
.vite-inspect
6+
.remote-assets
7+
components.d.ts

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# slidev-addon-python-runner
2+
3+
Python runner for the [Monaco Runner feature](https://sli.dev/features/monaco-run) in [Slidev](https://sli.dev/). Code executed in browser using [Pyodide](https://pyodide.org/).
4+
5+
![Demo](assets/image.png)
6+
7+
## Usage
8+
9+
Firstly, install the package:
10+
11+
```bash
12+
npm install slidev-addon-python-runner
13+
```
14+
15+
Then, add it as an addon in your headmatter in `slides.md`:
16+
17+
```md
18+
---
19+
addons:
20+
- slidev-addon-python-runner
21+
22+
# Optional configuration for this runner
23+
python:
24+
# Install packages from PyPI. Default: []
25+
installs: ["flask"]
26+
27+
# Code executed to set up the environment. Default: ""
28+
prelude: |
29+
GREETING_FROM_PRELUDE = "Hello, Slidev!"
30+
31+
# Automatically load the imported builtin packages. Default: true
32+
loadPackagesFromImports: true
33+
34+
# Disable annoying warning from `pandas`. Default: true
35+
suppressDeprecationWarnings: true
36+
37+
# Always reload the Python environment when the code changes. Default: false
38+
alwaysReload: false
39+
40+
# Options passed to `loadPyodide`. Default: {}
41+
loadPyodideOptions: {}
42+
---
43+
```
44+
45+
To add an interactive Python code runner, use the `monaco-run` directive:
46+
47+
````md
48+
```python {monaco-run}
49+
from termcolor import colored
50+
51+
print(colored("Hello, Slidev!", "blue"))
52+
```
53+
````
54+
55+
## Bundle `pyodide`
56+
57+
By default, when building slides (i.e. `slidev build`), the `pyodide` package will be replaced with the CDN version. This is because of https://github.com/pyodide/pyodide/issues/1949, which causes the imported python packages to be lost when using the bundled version.
58+
59+
To bundle the local version of `pyodide`, set the `PYODIDE_BUNDLE` environment variable to `true`. Note that in this way you can't import python packages in the static build.

assets/image.png

92.2 KB
Loading

package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "slidev-addon-python-runner",
3+
"type": "module",
4+
"scripts": {
5+
"build": "slidev build",
6+
"dev": "slidev --open",
7+
"export": "slidev export"
8+
},
9+
"license": "MIT",
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/KermanX/slidev-addon-python-runner.git"
13+
},
14+
"files": [
15+
"assets",
16+
"setup",
17+
"README.md",
18+
"LICENSE",
19+
"vite.config.ts"
20+
],
21+
"devDependencies": {
22+
"@slidev/cli": "latest",
23+
"@slidev/client": "latest",
24+
"@slidev/theme-default": "latest",
25+
"@slidev/types": "latest",
26+
"@types/node": "latest",
27+
"vite": "5",
28+
"vue": "latest"
29+
},
30+
"packageManager": "pnpm@9.14.3",
31+
"dependencies": {
32+
"pyodide": "^0.26.4"
33+
}
34+
}

0 commit comments

Comments
 (0)