fprettify

raw JSON →
0.3.7 verified Fri May 01 auth: no python

fprettify is an auto-formatter for modern Fortran source code. It automatically indents code, aligns statements, and supports Fortran 2003/2008 features. The current version is 0.3.7, released with Python 3 support only (dropped Python 2). Release cadence is irregular; latest release in 2021.

pip install fprettify
error ModuleNotFoundError: No module named 'configargparse'
cause Using --config-file without installing the optional dependency.
fix
pip install configargparse or pip install fprettify[config]
error AttributeError: module 'fprettify' has no attribute 'FortranFormatter'
cause Incorrect import: import fprettify instead of from fprettify import fprettify.
fix
Use: from fprettify import fprettify
error TypeError: format_file() missing 1 required positional argument: 'filename'
cause Calling format_file without arguments.
fix
Provide the file path: formatter.format_file('myfile.f90')
breaking Python 2 support was dropped in v0.3.7. If you are on Python 2, you must use an older version.
fix Use Python 3 or pin to fprettify==0.3.6 if Python 2 is required.
gotcha By default, fprettify overwrites files in place. There is no backup unless you use version control.
fix Use the --diff flag (CLI) or check the diff before committing. In code, copy files beforehand.
gotcha Optional dependency configargparse is required for config file support. Without it, --config-file fails silently or errors.
fix Install fprettify with extras: pip install fprettify[config]

Basic usage: import the FortranFormatter class, then call format_file or format_directory.

from fprettify import fprettify
formatter = fprettify.FortranFormatter()
# Format a single file
formatter.format_file('source.f90')
# Or format a directory recursively
formatter.format_directory('.')