Skip to content

gabyx/Githooks-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Githooks for Python

This repository contains shared repository Git hooks for shell scripts in githooks/* to be used with the Githooks Manager.

The following is included:

  • Hook to format python files with black (or yapf) (pre-commit).
  • Hook to check python files with flake8 (pre-commit).
  • Scripts for linting/formatting including running mypy
Table of Content (click to expand)

Requirements

Run them containerized where only docker is required.

If you want to run them non-containerized, make the following installed on your system:

  • Python requirements in requirements.txt
  • bash
  • GNU grep
  • GNU sed
  • GNU find
  • GNU xargs
  • GNU parallel [optional]

This works with Windows setups too.

Installation

The hooks can be used by simply using this repository as a shared hook repository inside python projects. See further documentation.

You should configure the shared hook repository in your project to use this repos main branch by using the following .githooks/.shared.yaml :

version: 1
urls:
  - https://github.com/gabyx/githooks-python.git@main`.

Hook: pre-commit/1-format/format-python.yaml

Formats all staged files with black.

For temporary using yapf use .githooks/.envs.yaml :

envs:
  githooks-python:
    - GITHOOKS_PYTHON_FORMAT_USE_YAPF=1

Hook: pre-commit/2-check/check-python.yaml

Lints all files staged files with flake8.

Scripts

The following scripts are provided:

  • format-python-all.sh : Script to format all python files in a directory recursively. See documentation.

  • check-python-all.sh : Script to check all python files in a directory recursively. See documentation.

  • check-python-static-all.sh : Script to check all python files statically with mypy in a directory recursively. See documentation.

They can be used in scripts by doing the following trick inside a repo which uses this hook:

shellHooks=$(git hooks shared root ns:githooks-python)
"$shellHooks/githooks/scripts/<script-name>.sh"

Testing

The containerized tests in tests/* are executed by

tests/test.sh

or only special tests steps by

tests/test.sh --seq 001..010

For showing the output also in case of success use:

tests/test.sh --show-output [other-args]

About

Githooks for python development

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published