
repos:
    # Compare the local template version to the latest remote template version
    # This hook should always pass. It will print a message if the local version 
    # is out of date.
  - repo: https://github.com/lincc-frameworks/pre-commit-hooks
    rev: v0.1.2
    hooks:
      - id: check-lincc-frameworks-template-version
        name: Check template version
        description: Compare current template version against latest
        verbose: true
    # Clear output from jupyter notebooks so that only the input cells are committed.
  - repo: local
    hooks:
      - id: jupyter-nb-clear-output
        name: Clear output from Jupyter notebooks
        description: Clear output from Jupyter notebooks.
        files: \.ipynb$
        exclude: ^docs/pre_executed
        stages: [pre-commit]
        language: system
        entry: jupyter nbconvert --clear-output
    # Prevents committing directly branches named 'main' and 'master'.
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0
    hooks:
      - id: no-commit-to-branch
        name: Prevent main branch commits
        description: Prevent the user from committing directly to the primary branch.
      - id: check-added-large-files
        name: Check for large files
        description: Prevent the user from committing very large files.
        args: ['--maxkb=500']
    # Verify that pyproject.toml is well formed
  - repo: https://github.com/abravalheri/validate-pyproject
    rev: v0.24.1
    hooks:
      - id: validate-pyproject
        name: Validate pyproject.toml
        description: Verify that pyproject.toml adheres to the established schema.
    # Verify that GitHub workflows are well formed
  - repo: https://github.com/python-jsonschema/check-jsonschema
    rev: 0.28.0
    hooks:
      - id: check-github-workflows
        args: ["--verbose"]
  - repo: local
    hooks:
      - id: xcxc-check
        name: Check for note-to-self comments (xcxc)
        description: Grep all source files for xcxc which signifies a comment that shouldn't be checked in.
        entry: bash -c "[[ $(grep -rniI xcxc --exclude .pre-commit-config.yaml --exclude-dir _readthedocs --exclude-dir htmlcov  --exclude-dir _results --exclude-dir env --exclude-dir autoapi ./* >&2 ; echo $?) == 1 ]]"
        language: system
        pass_filenames: false
        always_run: true
  - repo: https://github.com/astral-sh/ruff-pre-commit
    # Ruff version.
    rev: v0.14.7
    hooks:
      - id: ruff
        name: Lint code using ruff; sort and organize imports 
        types_or: [ python, pyi ]
        args: ["--fix"]
  - repo: https://github.com/astral-sh/ruff-pre-commit
    # Ruff version.
    rev: v0.14.7
    hooks:
      - id: ruff-format
        name: Format code using ruff
        types_or: [ python, pyi, jupyter ]
    # Make sure Sphinx can build the documentation while explicitly omitting 
    # notebooks from the docs, so users don't have to wait through the execution 
    # of each notebook or each commit. By default, these will be checked in the 
    # GitHub workflows.
  - repo: local
    hooks:
      - id: sphinx-build
        name: Build documentation with Sphinx
        entry: sphinx-build
        language: system
        always_run: true
        exclude_types: [file, symlink]
        args:
          [
            "-M", # Run sphinx in make mode, so we can use -D flag later
                  # Note: -M requires next 3 args to be builder, source, output
            "html", # Specify builder
            "./docs", # Source directory of documents
            "./_readthedocs", # Output directory for rendered documents
            "-T", # Show full trace back on exception
            "-E", # Don't use saved env; always read all files
            "-d", # Flag for cached environment and doctrees
            "./docs/_build/doctrees", # Directory
            "-D", # Flag to override settings in conf.py
            "exclude_patterns=notebooks/*,_build", # Exclude our notebooks from pre-commit
            "-W", # Warnings are errors
            "--keep-going", # Finish generating docs even if errors occur
            "-n", # Nitpick mode among other things checks for broken links
          ]
    # Run unit tests, verify that they pass. Note that coverage is run against
    # the ./src directory here because that is what will be committed. In the
    # github workflow script, the coverage is run against the installed package
    # and uploaded to Codecov by calling pytest like so:
    # `python -m pytest --cov=<package_name> --cov-report=xml`
  - repo: local
    hooks:
      - id: pytest-check
        name: Run unit tests
        description: Run unit tests with pytest.
        entry: bash -c "if python -m pytest -n auto --co -qq -m 'not slow'; then python -m pytest -n auto --cov=./src --cov-report=html -m 'not slow'; fi"
        language: system
        pass_filenames: false
        always_run: true
