Skip to main content

Run `black` on python code blocks in documentation files

Project description

Build Status Azure DevOps coverage

blacken-docs

Run black on python code blocks in documentation files.

install

pip install blacken-docs

usage

blacken-docs provides a single executable (blacken-docs) which will modify .rst / .md / .tex files in place.

It currently supports the following black options:

  • -l / --line-length
  • -t / --target-version
  • -S / --skip-string-normalization

Following additional parameters can be used:

  • -E / --skip-errors

blacken-docs will format code in the following block types:

(markdown)

    ```python
    def hello():
        print("hello world")
    ```

(rst)

    .. code-block:: python

        def hello():
            print("hello world")

(latex)

\begin{minted}{python}
def hello():
    print("hello world")
\end{minted}

(latex with pythontex)

\begin{pycode}
def hello():
    print("hello world")
\end{pycode}

(markdown/rst in python docstrings)

def f():
    """docstring here

    .. code-block:: python

        print("hello world")

    ```python
    print("hello world")
    ```
    """

usage with pre-commit

See pre-commit for instructions

Sample .pre-commit-config.yaml:

-   repo: https://github.com/asottile/blacken-docs
    rev: v1.8.0
    hooks:
    -   id: blacken-docs
        additional_dependencies: [black==...]

Since black is currently a moving target, it is suggested to pin black to a specific version using additional_dependencies.

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

blacken_docs-1.8.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

blacken_docs-1.8.0-py2.py3-none-any.whl (4.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file blacken_docs-1.8.0.tar.gz.

File metadata

  • Download URL: blacken_docs-1.8.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

File hashes

Hashes for blacken_docs-1.8.0.tar.gz
Algorithm Hash digest
SHA256 1a7ddc1525dee3accaeb53a61d9f80791c2d8a27553388f5a2f11fc1c91b4acd
MD5 57e1b3eb67fd9f1b83d032483741fb0b
BLAKE2b-256 f0d81004ba3168d9f2c9fd933a1a22357e939f222ab9437f29b0497a93c073cc

See more details on using hashes here.

File details

Details for the file blacken_docs-1.8.0-py2.py3-none-any.whl.

File metadata

  • Download URL: blacken_docs-1.8.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

File hashes

Hashes for blacken_docs-1.8.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ed41c95311286f7a74a3400fd6bb746c0fee571772d875d56a2462213841be02
MD5 ffc98c341fe74dfb76eaadd5b0881e6d
BLAKE2b-256 2376ce5a3a55a664fe9c4794ec8450d1da5fc686a87e48b8c8646cff37aef884

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