Use findent as a pre-commit hook.
pre-commit, and:
- The
wfindent-conda
andfindent-conda
hooks requireconda
available onPATH
(ormamba
, withPRE_COMMIT_USE_MAMBA=1
). - The
wfindent-system
hook requireswfindent
available onPATH
. - The
findent-system
hook requiresfindent
available onPATH
.
Add one of the hooks defined in .pre-commit-hooks.yaml
to your .pre-commit-config.yaml
file.
For example:
repos:
- repo: https://github.com/zmoon/findent-pre-commit
rev: main
hooks:
- id: wfindent-system
To control which files get formatted, set
files: <regex>
to match them.
The current setting (\.[fF](90|95|03|08)$
) matches free-form sources files
according to GCC.
To pass args to findent
, use, for example:
args: [--indent=4, -r0]
There are multiple ways to achieve this:
-
for
findent-system
, use the--findent-version-pin
arg, which will check the version before runningargs: [--findent-version-pin=4.3.3]
-
for
findent-pypi
/wfindent-pypi
, pinfindent
inadditional_dependencies
additional_dependencies: [findent==4.3.1]
- findent-pypi releases can be found on GitHub
- releases since
4.2.6.post0
should work for Windows (in addition to Unix-like)
-
for
findent-conda
/wfindent-conda
, pinfindent
inadditional_dependencies
additional_dependencies: [findent==4.3.2]
- available versions can be found on conda-forge
-
for
wfindent-system
, there is currently no way to ensure a certainfindent
version is being used
To install the Python wrapper findent-wrapper
with pipx
:
pipx install https://github.com/zmoon/findent-pre-commit/archive/main.zip
Note that the wfindent
tool distributed with findent and referenced above provides in-place editing
using shell scripting.
findent-wrapper
adds a --diff
option (and maybe more options in the future...).
As an alternative to the wfindent-system
hook defined in this repo, it is possible
to use a local hook setup.
# .pre-commit-config.yaml
- repo: local
hooks:
- id: wfindent
name: Format Fortran code using findent
entry: wfindent
description: Uses system copy of wfindent available on PATH.
language: system
pass_filenames: true
files: \.[fF](90|95|03|08)$
types: [text]
require_serial: true
Note that findent
cannot be used in this way, since it only reads from STDIN.