Skip to main content

SphinxContrib RunCmd

Build Status Coverage Status Pip Version Python Version Code style: black

Sphinx RunCmd aims to allow you to place the output of arbitrary commands in your rst files, while also giving you greater flexibility in how the output is formatted.

Installation

sphinxcontrib-runcmd is available on PyPI. To install:

$ pip install sphinxcontrib-runcmd

Add runcmd to your Project

First you'll want to add sphinxcontrib.runcmd to your conf.py file in your docs folder:

extensions = ["sphinxcontrib.runcmd"]

From there, all you need to do is use runcmd as a directive in your documentation files.

.. runcmd:: python script.py -h
   :syntax: bash
   :prompt:

Options

This directive is basically a sub-directive of code-block, so it has all of code blocks directives such as:

  • linenos
  • dedent
  • lineno-start
  • emphasize-lines
  • caption
  • class
  • name

This directive builds upon that and adds the following:

  • syntax: str
    • Since we're using the arguments section for a command we can't actually pass the syntax we want to the code-block in the arguments. Therefore you can set it in the options which will then get passed into the code-block to colorize your commands output.
  • replace: str
    • Takes in a comma separated list of regex pattern/replace,pattern/replace and applies it to the output in that order.
  • prompt: bool
    • Display the command prompt in the output
  • dedent-output: int
    • Will dedent the output only by the int value you specify. Will not dedent the prompt if specified. Be careful, because the code-block dedent will be applied on top of this dedent if both are set in the options.

Replace Option

The replace option uses the CSV package to parse the string, thus you can wrap your replacements in double quotes if you want to use commas and whatnot.

You also need to double escape any forward slashes, but you can single escape quotes.

.. runcmd:: python test.py -h
  :replace: "this\\/is\\/a\\/path/now\\/its\\/another\\/path","\"/'"

The first replacement will replace this/is/a/path with now/its/another/path.

The second replacement will replace " with '.

License

sphinxcontrib-runcmd is provided under an MIT License.

Metadata

Release files for sphinxcontrib-runcmd 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinxcontrib-runcmd 0.2.0
File Size Uploaded
sphinxcontrib-runcmd-0.2.0.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sphinxcontrib-runcmd 0.2.0
File Interpreter ABI Platform
sphinxcontrib_runcmd-0.2.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 11.4 kB

Release files / sphinxcontrib-runcmd-0.2.0.tar.gz

Download URL sphinxcontrib-runcmd-0.2.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3551c389d9c5fe82d693c7222feb9658b1a1a5a1abcb0063e8385e5528c64c76
BLAKE2b-256 checksum
How to use checksums
a2036eb30814c9839f36131284a46ec9fc39d7bd356078648bc7125d5d1c05e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

Release files / sphinxcontrib_runcmd-0.2.0-py2.py3-none-any.whl

Download URL sphinxcontrib_runcmd-0.2.0-py2.py3-none-any.whl
Size 6.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7b739b68e27210b4c7c12ba16e5b3da7b313c49991401f896d29bea0f0771934
BLAKE2b-256 checksum
How to use checksums
83d967a79080b5d9fcb367470af9e525a9c53122e95744665de09462dcd676d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page