Skip to main content

run black on documentation code snippets

Project description

https://github.com/keewis/blackdoc/workflows/CI/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.3.9.tar.gz (39.0 kB view details)

Uploaded Source

Built Distribution

blackdoc-0.3.9-py3-none-any.whl (35.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: blackdoc-0.3.9.tar.gz
  • Upload date:
  • Size: 39.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for blackdoc-0.3.9.tar.gz
Algorithm Hash digest
SHA256 b1da5ca93550081fc3f1b34bfdc731431ee74c378ea63abb31771a222ef5d053
MD5 3cb247765e3b86fc871ceb4d72143d0c
BLAKE2b-256 2e3c7d47d200211adc793789ae9363096ed693a7ec1e7fd9afad49e0684070cc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blackdoc-0.3.9-py3-none-any.whl
  • Upload date:
  • Size: 35.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for blackdoc-0.3.9-py3-none-any.whl
Algorithm Hash digest
SHA256 2de4ad14993705e6b1fd89b0aa117566ac0c6980f218d6012f22d7cf6f5b2f34
MD5 8f4cc09bdd93e443ab701f3ea9c06fae
BLAKE2b-256 aac2d9e0cbc72dbf90d23514954d69db12b3b4e547038fbcdcf7a4e50799f530

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