Skip to main content

An uncompromising Fortran formatter, inspired by Black

Project description

Sable logo

An uncompromising Fortran formatter, inspired by Black.

"So it goes." — Kurt Vonnegut, Slaughterhouse-Five

Sable enforces one consistent style for modern free-form Fortran, so you can focus on code instead of formatting.

Installation

pip install sable-fortran

Usage

# Format a file or directory in place
sable my_module.f90
sable src/

# Check formatting without changing files (exit 1 if changes are needed)
sable --check src/

# Preview changes as a unified diff
sable --diff src/

# Check + diff together (non-zero if any file would change)
sable --check --diff src/

# Migration mode: only low-risk whitespace/layout changes
sable --safe src/

# Format piped input (Sable reads stdin when no files are passed)
cat code.f90 | sable

# Optional: label stdin input in diagnostics
cat code.f90 | sable --stdin-filename my_module.f90

Directory scans include .f90, .F90, .f95, .F95, .f03, .F03, .f08, and .F08 files.

What Sable changes

  • Normalizes keyword/operator style (INTEGER -> integer, .EQ. -> ==, endif -> end if by default).
  • Applies consistent spacing and indentation.
  • Wraps long lines deterministically (including one-argument-per-line layouts).
  • Canonicalizes declarations (::, stable attribute order).
  • Preserves directives and formatting-off regions (! sable: off / on).
  • Guarantees idempotent output with exactly one trailing newline.
! Before
IF(A .EQ. B)THEN
CALL compute(alpha_input,beta_input,gamma_input,result_output)
ENDIF

! After
if (A == B) then
   call compute(    &
      alpha_input,  &
      beta_input,   &
      gamma_input,  &
      result_output &
   )
end if

Formatting rules (quick reference)

Old New
.EQ. ==
.NE. /=
.LT. <
.LE. <=
.GT. >
.GE. >=
  • Keywords are lower-case by default (--keyword-case upper to change).
  • Names are preserved exactly as written.
  • End keywords use spaced forms by default (end if, end do; configurable).
  • .AND., .OR., .NOT., .EQV., .NEQV. are preserved.
  • One space around most binary operators; no spaces around % or **.
  • No spaces inside parens/brackets.
  • Two spaces before inline comments (x = 1 ! note).
  • Default indent is 3 spaces (--indent-width to change).
  • Long lines wrap with & using deterministic split rules (--line-length).
  • Multi-statement lines split into one statement per line.

Configuration

Sable intentionally exposes few options:

Flag Default Description
--line-length, -l 100 Max line length
--indent-width, -i 3 Spaces per indent level
--keyword-case lower lower or upper
--end-keyword-form spaced spaced or compact
--no-normalize-operators off Keep old-style relational operators
--safe off Migration mode; skip non-safe syntax/canonicalization rewrites
--quiet off Suppress non-error status output

Name

Sable is heraldic for black — a nod to Black, the Python formatter that inspired this project.

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

sable_fortran-0.1.4.tar.gz (45.3 kB view details)

Uploaded Source

Built Distribution

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

sable_fortran-0.1.4-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

Details for the file sable_fortran-0.1.4.tar.gz.

File metadata

  • Download URL: sable_fortran-0.1.4.tar.gz
  • Upload date:
  • Size: 45.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for sable_fortran-0.1.4.tar.gz
Algorithm Hash digest
SHA256 1dce98343280f55ce6206786cdefd6032eefc0b779f555888467e5adf17cbdd5
MD5 789d7f2d57b8404611fcf3db651b462a
BLAKE2b-256 f36e686e981866051d0fd5582b9261d0022af0f630cadfbdb8022b2a91355b83

See more details on using hashes here.

File details

Details for the file sable_fortran-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: sable_fortran-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 30.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for sable_fortran-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2245d9b4aa270d2165049272b477c7f9e5d88e9400393b0d499d79355713f6db
MD5 a8560701e80bb227734d9c48eb8d191d
BLAKE2b-256 aa07995ede0b49af0d63a332c90c1018b8fbd83762199dfeddc87b4fcf7b2d6d

See more details on using hashes here.

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