Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 6 days 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
- Created: 2021-04-18T15:32:38.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-21T21:20:16.000Z (25 days ago)
- Last Synced: 2024-10-22T16:43:15.347Z (24 days 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
[![Tests](https://github.com/cphyc/pre-commit-all-the-way-down/actions/workflows/python-package.yml/badge.svg)](https://github.com/cphyc/pre-commit-all-the-way-down/actions/workflows/python-package.yml)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/cphyc/pre-commit-all-the-way-down/main.svg)](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
```