Pre-commit Integration

pycmdcheck integrates with the pre-commit framework to automatically check your Python package before each commit.

Installation

First, install pre-commit if you haven’t already:

pip install pre-commit

Adding pycmdcheck to Your Project

Add pycmdcheck to your .pre-commit-config.yaml:

Standard Check

repos:
  - repo: https://github.com/coatless-py-pkg/pycmdcheck
    rev: v0.1.0  # Use the latest version
    hooks:
      - id: pycmdcheck

Strict Mode

For stricter checking that treats warnings as errors:

repos:
  - repo: https://github.com/coatless-py-pkg/pycmdcheck
    rev: v0.1.0  # Use the latest version
    hooks:
      - id: pycmdcheck-strict

Using Both Hooks

You can use both hooks if you want different behavior for different scenarios:

repos:
  - repo: https://github.com/coatless-py-pkg/pycmdcheck
    rev: v0.1.0
    hooks:
      - id: pycmdcheck
        stages: [commit]
      - id: pycmdcheck-strict
        stages: [push]

This configuration runs standard checks on commit but enforces strict mode on push.

Hook Options

Both hooks accept additional arguments via the args option:

repos:
  - repo: https://github.com/coatless-py-pkg/pycmdcheck
    rev: v0.1.0
    hooks:
      - id: pycmdcheck
        args: [--skip, "test-coverage", --skip, "docs-build"]

CI Integration

Pre-commit hooks can be run in CI environments. Add this to your CI workflow:

# GitHub Actions example
- name: Run pre-commit
  uses: pre-commit/action@v3.0.1

Or run manually:

pre-commit run --all-files

Running pycmdcheck Directly in CI

For more control in CI, you can run pycmdcheck directly:

# GitHub Actions example
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - name: Install pycmdcheck
        run: pip install pycmdcheck
      - name: Run pycmdcheck
        run: pycmdcheck check --profile strict

Local Development

After adding the configuration, install the hooks:

pre-commit install

Now pycmdcheck will run automatically on each commit. To run manually:

# Run on staged files
pre-commit run pycmdcheck

# Run on all files
pre-commit run pycmdcheck --all-files

# Run strict mode
pre-commit run pycmdcheck-strict --all-files

Skipping Hooks

To skip the hook temporarily (use sparingly):

git commit --no-verify -m "WIP: work in progress"