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.6.tar.gz (42.3 kB view details)

Uploaded Source

Built Distribution

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

blackdoc-0.4.6-py3-none-any.whl (40.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for blackdoc-0.4.6.tar.gz
Algorithm Hash digest
SHA256 9cce04cd898ed0ceb1c423836e62024e1d118a38ee5f760b931cadf7761b964f
MD5 af070ab8d53f1e38eeb55abc3edd2ef7
BLAKE2b-256 313b2ae2120a479975c34022d49e0139a472cda17488043e5e9496e0e1786164

See more details on using hashes here.

Provenance

The following attestation bundles were made for blackdoc-0.4.6.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.6-py3-none-any.whl.

File metadata

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

File hashes

Hashes for blackdoc-0.4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 85d78ae44d07e8d85a318276813abfa8b8bcf236b47983aa203f692e139533ab
MD5 ec26cf90a7e14a729fc7b086c9874219
BLAKE2b-256 675bfe2e48b50f963e4381b03de0652cdfa9b912af207bcf6f3e04e248629896

See more details on using hashes here.

Provenance

The following attestation bundles were made for blackdoc-0.4.6-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 Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page