Skip to main content

Sphinx "runcmd" extension

Project description

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.

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

sphinxcontrib-runcmd-0.2.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

sphinxcontrib_runcmd-0.2.0-py2.py3-none-any.whl (6.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sphinxcontrib-runcmd-0.2.0.tar.gz.

File metadata

  • Download URL: sphinxcontrib-runcmd-0.2.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for sphinxcontrib-runcmd-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3551c389d9c5fe82d693c7222feb9658b1a1a5a1abcb0063e8385e5528c64c76
MD5 f83279160447eb14ba9168f3283d2851
BLAKE2b-256 a2036eb30814c9839f36131284a46ec9fc39d7bd356078648bc7125d5d1c05e8

See more details on using hashes here.

File details

Details for the file sphinxcontrib_runcmd-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: sphinxcontrib_runcmd-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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

File hashes

Hashes for sphinxcontrib_runcmd-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7b739b68e27210b4c7c12ba16e5b3da7b313c49991401f896d29bea0f0771934
MD5 b5deff6afc851000d9b86d4f7bd4001a
BLAKE2b-256 83d967a79080b5d9fcb367470af9e525a9c53122e95744665de09462dcd676d8

See more details on using hashes here.

Supported by

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