Files
test/.pre-commit-config.yaml
Andrew Vaillancourt 1b9396a2c6 Enforce docstring standards and update pre-commit
- Enforce Google-style docstrings in pre-commit hooks:
  - Add pydocstyle, pydoclint, and interrogate to Pipenv and pre-commit
  - Configure pydocstyle for PEP 257 and Google-style compliance
  - Set pydoclint to enforce function signature correctness
  - Ensure 100% function and class docstring coverage with interrogate:
    - There are some exceptions, e.g. init, module-level.
    - More exceptions can be added if the tooling is found to be too
      strict.

- Refine Black hook ordering to ensure all hooks run on formatted files:
  - Fail commit if formatting is needed (--check)
  - Auto-format files in a separate step
  - Prevent bypassing docstring checks by staging unformatted files

- Ensure return type consistency (DOC203 best practices):
  - Require both return type hints (-> type) and docstring return types
  - Explain rationale for requiring both:
    - Type hints help with static analysis and runtime type checking
    - Docstring return types improve readability and documentation clarity
    - Pre-commit hooks validate consistency across both formats
  - Update pre-commit hooks to explicitly check for this requirement

- Restructure pre-commit and linting configuration:
  - Move .pydocstyle.ini, .flake8, and pyproject.toml to the root
  - Update pre-commit hooks to reference these configs in the new structure

- Modify tox.ini to prevent packaging errors and improve workflow:
  - Add `skipsdist = True` to disable setuptools packaging
  - Set `usedevelop = False` to prevent unintended package installation
  - Ensure `tox` only runs documentation and linting tasks
  - Aligns with StarlingX repository standards and prevents conflicts
  - Retain the pre-commit/ directory for potential future hooks

- Update documentation and improve contributor guidance:
  - Add CONTRIBUTING.rst with detailed contribution guidelines
  - Create contributors.rst in doc/source for Sphinx-rendered docs
  - Link contributors.rst in index.rst for visibility in generated docs
  - Ensure contributing.rst references the latest CONTRIBUTING.rst
  - Document VSCode and PyCharm auto-doc settings in CONTRIBUTING.rst

This commit ensures consistent docstring enforcement, improves
pre-commit integration, aligns with best practices, and enhances
contributor documentation.

Change-Id: Iba282c20502adb81a7739ec6c3ed8b6f3bc45077
Signed-off-by: Andrew Vaillancourt <andrew.vaillancourt@windriver.com>
2025-02-18 14:35:58 -05:00

75 lines
2.5 KiB
YAML

# -----------------------------------------------------------------------------
# Pre-Commit Hook Configuration for starlingx/test
#
# This configuration ensures code quality by enforcing formatting, style, and
# documentation standards before commits. The following tools are used:
#
# - `isort` → Sorts and organizes imports.
# - `black` → Formats Python code to maintain consistent style.
# - `flake8` → Runs linting checks for Python code style and errors.
# - `pydocstyle` → Enforces PEP 257 and Google-style docstring conventions.
# - `pydoclint` → Validates that docstrings match function signatures.
# - `interrogate` → Ensures all public functions and classes have docstrings.
#
# Notes:
# - `interrogate` is configured to ignore nested functions (`--ignore-nested-functions`)
# to avoid unnecessary enforcement on pytest teardowns and small helper functions.
# - `black` uses `pyproject.toml` for consistency across formatting tools.
# - `pydocstyle` and `pydoclint` ensure compliance with Google-style docstrings.
# -----------------------------------------------------------------------------
default_stages: [commit]
default_language_version:
python: python3.11
repos:
- repo: local
hooks:
- id: isort
name: isort - import sorting
entry: isort
language: python
types: [python]
args: [--settings-path, pyproject.toml]
- id: black
name: black - fail if formatting needed
entry: black
language: python
types: [python]
args: [--config, pyproject.toml, --check]
- id: black
name: black - auto-format code
entry: black
language: python
types: [python]
args: [--config, pyproject.toml]
- id: flake8
name: flake8 - code lint and style checks
entry: flake8
language: python
types: [python]
args: [--config=.flake8]
- id: pydocstyle
name: pydocstyle - enforce PEP 257 and Google-style docstrings
entry: pydocstyle
language: python
types: [python]
args: [--config=pydocstyle.ini]
- id: pydoclint
name: pydoclint - enforce Google-style docstring structure
entry: pydoclint
language: python
types: [python]
args: ["--config=pyproject.toml"]
- id: interrogate
name: interrogate - ensure all functions and classes have docstrings
entry: interrogate
language: python
types: [python]
args: ["--fail-under", "100", "--ignore-module", "--ignore-init-method", "--ignore-nested-functions", "--verbose"]