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. The hook tries to detect regular header files and will skip header files that contain pure source code only. The detection is based on a test for #pragma once, #ifndef or #define.

Usage:

mpyhooks ifndef MyClass.H ...

Expected format:

#ifndef MyClass_H
#define MyClass_H

// ... content ...

#endif

tabs - Tab Replacement

Check for tabs in files and replaces them with spaces (default are 4).

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

shellcheck - Check Syntax for Shell Files

Check is based on shellcheck-py, which is a simple wrapper around shellcheck. It is part of the hooks collection, because in the default setting in this repository it will check only new and modified files of a fork with respect to a branch containing the current state of the upstream repository.

Pre-commit Integration

Detailed installation and usage instructions for pre-commit can be found here.

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.

For using the hooks in your own repository, create a .pre-commit-hooks.yaml in the root of the repository:

repos:
      - repo: https://codebase.helmholtz.cloud/fwdc/public/python.git
      rev: 5.1.2
      hooks:
          - id: line-length
          - id: preview-encoding
          - id: ifndef
          - id: tabs
          - id: non-standard-code
          - id: cpp-copyright
          - id: shell-copyright
          - id: config-copyright
          - id: keywords
          - id: shellcheck