Skip to content

Commit 1e52823

Browse files
committed
wip: initial commit
0 parents  commit 1e52823

File tree

7 files changed

+141
-0
lines changed

7 files changed

+141
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# This file was created automatically with `myst init --gh-pages` 🪄 💚
2+
# Ensure your GitHub Pages settings for this repository are set to deploy with **GitHub Actions**.
3+
4+
name: MyST GitHub Pages Deploy
5+
on:
6+
push:
7+
# Runs on pushes targeting the default branch
8+
branches: [main]
9+
env:
10+
# `BASE_URL` determines the website is served from, including CSS & JS assets
11+
# You may need to change this to `BASE_URL: ''`
12+
BASE_URL: /${{ github.event.repository.name }}
13+
14+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
15+
permissions:
16+
contents: read
17+
pages: write
18+
id-token: write
19+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
20+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
21+
concurrency:
22+
group: "pages"
23+
cancel-in-progress: false
24+
jobs:
25+
deploy:
26+
environment:
27+
name: github-pages
28+
url: ${{ steps.deployment.outputs.page_url }}
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
- name: Setup Pages
33+
uses: actions/configure-pages@v3
34+
- uses: actions/setup-node@v4
35+
with:
36+
node-version: 18.x
37+
- uses: actions/setup-python@v5
38+
with:
39+
python-version: '3.12'
40+
- name: Install MyST Markdown
41+
run: npm install -g mystmd
42+
- name: Build HTML Assets
43+
run: myst build --html
44+
- name: Upload artifact
45+
uses: actions/upload-pages-artifact@v3
46+
with:
47+
path: "./_build/html"
48+
- name: Deploy to GitHub Pages
49+
id: deployment
50+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# MyST build outputs
2+
_build

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# MyST Python Plugin
2+
An example of deploying a MyST book that uses a Python Plugin

content/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Python Plugin
2+
3+
$\sin(2\pi) + \cos(2\pi)$ is:
4+
5+
```{calc}
6+
sin(pi*2) + cos(pi*2)
7+
```

myst.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# See docs at: https://mystmd.org/guide/frontmatter
2+
version: 1
3+
project:
4+
title: Python Plugin
5+
references:
6+
guide: https://mystmd.org/guide
7+
plugins:
8+
- type: executable
9+
path: ./plugin.py
10+
toc:
11+
- file: content/index.md
12+
site:
13+
template: book-theme
14+
options:
15+
logo_text: Python Plugin

plugin.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import json
4+
import sys
5+
6+
7+
plugin = {
8+
"name": "Calculator",
9+
"directives": [
10+
{
11+
"name": "calc",
12+
"doc": "An example directive for running Python expressions.",
13+
"body": {
14+
"type": "string",
15+
"doc": "The expression to compute",
16+
},
17+
}
18+
],
19+
}
20+
21+
22+
def declare_result(content):
23+
"""Declare result as JSON to stdout
24+
25+
:param content: content to declare as the result
26+
"""
27+
28+
# Format result and write to stdout
29+
json.dump(content, sys.stdout, indent=2)
30+
# Successfully exit
31+
raise SystemExit(0)
32+
33+
34+
def run_directive(name, data):
35+
"""Execute a directive with the given name and data
36+
37+
:param name: name of the directive to run
38+
:param data: data of the directive to run
39+
"""
40+
assert name == "calc"
41+
42+
# Run user program
43+
result = eval(data["body"], {**globals(), **vars(__import__("math"))})
44+
result = {"type": "code", "value": str(result)}
45+
return [result]
46+
47+
48+
if __name__ == "__main__":
49+
parser = argparse.ArgumentParser()
50+
group = parser.add_mutually_exclusive_group()
51+
group.add_argument("--role")
52+
group.add_argument("--directive")
53+
group.add_argument("--transform")
54+
args = parser.parse_args()
55+
56+
if args.directive:
57+
data = json.load(sys.stdin)
58+
declare_result(run_directive(args.directive, data))
59+
elif args.transform:
60+
raise NotImplementedError
61+
elif args.role:
62+
raise NotImplementedError
63+
else:
64+
declare_result(plugin)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pillow

0 commit comments

Comments
 (0)