Pre-commit hook to sanitize and restore magic commands for code formatters like Black
Handles magic commands induced into .py files by Databricks notebooks, such as:
%load_ext autoreload
%autoreload 2
Firstly blackmagic-sanitize is run to make .py backups, comment out the magic commands, then a formatter hook can be run. Finally, blackmagic-restore unpacks the original .py files from backups.
.pre-commit-hooks.yaml
repos:
- repo: https://github.com/MarvinHerzogTE/black-magic
rev: 0.1.6
hooks:
- id: blackmagic
# All black arguments are valid
args: [--line-length=120, --diff]