Skip to main content

A Sphinx extension for embedding pyrepl-web Python REPLs in documentation.

Project description

sphinx-pyrepl-web

Sphinx extension to embed pyrepl-web in documentation.

Install

pip install sphinx-pyrepl-web

For development:

pip install -e ".[test,docs]"

Usage

Add the extension to the target project's conf.py:

extensions = [
    "sphinx_pyrepl_web",
]

Embed a REPL with the py-repl directive:

.. py-repl::

.. py-repl::
   :theme: catppuccin-latte
   :no-header:

.. py-repl::
   :src: setup.py
   :packages: numpy

.. py-repl::
   :no-header:

   >>> import math
   >>> math.sqrt(16)

Directive options

All options drive pyrepl-web's attributes, with the exception of silent:

Option Description
:theme: Color theme (catppuccin-mocha, catppuccin-latte)
:packages: Comma-separated PyPI packages to preload
:repl-title: Title in the REPL header
:src: Path to a Python startup script
:replay: Replay :src: with interactive prompts instead of silent load
:silent: Keep :src: silent even when combined with a directive body
:no-header: Hide the header bar
:no-buttons: Hide copy/clear buttons
:readonly: Disable input
:no-banner: Hide the Python version banner

Python code within the .. py-repl:: directive is written to _static/pyrepl/ at build time and emitted as replay-src.

Optional Sphinx config:

pyrepl_js = "../pyrepl.js"  # default; path to the pyrepl-web loader script
pyrepl_doctest_blocks = False  # default; see Docstring conversion below
pyrepl_autodoc_bootstrap = True  # default; silent :src: bootstrap for autodoc REPLs

Docstring conversion

Converting doctest examples from docstrings into interactive REPLs is opt-in with sphinx.ext.autodoc:

# conf.py
extensions = [
    "sphinx.ext.autodoc",
    "sphinx_pyrepl_web",
]
pyrepl_doctest_blocks = "autodoc"
pyrepl_doctest_blocks options
False (default) Disable autodoc conversion
"autodoc" Convert doctests found by autodoc
"all" Transform every doctest block found
pyrepl_autodoc_bootstrap options
True (default) Bootstrap REPL: in-tree modules via silent :src:, packages via packages=
False Replay doctest input only; documented names are not pre-defined

Updating pyrepl-web

Since chrizzFTD/pyrepl-web is a fork, this sphinx extension vendors the JavaScript assets for easier distribution. To update them, run:

python scripts/vendor_repl.py

The grill branch is used by default. Use the branch argument to specify a different one:

python scripts/vendor_repl.py --branch custom/feature-branch

This requires git and Bun.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_pyrepl_web-0.2.0.tar.gz (287.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinx_pyrepl_web-0.2.0-py3-none-any.whl (283.7 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_pyrepl_web-0.2.0.tar.gz.

File metadata

  • Download URL: sphinx_pyrepl_web-0.2.0.tar.gz
  • Upload date:
  • Size: 287.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for sphinx_pyrepl_web-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5cb764d96d8345c8fae8164409b85818062776497917bcec97a4cd58832e587d
MD5 de7c46ec6159f45fa9f1bfe1e2f1c2a8
BLAKE2b-256 84d70ae7e587d40afb2713700c983518a1000191c873a84f19a1ded449ba60ac

See more details on using hashes here.

File details

Details for the file sphinx_pyrepl_web-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_pyrepl_web-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0aec50d518b5e60a28889d0135d56b340a63f9b85c82c98fae16598f71ca8815
MD5 48d5a819eaeb57d4703f62eede4dc8c6
BLAKE2b-256 134df8f3883df4f8c0f98d3e4b22e1ef62fc577c8017fcc0a211b31b937c9297

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page