Skip to content

Commit

Permalink
docs: Add playground to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kayjan committed Jun 25, 2024
1 parent 567d817 commit d77809a
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 61 deletions.
10 changes: 5 additions & 5 deletions docs/_static/playground-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var colorNotebook = {
"playgroundWheels": ['pygments-2.17.2-py3-none-any.whl', 'bigtree-0.19.0-py3-none-any.whl'],
"notebookWheels": [],
"defaultPlayground": "print('hello world')"
}
var colorNotebook = {
"playgroundWheels": ['pygments-2.17.2-py3-none-any.whl', 'bigtree-0.19.0-py3-none-any.whl'],
"notebookWheels": [],
"defaultPlayground": ""
}
16 changes: 8 additions & 8 deletions docs/_static/playground.js

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions docs/_static/playground.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
Execute Python code in code blocks (Adapted from ColorAide).
This can be executed in either a Pyodide environment of a normal Python environment.
3rd party libraries (that are not available directly from Pyodide) are only loaded
when needed so that Pyodide will have a chance to load them if necessary.
Transform Python code by executing it, transforming to a Python console output,
and finding and outputting color previews.
"""
Expand All @@ -20,8 +17,6 @@
from pygments.formatters import find_formatter_class
from pygments.lexers import get_lexer_by_name

from bigtree import * # noqa

PY310 = (3, 10) <= sys.version_info
PY311 = (3, 11) <= sys.version_info

Expand Down Expand Up @@ -63,7 +58,7 @@
</div>
<div class="playground-footer" data-search-exclude>
<hr>
<button id="__playground-edit_{el_id}" class="playground-edit" title="Edit the current snippet">Edit</button>
<button id="__playground-edit_{el_id}" class="playground-edit" title="Edit the code snippet">Edit</button>
<button id="__playground-share_{el_id}" class="playground-share" title="Copy URL to current snippet">Share</button>
<button id="__playground-run_{el_id}" class="playground-run hidden" title="Run code (Ctrl + Enter)">Run</button>
<button id="__playground-cancel_{el_id}" class="playground-cancel hidden" title="Cancel edit (Escape)">Cancel</button>
Expand Down
38 changes: 21 additions & 17 deletions docs/_static/playground_whl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,28 @@
import urllib.request

# Output files
OUTPUT_WHL = "docs/playground/"
OUTPUT_WHL = "docs/_static/"
OUTPUT_JS = "docs/_static/"

# Build message output
BUILD_WHL_MESSAGE = f"{OUTPUT_WHL}(.*whl)"
BUILD_WHL_COMMAND = [sys.executable, "-m", "hatch", "build", OUTPUT_WHL]
# BUILD_WHL_MESSAGE = f"{OUTPUT_WHL}(.*whl)"
# BUILD_WHL_COMMAND = [sys.executable, "-m", "hatch", "build", OUTPUT_WHL]
BUILD_WHL_MESSAGE = r"Successfully built ([-_0-9.a-zA-Z]+?\.whl)"
BUILD_WHL_COMMAND = [sys.executable, "-m", "build", "--wheel", "-o", OUTPUT_WHL]

DEFAULT_COMMANDS = ["print('hello world')"]
DEFAULT_COMMANDS = [""]

PLAYGROUND_WHEELS = [
"https://files.pythonhosted.org/packages/97/9c/372fef8377a6e340b1704768d20daaded98bf13282b5327beb2e2fe2c7ef/pygments-2.17.2-py3-none-any.whl"
]

CONFIG = """\
var colorNotebook = {{
"playgroundWheels": {},
"notebookWheels": [],
"defaultPlayground": "{}"
}}
"""


def build_package():
Expand All @@ -39,7 +53,9 @@ def build_package():
env=os.environ.copy(),
)
out, _ = process.communicate()
m = re.compile(BUILD_WHL_MESSAGE).search(out.decode("utf-8"))
build_message = out.decode("utf-8")
m = re.compile(BUILD_WHL_MESSAGE).search(build_message)
print(build_message)

return process.returncode, m.group(1) if m else ""

Expand Down Expand Up @@ -67,18 +83,6 @@ def download_wheel(url, dest):

if __name__ == "__main__":

PLAYGROUND_WHEELS = [
"https://files.pythonhosted.org/packages/97/9c/372fef8377a6e340b1704768d20daaded98bf13282b5327beb2e2fe2c7ef/pygments-2.17.2-py3-none-any.whl"
]

CONFIG = """\
var colorNotebook = {{
"playgroundWheels": {},
"notebookWheels": [],
"defaultPlayground": "{}"
}}
"""

PLAYGROUND = {}
for url in PLAYGROUND_WHEELS:
PLAYGROUND[os.path.join(OUTPUT_WHL, url.split("/")[-1])] = url
Expand Down
21 changes: 21 additions & 0 deletions docs/playground/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: Playground
hide:
- navigation
- toc
---

# 🎡️ Playground

```py play
# from bigtree import dict_to_tree

path_dict = {
"a": {"age": 90},
"a/b": {"age": 65},
"a/c": {"age": 60},
"a/b/d": {"age": 40},
}
root = dict_to_tree(path_dict)
root.show()
```
24 changes: 0 additions & 24 deletions docs/playground/playground.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
black>=24.1.0
build
IPython
mdx_truly_sane_lists==1.3
mkdocs==1.5.3
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ nav:
- Resources:
- gettingstarted/resources/articles.md
- Playground:
- playground/playground.md
- playground/index.md
- Code Documentation:
- Node:
- bigtree/node/index.md
Expand Down

0 comments on commit d77809a

Please sign in to comment.