Skip to main content

A fast, configurable Fortran formatter with Fypp, Doxygen, and OpenACC/OpenMP support

Project description

ffmt

PyPI CI License: MIT GitHub Marketplace

A fast, configurable Fortran formatter with support for Fypp, Doxygen, and OpenACC/OpenMP directives. Written in Rust. Installable via pip.

Installation

pip install ffmt

Or via Cargo:

cargo install ffmt

Usage

ffmt src/                        # format in-place
ffmt --check src/                # CI mode (exit 1 if changes needed)
ffmt --diff src/                 # show colored diff
ffmt -j 8 src/                   # parallel
cat file.fpp | ffmt -            # stdin/stdout
ffmt --range 10:50 file.fpp      # format only lines 10-50

What it does

  • Indentation -- scope-based indentation for all Fortran constructs
  • Whitespace -- consistent spacing around operators, commas, colons, parentheses
  • Keywords -- case normalization (IF -> if, ENDDO -> end do)
  • Continuation lines -- normalized with proportional re-indentation
  • Preprocessor -- Fypp (#:if, #:for), OpenACC (!$acc), OpenMP (!$omp) handled correctly

Configuration

Create ffmt.toml or add [tool.ffmt] to pyproject.toml:

indent-width = 4
line-length = 132
keyword-case = "lower"         # lower, upper, preserve
normalize-keywords = true      # enddo -> end do
named-ends = true              # end subroutine -> end subroutine s_foo
align-declarations = true      # align :: in consecutive declarations
unicode-to-ascii = true        # Greek/math symbols -> LaTeX in comments
rewrap-comments = true         # wrap long comments at line-length
rewrap-code = true             # wrap long code lines at line-length
space-after-comment = true     # !comment -> ! comment
collapse-double-spaces = true  # x  =  y -> x = y
keyword-paren-space = true     # if( -> if (
fypp-list-commas = true        # normalize commas in Fypp '[...]' args

[whitespace]
relational = true              # ==, /=, <, <=, >, >=
logical = true                 # .and., .or., .not.
plusminus = true                # binary +, -
multdiv = false                 # *, /
power = false                   # **
assignment = true               # =
declaration = true              # ::
comma = true                    # space after comma

All options have sensible defaults -- most projects need no config file at all.

Preserved as-is

  • String literals and inline expressions (${...}$, @{...}@)
  • Comment contents and Doxygen alignment (!<, !>, !!)
  • Continuation line structure
  • #ifdef/#endif blocks (no indentation change)

Editor integration

ffmt includes a built-in LSP server for real-time format-on-save:

ffmt --lsp

VS Code

{
    "fortran.formatting.formatter": "ffmt",
    "fortran.formatting.args": ["--stdin-filepath", "${file}", "-"]
}

Vim/Neovim

autocmd BufWritePost *.fpp,*.f90 silent !ffmt %
" Or: set formatprg=ffmt\ -

Neovim (LSP)

vim.lsp.start({
    name = "ffmt",
    cmd = { "ffmt", "--lsp" },
    root_dir = vim.fs.dirname(vim.fs.find({ "ffmt.toml", "pyproject.toml" }, { upward = true })[1]),
})

CI integration

GitHub Actions

- uses: sbryngelson/ffmt@v0.1.0
  with:
    args: "--check src/"

pre-commit

repos:
  - repo: https://github.com/sbryngelson/ffmt
    rev: v0.1.0
    hooks:
      - id: ffmt

Other Fortran Formatters

Formatter Language Status Notes
fprettify Python Unmaintained (last release 2020) Free-form only. Fypp support. Requires multiple passes for convergence.
findent C Active Indentation and fixed/free conversion. No whitespace normalization.
Codee Formatter Proprietary Active Commercial. Tree-sitter based. Fixed and free-form.
LFortran fmt Rust In development AST-based. Part of the LFortran compiler project.
Fortitude Rust Active Linter with auto-fix, not a full formatter. Tree-sitter based.
f90-mode Emacs Lisp Active Emacs built-in. Indentation only.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ffmt-0.2.0.tar.gz (52.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ffmt-0.2.0-py3-none-win_amd64.whl (1.4 MB view details)

Uploaded Python 3Windows x86-64

ffmt-0.2.0-py3-none-manylinux_2_34_x86_64.whl (1.8 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ x86-64

ffmt-0.2.0-py3-none-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file ffmt-0.2.0.tar.gz.

File metadata

  • Download URL: ffmt-0.2.0.tar.gz
  • Upload date:
  • Size: 52.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ffmt-0.2.0.tar.gz
Algorithm Hash digest
SHA256 05e6fb619fa74b80ef76f432e79fe1316564e2b9d0d1d63dad54bbfed1524041
MD5 0c3814cd8f47741f715475b5cba1279b
BLAKE2b-256 5a4771572c47a19a41ee754a98b11f81dd1c0f809f357c8737ec5f0d64d10155

See more details on using hashes here.

Provenance

The following attestation bundles were made for ffmt-0.2.0.tar.gz:

Publisher: release.yml on sbryngelson/ffmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ffmt-0.2.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: ffmt-0.2.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ffmt-0.2.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 bd8f3b739dd31359c89d8c43851b4eaf3cfac5cc7040d493e22f5cd1b18b92e2
MD5 bebab3c21c90f5376da43f80b78db712
BLAKE2b-256 2cf21779066280fbaf18d792cd42008cd0a2de691ace2c774822407463f1febf

See more details on using hashes here.

Provenance

The following attestation bundles were made for ffmt-0.2.0-py3-none-win_amd64.whl:

Publisher: release.yml on sbryngelson/ffmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ffmt-0.2.0-py3-none-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: ffmt-0.2.0-py3-none-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: Python 3, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ffmt-0.2.0-py3-none-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 561c1f841d223e5fc4dcac922c4f74eec86bef3ab274092c269ca4fc85041d97
MD5 c2338a91c280df00e58375ad87e6b695
BLAKE2b-256 5a300f4b9bd76bee1644873b82dd314c4fd43e0aebc666f176f0881bbd35932b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ffmt-0.2.0-py3-none-manylinux_2_34_x86_64.whl:

Publisher: release.yml on sbryngelson/ffmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ffmt-0.2.0-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: ffmt-0.2.0-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ffmt-0.2.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ad442fb313fac598226c789196d7152a3f5f3bdacda04195f0cf0d8888607981
MD5 1505c91b0dc061712a5392d8510fab25
BLAKE2b-256 b09cbd87af8171c837f9b2e37d669cdbbe639c60abad581ee18dfc62584736f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for ffmt-0.2.0-py3-none-macosx_11_0_arm64.whl:

Publisher: release.yml on sbryngelson/ffmt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page