autohooks


Nameautohooks JSON
Version 24.2.0 PyPI version JSON
download
home_pagehttps://github.com/greenbone/autohooks/
SummaryLibrary for managing git hooks
upload_time2024-02-26 10:34:13
maintainer
docs_urlNone
authorGreenbone AG
requires_python>=3.9,<4.0
licenseGPL-3.0-or-later
keywords git formatting linting hooks
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![Greenbone Logo](https://www.greenbone.net/wp-content/uploads/gb_new-logo_horizontal_rgb_small.png)
# Autohooks <!-- omit in toc -->

[![PyPI release](https://img.shields.io/pypi/v/autohooks.svg)](https://pypi.org/project/autohooks/)
[![Build and test Python package](https://github.com/greenbone/autohooks/actions/workflows/ci-python.yml/badge.svg)](https://github.com/greenbone/autohooks/actions/workflows/ci-python.yml)
[![codecov](https://codecov.io/gh/greenbone/autohooks/branch/main/graph/badge.svg?token=9IX7ucaFwj)](https://codecov.io/gh/greenbone/autohooks)

Library for managing and writing [git hooks](https://git-scm.com/docs/githooks)
in Python using `pyproject.toml` for its settings.

Looking for automatic formatting and linting, e.g., with [black] and [ruff],
while creating a git commit using a pure Python implementation? Do you just want
to have your git hook settings in the `pyproject.toml` file too?

Welcome to **autohooks**!

- [Why?](#why)
- [Solution](#solution)
- [Requirements](#requirements)
- [Plugins](#plugins)
- [Installing autohooks](#installing-autohooks)
- [Command Completion](#command-completion)
  - [Setup for bash](#setup-for-bash)
  - [Setup for zsh](#setup-for-zsh)
- [Maintainer](#maintainer)
- [Contributing](#contributing)
- [License](#license)

## Why?

Several outstanding libraries for managing and executing git hooks exist already.
To name a few: [husky](https://github.com/typicode/husky),
[lint-staged](https://github.com/okonet/lint-staged),
[precise-commits](https://github.com/nrwl/precise-commits) or
[pre-commit](https://github.com/pre-commit/pre-commit).

However, they need another interpreter besides python (like husky), require a
different config file besides `pyproject.toml` or are too ambiguous (like
pre-commit). pre-commit is written in python but has support hooks written in
all kind of languages. Additionally, it maintains the dependencies by itself and
does not install them in the current environment.

## Solution

autohooks is a pure python library that installs a minimal
[executable git hook](https://github.com/greenbone/autohooks/blob/main/autohooks/precommit/template).
It allows the decision of how to maintain the hook dependencies
by supporting different modes and stores its settings in the well known
`pyproject.toml` file.

![Autohooks](https://raw.githubusercontent.com/greenbone/autohooks/main/autohooks.gif)

## Requirements

Python 3.9+ is required for autohooks.

## Plugins

* Python code formatting via [black](https://github.com/greenbone/autohooks-plugin-black)

* Python code formatting via [autopep8](https://github.com/LeoIV/autohooks-plugin-autopep8)

* Python code linting via [ruff](https://github.com/greenbone/autohooks-plugin-ruff)

* Python code linting via [pylint](https://github.com/greenbone/autohooks-plugin-pylint)

* Python code linting via [flake8](https://github.com/greenbone/autohooks-plugin-flake8)

* Python code linting via [mypy](https://github.com/greenbone/autohooks-plugin-mypy)

* Python import sorting via [isort](https://github.com/greenbone/autohooks-plugin-isort)

* Running tests via [pytest](https://github.com/greenbone/autohooks-plugin-pytest/)

## Installing autohooks

Quick installation of [ruff] and [black] plugins using [poetry]:

```shell
poetry add --dev autohooks autohooks-plugin-black autohooks-plugin-ruff
poetry run autohooks activate --mode poetry
poetry run autohooks plugins add autohooks.plugins.black autohooks.plugins.ruff
```

The output of `autohooks activate` should be similar to
```
 ✓ autohooks pre-commit hook installed at /autohooks-test/.git/hooks/pre-commit using poetry mode.
```

Autohooks has an extensible plugin model. Each plugin provides different
functionality which often requires to install additional dependencies.

For managing these dependencies currently three modes are supported by
autohooks:

* `pythonpath` for dependency management via [pip]
* `poetry` for dependency management via [poetry] (recommended)
* `pipenv` for dependency management via [pipenv]

These modes handle how autohooks, the plugins and their dependencies are loaded
during git hook execution.

If no mode is specified in the [`pyproject.toml` config file](#configure-mode-and-plugins-to-be-run)
and no mode is set during [activation](#activating-the-git-hooks), autohooks
will use the [pythonpath mode](#pythonpath-mode) by default.

For more details on using [pip], [poetry] or [pipenv] in conjunction with these
modes see the [documentation](https://greenbone.github.io/autohooks).

## Command Completion

`autohooks` comes with support for command line completion in bash
and zsh.

### Setup for bash

```bash
echo "source ~/.autohooks-complete.bash" >> ~/.bashrc
autohooks --print-completion bash > ~/.autohooks-complete.bash
```

Alternatively, you can use the result of the completion command directly with
the eval function of your bash shell:

```bash
eval "$(autohooks --print-completion bash)"
```

### Setup for zsh

```zsh
echo 'fpath=("$HOME/.zsh.d" $fpath)' >> ~/.zsh
mkdir -p ~/.zsh.d/
autohooks --print-completion zsh > ~/.zsh.d/_autohooks
```

Alternatively, you can use the result of the completion command directly with
the eval function of your zsh shell:

```bash
eval "$(autohooks --print-completion zsh)"
```

## Maintainer

This project is maintained by [Greenbone AG](https://www.greenbone.net/).

## Contributing

Your contributions are highly appreciated. Please
[create a pull request](https://github.com/greenbone/autohooks/pulls)
on GitHub. Bigger changes need to be discussed with the development team via the
[issues section at GitHub](https://github.com/greenbone/autohooks/issues)
first.

## License

Copyright (C) 2019 - 2024 [Greenbone AG](https://www.greenbone.net/)

Licensed under the [GNU General Public License v3.0 or later](LICENSE).

[black]: https://black.readthedocs.io/en/stable/
[pip]: https://pip.pypa.io/en/stable/
[pipenv]: https://pipenv.readthedocs.io/en/latest/
[poetry]: https://python-poetry.org/
[pylint]: https://pylint.readthedocs.io/en/latest/
[ruff]: https://docs.astral.sh/ruff/


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/greenbone/autohooks/",
    "name": "autohooks",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "git,formatting,linting,hooks",
    "author": "Greenbone AG",
    "author_email": "info@greenbone.net",
    "download_url": "https://files.pythonhosted.org/packages/8b/9d/29e14a12211fedd24eb971ccda2eefba745f73b738098662651c4a7b2083/autohooks-24.2.0.tar.gz",
    "platform": null,
    "description": "![Greenbone Logo](https://www.greenbone.net/wp-content/uploads/gb_new-logo_horizontal_rgb_small.png)\n# Autohooks <!-- omit in toc -->\n\n[![PyPI release](https://img.shields.io/pypi/v/autohooks.svg)](https://pypi.org/project/autohooks/)\n[![Build and test Python package](https://github.com/greenbone/autohooks/actions/workflows/ci-python.yml/badge.svg)](https://github.com/greenbone/autohooks/actions/workflows/ci-python.yml)\n[![codecov](https://codecov.io/gh/greenbone/autohooks/branch/main/graph/badge.svg?token=9IX7ucaFwj)](https://codecov.io/gh/greenbone/autohooks)\n\nLibrary for managing and writing [git hooks](https://git-scm.com/docs/githooks)\nin Python using `pyproject.toml` for its settings.\n\nLooking for automatic formatting and linting, e.g., with [black] and [ruff],\nwhile creating a git commit using a pure Python implementation? Do you just want\nto have your git hook settings in the `pyproject.toml` file too?\n\nWelcome to **autohooks**!\n\n- [Why?](#why)\n- [Solution](#solution)\n- [Requirements](#requirements)\n- [Plugins](#plugins)\n- [Installing autohooks](#installing-autohooks)\n- [Command Completion](#command-completion)\n  - [Setup for bash](#setup-for-bash)\n  - [Setup for zsh](#setup-for-zsh)\n- [Maintainer](#maintainer)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Why?\n\nSeveral outstanding libraries for managing and executing git hooks exist already.\nTo name a few: [husky](https://github.com/typicode/husky),\n[lint-staged](https://github.com/okonet/lint-staged),\n[precise-commits](https://github.com/nrwl/precise-commits) or\n[pre-commit](https://github.com/pre-commit/pre-commit).\n\nHowever, they need another interpreter besides python (like husky), require a\ndifferent config file besides `pyproject.toml` or are too ambiguous (like\npre-commit). pre-commit is written in python but has support hooks written in\nall kind of languages. Additionally, it maintains the dependencies by itself and\ndoes not install them in the current environment.\n\n## Solution\n\nautohooks is a pure python library that installs a minimal\n[executable git hook](https://github.com/greenbone/autohooks/blob/main/autohooks/precommit/template).\nIt allows the decision of how to maintain the hook dependencies\nby supporting different modes and stores its settings in the well known\n`pyproject.toml` file.\n\n![Autohooks](https://raw.githubusercontent.com/greenbone/autohooks/main/autohooks.gif)\n\n## Requirements\n\nPython 3.9+ is required for autohooks.\n\n## Plugins\n\n* Python code formatting via [black](https://github.com/greenbone/autohooks-plugin-black)\n\n* Python code formatting via [autopep8](https://github.com/LeoIV/autohooks-plugin-autopep8)\n\n* Python code linting via [ruff](https://github.com/greenbone/autohooks-plugin-ruff)\n\n* Python code linting via [pylint](https://github.com/greenbone/autohooks-plugin-pylint)\n\n* Python code linting via [flake8](https://github.com/greenbone/autohooks-plugin-flake8)\n\n* Python code linting via [mypy](https://github.com/greenbone/autohooks-plugin-mypy)\n\n* Python import sorting via [isort](https://github.com/greenbone/autohooks-plugin-isort)\n\n* Running tests via [pytest](https://github.com/greenbone/autohooks-plugin-pytest/)\n\n## Installing autohooks\n\nQuick installation of [ruff] and [black] plugins using [poetry]:\n\n```shell\npoetry add --dev autohooks autohooks-plugin-black autohooks-plugin-ruff\npoetry run autohooks activate --mode poetry\npoetry run autohooks plugins add autohooks.plugins.black autohooks.plugins.ruff\n```\n\nThe output of `autohooks activate` should be similar to\n```\n \u2713 autohooks pre-commit hook installed at /autohooks-test/.git/hooks/pre-commit using poetry mode.\n```\n\nAutohooks has an extensible plugin model. Each plugin provides different\nfunctionality which often requires to install additional dependencies.\n\nFor managing these dependencies currently three modes are supported by\nautohooks:\n\n* `pythonpath` for dependency management via [pip]\n* `poetry` for dependency management via [poetry] (recommended)\n* `pipenv` for dependency management via [pipenv]\n\nThese modes handle how autohooks, the plugins and their dependencies are loaded\nduring git hook execution.\n\nIf no mode is specified in the [`pyproject.toml` config file](#configure-mode-and-plugins-to-be-run)\nand no mode is set during [activation](#activating-the-git-hooks), autohooks\nwill use the [pythonpath mode](#pythonpath-mode) by default.\n\nFor more details on using [pip], [poetry] or [pipenv] in conjunction with these\nmodes see the [documentation](https://greenbone.github.io/autohooks).\n\n## Command Completion\n\n`autohooks` comes with support for command line completion in bash\nand zsh.\n\n### Setup for bash\n\n```bash\necho \"source ~/.autohooks-complete.bash\" >> ~/.bashrc\nautohooks --print-completion bash > ~/.autohooks-complete.bash\n```\n\nAlternatively, you can use the result of the completion command directly with\nthe eval function of your bash shell:\n\n```bash\neval \"$(autohooks --print-completion bash)\"\n```\n\n### Setup for zsh\n\n```zsh\necho 'fpath=(\"$HOME/.zsh.d\" $fpath)' >> ~/.zsh\nmkdir -p ~/.zsh.d/\nautohooks --print-completion zsh > ~/.zsh.d/_autohooks\n```\n\nAlternatively, you can use the result of the completion command directly with\nthe eval function of your zsh shell:\n\n```bash\neval \"$(autohooks --print-completion zsh)\"\n```\n\n## Maintainer\n\nThis project is maintained by [Greenbone AG](https://www.greenbone.net/).\n\n## Contributing\n\nYour contributions are highly appreciated. Please\n[create a pull request](https://github.com/greenbone/autohooks/pulls)\non GitHub. Bigger changes need to be discussed with the development team via the\n[issues section at GitHub](https://github.com/greenbone/autohooks/issues)\nfirst.\n\n## License\n\nCopyright (C) 2019 - 2024 [Greenbone AG](https://www.greenbone.net/)\n\nLicensed under the [GNU General Public License v3.0 or later](LICENSE).\n\n[black]: https://black.readthedocs.io/en/stable/\n[pip]: https://pip.pypa.io/en/stable/\n[pipenv]: https://pipenv.readthedocs.io/en/latest/\n[poetry]: https://python-poetry.org/\n[pylint]: https://pylint.readthedocs.io/en/latest/\n[ruff]: https://docs.astral.sh/ruff/\n\n",
    "bugtrack_url": null,
    "license": "GPL-3.0-or-later",
    "summary": "Library for managing git hooks",
    "version": "24.2.0",
    "project_urls": {
        "Documentation": "https://greenbone.github.io/autohooks/",
        "Homepage": "https://github.com/greenbone/autohooks/",
        "Repository": "https://github.com/greenbone/autohooks/"
    },
    "split_keywords": [
        "git",
        "formatting",
        "linting",
        "hooks"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f056782de8fe79c99777cfdef761bfdd232f1557b7e24b3e81cc676f59006f95",
                "md5": "30b164ee721271c6766c7a1f259a4daa",
                "sha256": "a2097de2e092fa7b78a17b63b73980d3cc42b01065feb2caf0d41e2bb506621b"
            },
            "downloads": -1,
            "filename": "autohooks-24.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "30b164ee721271c6766c7a1f259a4daa",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 35548,
            "upload_time": "2024-02-26T10:34:10",
            "upload_time_iso_8601": "2024-02-26T10:34:10.701739Z",
            "url": "https://files.pythonhosted.org/packages/f0/56/782de8fe79c99777cfdef761bfdd232f1557b7e24b3e81cc676f59006f95/autohooks-24.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8b9d29e14a12211fedd24eb971ccda2eefba745f73b738098662651c4a7b2083",
                "md5": "78709f2839078572864e91956cb19e15",
                "sha256": "ee929a9f7ff68e61c73201de817b679df168b4465be1026550a71956b419200b"
            },
            "downloads": -1,
            "filename": "autohooks-24.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "78709f2839078572864e91956cb19e15",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 74073,
            "upload_time": "2024-02-26T10:34:13",
            "upload_time_iso_8601": "2024-02-26T10:34:13.462746Z",
            "url": "https://files.pythonhosted.org/packages/8b/9d/29e14a12211fedd24eb971ccda2eefba745f73b738098662651c4a7b2083/autohooks-24.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-26 10:34:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "greenbone",
    "github_project": "autohooks",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "autohooks"
}
        
Elapsed time: 0.98656s