Skip to main content

run black on documentation code snippets

Project description

https://github.com/keewis/blackdoc/actions/workflows/ci.yml/badge.svg?branch=main https://img.shields.io/badge/code%20style-black-000000.svg Documentation Status

blackdoc is a tool that applies black to code in documentation.

It was originally a rewrite of a gist and called black-doctest. In April 2020, it was renamed to blackdoc.

Installation

Dependencies:

Install it with:

python -m pip install blackdoc

Usage

The commandline interface supports two modes: checking and inplace reformatting.

python -m blackdoc --help

In inplace reformatting mode, it will reformat the doctest lines and write them back to disk:

# on explicitly mentioned files
python -m blackdoc file1.py file2.py
# on the whole directory
python -m blackdoc .

When checking, it will report the changed files but will not write them to disk:

python -m blackdoc --check .

It is also possible to use the entrypoint script:

blackdoc --help

pre-commit

This repository defines a pre-commit hook:

hooks:
...
- repo: https://github.com/keewis/blackdoc
  rev: 3.8.0
  hooks:
  - id: blackdoc

It is recommended to pin black in order to avoid having different versions for each contributor. To automatically synchronize this pin with the version of the black hook, use the blackdoc-autoupdate-black hook:

hooks:
...
- repo: https://github.com/psf/black
  rev: 23.10.1
  hooks:
  - id: black
...
- repo: https://github.com/keewis/blackdoc
  rev: 3.8.0
  hooks:
  - id: blackdoc
    additional_dependencies: ["black==23.10.1"]
  - id: blackdoc-autoupdate-black

Note that this hook is not run on pre-commit autoupdate.

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

blackdoc-0.4.1.tar.gz (40.9 kB view details)

Uploaded Source

Built Distribution

blackdoc-0.4.1-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

Details for the file blackdoc-0.4.1.tar.gz.

File metadata

  • Download URL: blackdoc-0.4.1.tar.gz
  • Upload date:
  • Size: 40.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for blackdoc-0.4.1.tar.gz
Algorithm Hash digest
SHA256 18a4ed8cfd2c5cdc2709583a5401f01e5d729e6d0624aeb27fd35fe879007348
MD5 83800d68d56729892affdf6cc8dfff00
BLAKE2b-256 476e08e9a12d95ef9dc607b5213424a96030db0a9a293bfaa36a86e715396978

See more details on using hashes here.

Provenance

The following attestation bundles were made for blackdoc-0.4.1.tar.gz:

Publisher: publish.yml on keewis/blackdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blackdoc-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: blackdoc-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 39.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for blackdoc-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a8452f05613d9a696d5d1e2f43872864127ed3c84e93f22c09a5e7643f445891
MD5 8eebb36eb94ad2d45793272a7cb4fcb1
BLAKE2b-256 ead464d542960e9756966d272d996fe18466d452b18218d60dd8828bb7bd2e7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for blackdoc-0.4.1-py3-none-any.whl:

Publisher: publish.yml on keewis/blackdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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