sphinx-computron
Sphinx-computron is an extension for Sphinx that allows a document author to insert arbitrary python code samples in code blocks, or run python code from python files on the filesystem. The output is interpreted as ReST, as if the output of the executed code was copy-pasted in-place into the document.
This was written as an alternative to other code execution functions which relied on doctest formats, and attempts to be more flexible, similar to literal-block and code-block statements.
The original author is JP Senior. His version of the package appears to be unmantained so I decided to salvage it by making a hard fork. The name had to be changed to avoid collisions with his version published on PyPI.
The package is available on PyPI as sphinx-computron.
Options
- filename
If specified, will load code from a file (relative to sphinx doc root) and prepend that to the directive’s content before its execution.
- argv
Passes the specified whitespace-separated arguments to the script. If specified: sys.argv = [filename] + argv.split(). If not specified: sys.argv = [filename].
computron-injection
Executing python code and parsing output as ReST:
.. computron-injection::
print('*This is interpreted as ReST!*')
Whatever is written into stdout is collected and the injected in-place into the document. Stderr is not captured.
Executing python code from a file
computron-injection also allows you to import a python file and execute it within a document. The path is specified relative to the source ReST file where the directive is encountered.
Running a Python file in the same directory:
.. computron-injection:: :filename: my_class.py
With arguments ['Hello', 'world!']:
.. computron-injection:: :filename: my_class.py :argv: Hello world!
Activating on Sphinx
To activate the extension, add it to your extensions variable in conf.py for your project.
Activating the extension in sphinx:
extensions.append('sphinx_computron')
Release files for sphinx-computron 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sphinx_computron-1.0.0.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sphinx_computron-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.9 kB
Release files / sphinx_computron-1.0.0.tar.gz
| Download URL | sphinx_computron-1.0.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4325d94b46ac95f92f4440e1c5ee6c90d84321b20870e40c5153faa1d6cbadbe
|
|
BLAKE2b-256 checksum How to use checksums |
9a1e51c961025101b53408150aa98552597529055e633ffaa7298e79a3076dfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.26.0 setuptools/57.4.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.7
|
Release files / sphinx_computron-1.0.0-py3-none-any.whl
| Download URL | sphinx_computron-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c9233bf69abe752ded8c1d21c175c2a36eda51e5b48123d6c67a14d21e230810
|
|
BLAKE2b-256 checksum How to use checksums |
9d7d34359f9c9a8667f3012a975018eee8ae3af3d426b9f1497e589a05b64576
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.26.0 setuptools/57.4.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.7
|