mpyhooks

This tool provides various hooks to check file content in a repository, with many originating from the OpenFOAM Foundation’s code style guide. The hooks can be easily integrated with pre-commit for automated checking.

Usage

mpyhooks <hook> [options] [files ...]

Available Hooks

encoding - Preview File Encoding

Check encoding for preview files in Rodare (Rossendorf Data Repository).

Usage:

mpyhooks encoding file1 file2 ...

line-length - Line Length Check

Check for line length less than 80 characters. Enforces maximum line length following OpenFOAM Foundation software style guide.

Usage:

mpyhooks line-length file1.C file2.H ...

ifndef - Header Guard Check

Check for #ifndef directive and #define statements in header files. Ensures proper include guards in header files.

Usage:

mpyhooks ifndef MyClass.H ...

Expected format:

#ifndef MyClass_H
#define MyClass_H

// ... content ...

#endif

tabs - Tab Detection

Check for tabs in files (should use 4 spaces instead).

Usage:

mpyhooks tabs file1.C file2.py ...

non-standard-code - Code Style Check

Checks for non-standard C++ patterns per OpenFOAM Foundation software guidelines.

Usage:

mpyhooks non-standard-code file1.C file2.H ...

keywords - Keyword Validation

Check keyword validity in case metadata.

Usage:

mpyhooks keywords --ref reference.yml case.yml

Pre-commit Integration

Detailed installation and usage instructions for pre-commit can be found here. To use the hooks provided by this package you have to have access to the repository for this package in Helmholtz Codebase. For using the hooks in your own repository, create a .pre-commit-hooks.yaml in the root of the repository:

repos:
      - repo: https://TOKEN_NAME:TOKEN@codebase.helmholtz.cloud/fwdc/python.git
      rev: 2.1.3
      hooks:
          - id: line-length
          - id: preview-encoding
          - id: ifndef
          - id: tabs
          - id: non-standard-code
          - id: copyright-year
          - id: copyright-header
            name: source-code-header
            types_or: [c, c++, header]
            entry: |-
              mpyhooks copyright-header
              'My C++ Header RegExp'
          - id: copyright-header
            name: shell-header
            types: [file, text, shell]
            entry: |-
              mpyhooks copyright-header
              'My Shell Header RegExp'

Install pre-commit:

pip install pre-commit
pre-commit install

Now hooks run automatically on git commit for all stashed files. For running a single hook only use pre commit run <hook>, or for running all hooks on all files pre commit run --all-files, or for running the hooks only on selected files pre-commit run --files .... For more information on pre-commit the reader is referred to its documentation.