https://github.com/cphyc/pre-commit-all-the-way-down
Apply pre-commit hooks on chunks of file as a pre-commit hook
https://github.com/cphyc/pre-commit-all-the-way-down
Last synced: about 1 year ago
JSON representation
Apply pre-commit hooks on chunks of file as a pre-commit hook
- Host: GitHub
- URL: https://github.com/cphyc/pre-commit-all-the-way-down
- Owner: cphyc
- Archived: true
- Created: 2021-04-18T15:32:38.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-12-16T21:15:15.000Z (over 1 year ago)
- Last Synced: 2025-02-28T21:24:48.427Z (over 1 year ago)
- Language: Python
- Size: 222 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Pre-commit all the way down
[](https://github.com/cphyc/pre-commit-all-the-way-down/actions/workflows/python-package.yml)
[](https://results.pre-commit.ci/latest/github/neutrinoceros/cphyc/pre-commit-all-the-way-down)
pre-commit hooks to run [`pre-commit`](https://pypi.org/project/pre-commit/) on
code snippets embeded in files that don't match the language used.
The primary (and currently only) application for this is to apply
Python-targeted hooks to Python snippets included in documentation files.
This project is inspired by the great
[`blacken-docs`](https://pypi.org/project/blacken-docs/).
## Install
The package is not available on Pypi yet. In the meantime it can be installed as
```shell
pip install git+https://github.com/cphyc/pre-commit-all-the-way-down.git#egg=pre_commit_all_the_way_down
```
or
```shell
git clone https://github.com/cphyc/pre-commit-all-the-way-down.git
cd pre-commit-all-the-way-down
pip install .
```
## Usage
### python-doc
This hook applies pre-commit hooks to Python blocks in `.rst` files.
It does so in 4 steps
1. extract Python code snippets
2. write their content to temporary files
3. run `pre-commit` hooks against these files
4. write back to the original file.
The executable has a single option, `--whitelist` which allows to explicitly list which `pre-commit` hooks will be run.
For example
```shell
# will apply all pre-commit hooks to the file
python-doc documentation.rst
# will only apply black & isort
python-doc documentation.rst --whitelist black --whitelist isort
```
## Usage with pre-commit
The package has been tailored to fit in the `pre-commit` machinery. To use it, add the following to your `.pre-commit-config.yaml` file
```yaml
- repo: https://github.com/cphyc/pre-commit-all-the-way-down
rev: v0.0.2
hooks:
- id: python-doc
```