sphinx-pyrepl-web 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sphinx_pyrepl_web-0.1.0/.github/workflows/python-package.yml +31 -0
- sphinx_pyrepl_web-0.1.0/.gitignore +10 -0
- sphinx_pyrepl_web-0.1.0/.readthedocs.yml +15 -0
- sphinx_pyrepl_web-0.1.0/LICENSE +21 -0
- sphinx_pyrepl_web-0.1.0/PKG-INFO +116 -0
- sphinx_pyrepl_web-0.1.0/README.md +87 -0
- sphinx_pyrepl_web-0.1.0/docs/_static/replay_demo.py +3 -0
- sphinx_pyrepl_web-0.1.0/docs/_static/setup.py +6 -0
- sphinx_pyrepl_web-0.1.0/docs/conf.py +21 -0
- sphinx_pyrepl_web-0.1.0/docs/example.rst +106 -0
- sphinx_pyrepl_web-0.1.0/docs/index.rst +7 -0
- sphinx_pyrepl_web-0.1.0/pyproject.toml +40 -0
- sphinx_pyrepl_web-0.1.0/scripts/vendor_repl.py +93 -0
- sphinx_pyrepl_web-0.1.0/sphinx_pyrepl_web/__init__.py +180 -0
- sphinx_pyrepl_web-0.1.0/sphinx_pyrepl_web/pyrepl/chunk-94xkfg72.js +1 -0
- sphinx_pyrepl_web-0.1.0/sphinx_pyrepl_web/pyrepl/chunk-e4mhg83d.js +3 -0
- sphinx_pyrepl_web-0.1.0/sphinx_pyrepl_web/pyrepl/chunk-ftjk4vft.js +2 -0
- sphinx_pyrepl_web-0.1.0/sphinx_pyrepl_web/pyrepl/chunk-jfxv8vy0.js +36 -0
- sphinx_pyrepl_web-0.1.0/sphinx_pyrepl_web/pyrepl/chunk-vx91qfkd.js +2 -0
- sphinx_pyrepl_web-0.1.0/sphinx_pyrepl_web/pyrepl/chunk-x20ze186.js +16 -0
- sphinx_pyrepl_web-0.1.0/sphinx_pyrepl_web/pyrepl/pyrepl.esm.js +697 -0
- sphinx_pyrepl_web-0.1.0/sphinx_pyrepl_web/pyrepl/pyrepl.js +1 -0
- sphinx_pyrepl_web-0.1.0/sphinx_pyrepl_web/pyrepl/version.txt +1 -0
- sphinx_pyrepl_web-0.1.0/tests/test_basic.py +69 -0
- sphinx_pyrepl_web-0.1.0/tests/test_build_replay.py +86 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Run tests on push.
|
|
2
|
+
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
|
|
3
|
+
|
|
4
|
+
name: Python CI
|
|
5
|
+
on: [push]
|
|
6
|
+
jobs:
|
|
7
|
+
build:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
strategy:
|
|
10
|
+
matrix:
|
|
11
|
+
python-version: ["3.12", "3.13", "3.14"]
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v5
|
|
14
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
15
|
+
uses: actions/setup-python@v6
|
|
16
|
+
with:
|
|
17
|
+
python-version: ${{ matrix.python-version }}
|
|
18
|
+
- name: Install
|
|
19
|
+
run: |
|
|
20
|
+
python -m pip install --upgrade pip
|
|
21
|
+
python -m pip install ".[test]"
|
|
22
|
+
python -m pip install pytest-cov codecov
|
|
23
|
+
- name: Test
|
|
24
|
+
run: |
|
|
25
|
+
PYTHONWARNINGS=error pytest --cov --durations=10 .
|
|
26
|
+
# https://github.com/marketplace/actions/codecov
|
|
27
|
+
- name: Codecov Report
|
|
28
|
+
if: matrix.python-version == '3.14'
|
|
29
|
+
uses: codecov/codecov-action@v4
|
|
30
|
+
env:
|
|
31
|
+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Christian López Barrón
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sphinx-pyrepl-web
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Sphinx extension for embedding pyrepl-web Python REPLs in documentation.
|
|
5
|
+
Keywords: sphinx,pyrepl,pyodide,repl
|
|
6
|
+
Author-email: Christian López Barrón <chris.gfz@gmail.com>
|
|
7
|
+
Requires-Python: >=3.12
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Framework :: Sphinx :: Extension
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Topic :: Documentation
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: sphinx>9
|
|
19
|
+
Requires-Dist: myst-parser ; extra == "docs"
|
|
20
|
+
Requires-Dist: pytest ; extra == "test"
|
|
21
|
+
Requires-Dist: sphinx-pytest ; extra == "test"
|
|
22
|
+
Project-URL: Documentation, https://sphinx-pyrepl-web.readthedocs.io/
|
|
23
|
+
Project-URL: Home, https://github.com/chrizzFTD/sphinx-pyrepl-web
|
|
24
|
+
Project-URL: Issues, https://github.com/chrizzFTD/sphinx-pyrepl-web/issues
|
|
25
|
+
Project-URL: Repository, https://github.com/chrizzFTD/sphinx-pyrepl-web
|
|
26
|
+
Provides-Extra: docs
|
|
27
|
+
Provides-Extra: test
|
|
28
|
+
|
|
29
|
+
# sphinx-pyrepl-web
|
|
30
|
+
|
|
31
|
+
Sphinx extension to embed [pyrepl-web](https://github.com/chrizzFTD/pyrepl-web) in documentation.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install sphinx-pyrepl-web
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
For development:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install -e ".[test,docs]"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
Add the extension to the target project's `conf.py`:
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
extensions = [
|
|
51
|
+
"sphinx_pyrepl_web",
|
|
52
|
+
]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Embed a REPL with the `py-repl` directive:
|
|
56
|
+
|
|
57
|
+
```rst
|
|
58
|
+
.. py-repl::
|
|
59
|
+
|
|
60
|
+
.. py-repl::
|
|
61
|
+
:theme: catppuccin-latte
|
|
62
|
+
:no-header:
|
|
63
|
+
|
|
64
|
+
.. py-repl::
|
|
65
|
+
:src: setup.py
|
|
66
|
+
:packages: numpy
|
|
67
|
+
|
|
68
|
+
.. py-repl::
|
|
69
|
+
:no-header:
|
|
70
|
+
|
|
71
|
+
>>> import math
|
|
72
|
+
>>> math.sqrt(16)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Directive options
|
|
76
|
+
|
|
77
|
+
Most options drive [pyrepl-web](https://github.com/chrizzFTD/pyrepl-web)'s attributes, with a few exceptions unique to this extension:
|
|
78
|
+
|
|
79
|
+
| Option | Description | `pyrepl-web` attr? |
|
|
80
|
+
|--------|-------------|------------------|
|
|
81
|
+
| `:theme:` | Color theme (`catppuccin-mocha`, `catppuccin-latte`) | ✅ |
|
|
82
|
+
| `:packages:` | Comma-separated PyPI packages to preload | ✅ |
|
|
83
|
+
| `:repl-title:` | Title in the REPL header | ✅ |
|
|
84
|
+
| `:src:` | Path to a Python startup script | ✅ |
|
|
85
|
+
| `:replay:` | Replay `:src:` with interactive prompts instead of silent load | ✅ |
|
|
86
|
+
| `:silent:` | Keep `:src:` silent even when combined with a directive body | ❌ |
|
|
87
|
+
| `:strip-prompts:` | Strip ``>>>`` / ``...`` prefixes from directive body | ❌ |
|
|
88
|
+
| `:no-header:` | Hide the header bar | ✅ |
|
|
89
|
+
| `:no-buttons:` | Hide copy/clear buttons | ✅ |
|
|
90
|
+
| `:readonly:` | Disable input | ✅ |
|
|
91
|
+
| `:no-banner:` | Hide the Python version banner | ✅ |
|
|
92
|
+
|
|
93
|
+
Directive body content (inline Python in the `.. py-repl::` block) is also extension-only: it is written to `_static/pyrepl/` at build time and emitted as `replay-src`.
|
|
94
|
+
|
|
95
|
+
Optional Sphinx config:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
pyrepl_js = "../pyrepl.js" # default; path to the pyrepl-web loader script
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Updating pyrepl-web
|
|
102
|
+
|
|
103
|
+
Since [chrizzFTD/pyrepl-web](https://github.com/chrizzFTD/pyrepl-web) is a fork, this sphinx extension vendors the JavaScript assets for easier distribution. To update them, run:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
python scripts/vendor_repl.py
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The `grill` branch is used by default. Use the `branch` argument to specify a different one:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
python scripts/vendor_repl.py --branch cursor/repl-startup-replay-2e3f
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
This requires [git](https://git-scm.com/) and [Bun](https://bun.sh/).
|
|
116
|
+
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# sphinx-pyrepl-web
|
|
2
|
+
|
|
3
|
+
Sphinx extension to embed [pyrepl-web](https://github.com/chrizzFTD/pyrepl-web) in documentation.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install sphinx-pyrepl-web
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For development:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install -e ".[test,docs]"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Add the extension to the target project's `conf.py`:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
extensions = [
|
|
23
|
+
"sphinx_pyrepl_web",
|
|
24
|
+
]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Embed a REPL with the `py-repl` directive:
|
|
28
|
+
|
|
29
|
+
```rst
|
|
30
|
+
.. py-repl::
|
|
31
|
+
|
|
32
|
+
.. py-repl::
|
|
33
|
+
:theme: catppuccin-latte
|
|
34
|
+
:no-header:
|
|
35
|
+
|
|
36
|
+
.. py-repl::
|
|
37
|
+
:src: setup.py
|
|
38
|
+
:packages: numpy
|
|
39
|
+
|
|
40
|
+
.. py-repl::
|
|
41
|
+
:no-header:
|
|
42
|
+
|
|
43
|
+
>>> import math
|
|
44
|
+
>>> math.sqrt(16)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Directive options
|
|
48
|
+
|
|
49
|
+
Most options drive [pyrepl-web](https://github.com/chrizzFTD/pyrepl-web)'s attributes, with a few exceptions unique to this extension:
|
|
50
|
+
|
|
51
|
+
| Option | Description | `pyrepl-web` attr? |
|
|
52
|
+
|--------|-------------|------------------|
|
|
53
|
+
| `:theme:` | Color theme (`catppuccin-mocha`, `catppuccin-latte`) | ✅ |
|
|
54
|
+
| `:packages:` | Comma-separated PyPI packages to preload | ✅ |
|
|
55
|
+
| `:repl-title:` | Title in the REPL header | ✅ |
|
|
56
|
+
| `:src:` | Path to a Python startup script | ✅ |
|
|
57
|
+
| `:replay:` | Replay `:src:` with interactive prompts instead of silent load | ✅ |
|
|
58
|
+
| `:silent:` | Keep `:src:` silent even when combined with a directive body | ❌ |
|
|
59
|
+
| `:strip-prompts:` | Strip ``>>>`` / ``...`` prefixes from directive body | ❌ |
|
|
60
|
+
| `:no-header:` | Hide the header bar | ✅ |
|
|
61
|
+
| `:no-buttons:` | Hide copy/clear buttons | ✅ |
|
|
62
|
+
| `:readonly:` | Disable input | ✅ |
|
|
63
|
+
| `:no-banner:` | Hide the Python version banner | ✅ |
|
|
64
|
+
|
|
65
|
+
Directive body content (inline Python in the `.. py-repl::` block) is also extension-only: it is written to `_static/pyrepl/` at build time and emitted as `replay-src`.
|
|
66
|
+
|
|
67
|
+
Optional Sphinx config:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
pyrepl_js = "../pyrepl.js" # default; path to the pyrepl-web loader script
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Updating pyrepl-web
|
|
74
|
+
|
|
75
|
+
Since [chrizzFTD/pyrepl-web](https://github.com/chrizzFTD/pyrepl-web) is a fork, this sphinx extension vendors the JavaScript assets for easier distribution. To update them, run:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
python scripts/vendor_repl.py
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The `grill` branch is used by default. Use the `branch` argument to specify a different one:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
python scripts/vendor_repl.py --branch cursor/repl-startup-replay-2e3f
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
This requires [git](https://git-scm.com/) and [Bun](https://bun.sh/).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from datetime import date
|
|
2
|
+
|
|
3
|
+
from sphinx_pyrepl_web import __version__
|
|
4
|
+
|
|
5
|
+
project = "sphinx-pyrepl-web"
|
|
6
|
+
version = __version__
|
|
7
|
+
author = "Christian López Barrón"
|
|
8
|
+
copyright = f"{date.today().year}, {author}"
|
|
9
|
+
|
|
10
|
+
extensions = [
|
|
11
|
+
"myst_parser",
|
|
12
|
+
"sphinx_pyrepl_web",
|
|
13
|
+
]
|
|
14
|
+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
|
|
15
|
+
|
|
16
|
+
html_sidebars = {
|
|
17
|
+
"**": [
|
|
18
|
+
"about.html",
|
|
19
|
+
"localtoc.html",
|
|
20
|
+
],
|
|
21
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Examples
|
|
2
|
+
========
|
|
3
|
+
|
|
4
|
+
Basic REPL
|
|
5
|
+
----------
|
|
6
|
+
|
|
7
|
+
.. code-block:: rst
|
|
8
|
+
|
|
9
|
+
.. py-repl::
|
|
10
|
+
|
|
11
|
+
.. py-repl::
|
|
12
|
+
|
|
13
|
+
Light theme, minimal
|
|
14
|
+
--------------------
|
|
15
|
+
|
|
16
|
+
.. code-block:: rst
|
|
17
|
+
|
|
18
|
+
.. py-repl::
|
|
19
|
+
:theme: catppuccin-latte
|
|
20
|
+
:no-header:
|
|
21
|
+
:no-banner:
|
|
22
|
+
|
|
23
|
+
.. py-repl::
|
|
24
|
+
:theme: catppuccin-latte
|
|
25
|
+
:no-header:
|
|
26
|
+
:no-banner:
|
|
27
|
+
|
|
28
|
+
Startup script
|
|
29
|
+
--------------
|
|
30
|
+
|
|
31
|
+
The ``:src:`` option loads a Python script into the REPL namespace. If the script
|
|
32
|
+
defines a ``setup()`` function, its output is shown when the REPL starts.
|
|
33
|
+
|
|
34
|
+
.. code-block:: rst
|
|
35
|
+
|
|
36
|
+
.. py-repl::
|
|
37
|
+
:src: _static/setup.py
|
|
38
|
+
|
|
39
|
+
.. py-repl::
|
|
40
|
+
:src: _static/setup.py
|
|
41
|
+
|
|
42
|
+
The startup script:
|
|
43
|
+
|
|
44
|
+
.. literalinclude:: _static/setup.py
|
|
45
|
+
:language: python
|
|
46
|
+
|
|
47
|
+
Replay session
|
|
48
|
+
--------------
|
|
49
|
+
|
|
50
|
+
Inline directive content is replayed with ``>>>`` prompts, syntax highlighting,
|
|
51
|
+
and live output. Doctest-style ``>>>`` prefixes are stripped automatically.
|
|
52
|
+
|
|
53
|
+
.. code-block:: rst
|
|
54
|
+
|
|
55
|
+
.. py-repl::
|
|
56
|
+
:no-header:
|
|
57
|
+
:no-banner:
|
|
58
|
+
|
|
59
|
+
>>> x = 2 + 2
|
|
60
|
+
>>> print(f"{x=}")
|
|
61
|
+
>>> x * 10
|
|
62
|
+
|
|
63
|
+
.. py-repl::
|
|
64
|
+
:no-header:
|
|
65
|
+
:no-banner:
|
|
66
|
+
|
|
67
|
+
>>> x = 2 + 2
|
|
68
|
+
>>> print(f"{x=}")
|
|
69
|
+
>>> x * 10
|
|
70
|
+
|
|
71
|
+
Combine a silent bootstrap file with a visible replay body:
|
|
72
|
+
|
|
73
|
+
.. code-block:: rst
|
|
74
|
+
|
|
75
|
+
.. py-repl::
|
|
76
|
+
:src: _static/setup.py
|
|
77
|
+
:no-header:
|
|
78
|
+
|
|
79
|
+
>>> print(message)
|
|
80
|
+
|
|
81
|
+
.. py-repl::
|
|
82
|
+
:src: _static/setup.py
|
|
83
|
+
:no-header:
|
|
84
|
+
|
|
85
|
+
>>> print(message)
|
|
86
|
+
|
|
87
|
+
Use ``:replay:`` on ``:src:`` to replay a file with prompts instead of silent load:
|
|
88
|
+
|
|
89
|
+
.. code-block:: rst
|
|
90
|
+
|
|
91
|
+
.. py-repl::
|
|
92
|
+
:src: _static/replay_demo.py
|
|
93
|
+
:replay:
|
|
94
|
+
:no-header:
|
|
95
|
+
:no-banner:
|
|
96
|
+
|
|
97
|
+
.. py-repl::
|
|
98
|
+
:src: _static/replay_demo.py
|
|
99
|
+
:replay:
|
|
100
|
+
:no-header:
|
|
101
|
+
:no-banner:
|
|
102
|
+
|
|
103
|
+
The replay script:
|
|
104
|
+
|
|
105
|
+
.. literalinclude:: _static/replay_demo.py
|
|
106
|
+
:language: python
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["flit_core >=3.2,<4"]
|
|
3
|
+
build-backend = "flit_core.buildapi"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sphinx-pyrepl-web"
|
|
7
|
+
authors = [{name = "Christian López Barrón", email = "chris.gfz@gmail.com"}]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
license = {file = "LICENSE"}
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 4 - Beta",
|
|
12
|
+
"Framework :: Sphinx :: Extension",
|
|
13
|
+
"License :: OSI Approved :: MIT License",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3.12",
|
|
16
|
+
"Programming Language :: Python :: 3.13",
|
|
17
|
+
"Programming Language :: Python :: 3.14",
|
|
18
|
+
"Topic :: Documentation",
|
|
19
|
+
]
|
|
20
|
+
keywords = ["sphinx", "pyrepl", "pyodide", "repl"]
|
|
21
|
+
dynamic = ["version", "description"]
|
|
22
|
+
requires-python = ">=3.12"
|
|
23
|
+
dependencies = [
|
|
24
|
+
"sphinx>9",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Home = "https://github.com/chrizzFTD/sphinx-pyrepl-web"
|
|
29
|
+
Documentation = "https://sphinx-pyrepl-web.readthedocs.io/"
|
|
30
|
+
Repository = "https://github.com/chrizzFTD/sphinx-pyrepl-web"
|
|
31
|
+
Issues = "https://github.com/chrizzFTD/sphinx-pyrepl-web/issues"
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
test = [
|
|
35
|
+
"pytest",
|
|
36
|
+
"sphinx-pytest",
|
|
37
|
+
]
|
|
38
|
+
docs = [
|
|
39
|
+
"myst-parser",
|
|
40
|
+
]
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Vendor pyrepl-web build artifacts from chrizzFTD/pyrepl-web (grill branch)."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import shutil
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
import tempfile
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
REPO = "https://github.com/chrizzFTD/pyrepl-web.git"
|
|
14
|
+
DEFAULT_BRANCH = "grill"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def run(cmd: list[str], *, cwd: Path | None = None) -> None:
|
|
18
|
+
print(f"+ {' '.join(cmd)}")
|
|
19
|
+
subprocess.run(cmd, cwd=cwd, check=True)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def require_tool(name: str) -> None:
|
|
23
|
+
if shutil.which(name) is None:
|
|
24
|
+
sys.exit(f"error: {name!r} not found on PATH")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def main() -> None:
|
|
28
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
29
|
+
parser.add_argument(
|
|
30
|
+
"--asset-dir",
|
|
31
|
+
type=Path,
|
|
32
|
+
default=Path(__file__).resolve().parent.parent / "sphinx_pyrepl_web" / "pyrepl",
|
|
33
|
+
help="Directory to write vendored assets into",
|
|
34
|
+
)
|
|
35
|
+
parser.add_argument(
|
|
36
|
+
"--branch",
|
|
37
|
+
default=DEFAULT_BRANCH,
|
|
38
|
+
help=f"pyrepl-web branch to vendor (default: {DEFAULT_BRANCH})",
|
|
39
|
+
)
|
|
40
|
+
args = parser.parse_args()
|
|
41
|
+
asset_dir: Path = args.asset_dir
|
|
42
|
+
branch: str = args.branch
|
|
43
|
+
|
|
44
|
+
require_tool("git")
|
|
45
|
+
require_tool("bun")
|
|
46
|
+
|
|
47
|
+
with tempfile.TemporaryDirectory(prefix="vendor-pyrepl-") as tmp:
|
|
48
|
+
clone_dir = Path(tmp) / "pyrepl-web"
|
|
49
|
+
run(
|
|
50
|
+
[
|
|
51
|
+
"git",
|
|
52
|
+
"clone",
|
|
53
|
+
"--depth",
|
|
54
|
+
"1",
|
|
55
|
+
"--branch",
|
|
56
|
+
branch,
|
|
57
|
+
REPO,
|
|
58
|
+
str(clone_dir),
|
|
59
|
+
]
|
|
60
|
+
)
|
|
61
|
+
commit = subprocess.check_output(
|
|
62
|
+
["git", "rev-parse", "HEAD"],
|
|
63
|
+
cwd=clone_dir,
|
|
64
|
+
text=True,
|
|
65
|
+
).strip()
|
|
66
|
+
run(["bun", "install"], cwd=clone_dir)
|
|
67
|
+
run(["bun", "run", "build"], cwd=clone_dir)
|
|
68
|
+
|
|
69
|
+
dist = clone_dir / "dist"
|
|
70
|
+
if not dist.is_dir():
|
|
71
|
+
sys.exit(f"error: build did not produce {dist}")
|
|
72
|
+
|
|
73
|
+
if asset_dir.exists():
|
|
74
|
+
shutil.rmtree(asset_dir)
|
|
75
|
+
asset_dir.mkdir(parents=True)
|
|
76
|
+
copied = []
|
|
77
|
+
for src in sorted(dist.iterdir()):
|
|
78
|
+
if src.is_file():
|
|
79
|
+
shutil.copy2(src, asset_dir / src.name)
|
|
80
|
+
copied.append(src.name)
|
|
81
|
+
|
|
82
|
+
version_file = asset_dir / "version.txt"
|
|
83
|
+
version_file.write_text(f"{branch}@{commit}\n", encoding="utf-8")
|
|
84
|
+
copied.append("version.txt")
|
|
85
|
+
|
|
86
|
+
print(f"\nVendored {len(copied)} file(s) to {asset_dir}:")
|
|
87
|
+
for name in copied:
|
|
88
|
+
print(f" {name}")
|
|
89
|
+
print(f"Source: {REPO} ({branch}@{commit})")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
if __name__ == "__main__":
|
|
93
|
+
main()
|