Skip to main content

Dimensional homogeneity checker for Fortran projects, with LSP support.

Project description

DimFort

preview

release License: MIT Python: 3.11+

Static unit-consistency checker for Fortran. You annotate declarations with the dimension they should carry, and DimFort verifies that assignments, arithmetic, intrinsics, and procedure calls all line up. Annotations are written as a custom Doxygen command, so a single source of truth feeds both the checker and your generated documentation.

real :: velocity  !< @unit{m/s}
real :: mass      !< @unit{kg}
real :: force     !< @unit{kg*m/s^2}

force = mass * velocity            ! diagnosed: force unit is kg, expected kg*m/s^2

Status: pre-alpha. End-to-end, these work today: the annotation scanner, attachment pass, the full H-series checker (H001–H004), intrinsics, user-defined function and subroutine calls, derived-type field access, rational ** exponents, multi-file worksets, a workspace-aware LSP server with live-edit diagnostics, hover, inlay hints, go-to-definition, code lens, code actions, completion, and a CLI that accepts files or directories.

Install

DimFort is published on PyPI as dimfort. It's a CLI tool with an entry point — install it isolated with pipx:

pipx install 'dimfort[lsp]'      # includes the LSP server extra
dimfort --version

The [lsp] extra pulls in pygls; omit it if you only want the CLI and never the language server.

On macOS with Homebrew Python: PEP 668 makes plain pip install refuse to touch Homebrew's site-packages. Use pipx as shown above, or install into a virtual environment. If pipx install says "command not found", run brew install pipx && pipx ensurepath first.

From source (contributors)

git clone https://github.com/ArrialVictor/DimFort.git
cd DimFort
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev,lsp]"

Requirements

Python ≥ 3.11. The Fortran parser (tree-sitter-fortran) is a runtime dependency installed automatically — no external compiler or subprocess needed for parsing. For .F90 files using CPP #-directives DimFort shells out to the system cpp if [parser] cpp_defines or [parser] include_paths are set in .dimfort.toml.

Usage

dimfort check path/to/file.f90       # check a single file
dimfort check path/to/project/       # walk a directory recursively
dimfort check path/...  --summary    # also print a per-file H/U count table
dimfort lsp                          # start the language server (stdio)

Exit code is 0 if no errors, 1 if any error-severity diagnostic was produced, 2 for usage / file / config errors. Warnings alone do not fail the run.

Diagnostic codes split into two families:

  • H-series (H001H004) — homogeneity violations: the math doesn't balance dimensionally. Real bugs.
  • U-series (U001, U002, U005U007, U010, U-conflict) — annotation / metadata problems: something's wrong with the annotations themselves, not the math.

Full reference: docs/usage.md.

Doxygen integration

Annotations are read from Doxygen comments (!> / !! preceding a declaration, or !< trailing it) and apply to every variable in a declaration list. To make Doxygen render them natively, add one line to your Doxyfile:

ALIASES += "unit{1}=\par Unit:^^\1"

Module-level constants follow the same notation:

!> @brief Gravitational acceleration.
!> @unit{m/s^2}
real, parameter :: g = 9.81

See docs/annotations.md for the full reference: unit-expression grammar, continuation-line forms, declaration lists, and the diagnostic codes the scanner can emit.

Documentation

Editor integrations

Thin LSP clients that wire dimfort lsp into common editors. Each lives in its own repository, releases on its own cadence, and shares the same feature surface (diagnostics, hover, inlay hints, go-to-definition, code actions, completion).

License

See LICENSE.

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

dimfort-0.1.2.tar.gz (153.0 kB view details)

Uploaded Source

Built Distribution

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

dimfort-0.1.2-py3-none-any.whl (89.1 kB view details)

Uploaded Python 3

File details

Details for the file dimfort-0.1.2.tar.gz.

File metadata

  • Download URL: dimfort-0.1.2.tar.gz
  • Upload date:
  • Size: 153.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dimfort-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d194be3a53d0facf223d692239cad2d34e82443c323dbf661921348c50d7466e
MD5 f03980050391c7f2909f912e217ac692
BLAKE2b-256 be59565a462061e7828de5d49188ff53ff9b694401e6b0cb41f97ea31335ab8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for dimfort-0.1.2.tar.gz:

Publisher: release.yml on ArrialVictor/DimFort

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

File details

Details for the file dimfort-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: dimfort-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 89.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dimfort-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6c0368193d99097a36f6b99a4cb87815c8616ef128edcac69793ff6773265f89
MD5 47b4e0f56b7a0d75f4ffa7c07713ce22
BLAKE2b-256 9558975fb34ae10bcbba83a0b295f7e7c1838be09ba80584874eab35a2b8e4d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for dimfort-0.1.2-py3-none-any.whl:

Publisher: release.yml on ArrialVictor/DimFort

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