Skip to main content

Library for managing git hooks

Project description

Greenbone Logo

Autohooks

PyPI release

Library for managing and writing git hooks in Python

Why?

Several outstanding libraries for managing and executing git hooks already exist. To name few: husky, lint-staged, precise-commits or pre-commit.

But either they need another interpreter besides python (like husky) or they are too ambiguous (like pre-commit). pre-commit is written in python but has support hooks written in all kind of languages. Also it maintains the dependencies by itself and doesn't install in the current environment.

Solution

Autohooks is a pure python library that installs a minimal executable git hook. If autohooks isn't installed in your current python path the hooks aren't executed. So autohooks is always opt-in by installing the package into your current development environment. It would be even possible to run different versions of autohooks by switching the environment.

Installation

For the installation of autohooks three steps are necessary:

  1. Install the autohooks package into your current environment
  2. Activate the git hooks
  3. Configure the plugins to be run

Install autohooks python package

For installing the autohooks python package, using pipenv is highly recommended.

To install autohooks as a development dependency run

pipenv install --dev autohooks

Alternatively autohooks can be installed directly from GitHub

pipenv install --dev -e git+https://github.com/bjoernricks/autohooks#egg=autohooks

Activating the git hooks

If autohooks is installed from git or a source tarball, the git hooks should be activated automatically. The activation can be verified by running e.g. autohooks check.

Installing autohooks from a wheel package will NOT activate the git commit hooks.

To manually activate the git hooks you can run

pipenv run autohooks activate

Configure plugins to be run

To actually run an action on git hooks, autohooks plugins have to be configured. Autohooks uses the pyproject.toml file specified in PEP518 for its configuration. Adding a [tool.autohooks] section allows to set python modules to be run on a specific git hook.

Example pyproject.toml:

[build-system]
requires = ["setuptools", "wheel"]

[tool.autohooks]
pre-commit = ["autohooks.plugins.black"]

Plugins

  • Python code formatting via black

  • Python code linting via pylint

Maintainer

This project is maintained by Greenbone Networks GmbH.

Contributing

Your contributions are highly appreciated. Please create a pull request on GitHub. Bigger changes need to be discussed with the development team via the issues section at GitHub first.

License

Copyright (C) 2019 Greenbone Networks GmbH

Licensed under the GNU General Public License v3.0 or later.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autohooks-1.0.1.tar.gz (27.7 kB view details)

Uploaded Source

File details

Details for the file autohooks-1.0.1.tar.gz.

File metadata

  • Download URL: autohooks-1.0.1.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for autohooks-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3dff17e3ff68f8073a51432580809fdf384c0bd079c4aef2228b06539f0eb4a6
MD5 d44174b8b46d69e82aeada24a4e4c70d
BLAKE2b-256 e6c26c5312c55980f44706b0dcd2d75aca43cd1f49bc7489a7de2b771467bf14

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page