Library for managing git hooks

Overview

Greenbone Logo

Autohooks

PyPI release Build and test Python package

Library for managing and writing git hooks in Python.

Looking for automatic formatting or linting, e.g., with black and pylint, while creating a git commit using a pure Python implementation? Welcome to autohooks!

Why?

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

However, they either need another interpreter besides python (like husky) 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. It allows the decision of how to maintain the hook dependencies by supporting different modes.

Requirements

Python 3.7+ is required for autohooks.

Modes

Currently three modes for using autohooks are supported:

  • pythonpath
  • pipenv
  • poetry

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 and no mode is set during activation, autohooks will use the pythonpath mode by default.

poetry or pipenv modes leverage the /usr/bin/env command using the --split-string (-S) option. If autohooks detects that it is running on an OS where /usr/bin/env is yet to support split_strings (notably ubuntu < 19.x), autohooks will automatically change to an internally chosen poetry_multiline/pipenv_mutliline mode. The 'multiline' modes should not be user-configured options; setting your project to use poetry or pipenvallows team members the greatest latitude to use an OS of their choice yet leverage the sane /usr/bin/env --split-string if possible. Though poetry_multiline would generally work for all, it is very confusing sorcery. (Multiline shebang explained)

Pythonpath Mode

In the pythonpath mode, the user has to install autohooks, the desired plugins and their dependencies into the PYTHONPATH manually.

This can be achieved by running pip install --user autohooks ... to put them into the installation directory of the current user or with pip install authooks ... for a system wide installation.

Alternatively, a virtual environment could be used separating the installation from the global and user wide Python packages.

It is also possible to use pipenv for managing the virtual environment but activating the environment has to be done manually.

Therefore it is even possible to run different versions of autohooks by using the pythonpath mode and switching to a virtual environment.

Pipenv Mode

In the pipenv mode pipenv is used to run autohooks in a dedicated virtual environment. Pipenv uses a lock file to install exact versions. Therefore the installation is deterministic and reliable between different developer setups. In contrast to the pythonpath mode the activation of the virtual environment provided by pipenv is done automatically in the background.

Poetry Mode

Like with the pipenv mode, it is possible to run autohooks in a dedicated environment controlled by poetry. By using the poetry mode the virtual environment will be activated automatically in the background when executing the autohooks based git commit hook.

Using the poetry mode is highly recommended.

Installing autohooks

Four steps are necessary for installing autohooks:

  1. Choosing an autohooks mode
  2. Installing the autohooks python package into the current environment
  3. Configuring plugins to be run
  4. Activating the git hooks

1. Choosing an autohooks Mode

For its configuration, autohooks uses the pyproject.toml file specified in PEP518. Adding a [tool.autohooks] section allows to specify the desired autohooks mode and to set python modules to be run as autohooks plugins.

The mode can be set by adding a mode = line to the pyproject.toml file. Current possible options are "pythonpath", "pipenv" and "poetry" (see autohooks mode). If the mode setting is missing, the pythonpath mode is used.

Example pyproject.toml:

[tool.autohooks]
mode = "pipenv"

2. Installing the autohooks Python Package into the Current Environment

Using poetry is highly recommended for installing the autohooks python package.

To install autohooks as a development dependency run

poetry add --dev autohooks

Alternatively, autohooks can be installed directly from GitHub by running

poetry add --dev git+https://github.com/greenbone/autohooks

3. Configuring Plugins to Be Run

To actually run an action on git hooks, autohooks plugins have to be installed and configured, e.g., to install python linting via pylint run

poetry add --dev autohooks-plugin-pylint

Afterwards, the pylint plugin can be configured to run as a pre-commit git hook by adding the autohooks-plugins-pylint python module name to the pre-commit setting in the [tool.autohooks] section in the pyproject.toml file.

Example pyproject.toml:

[tool.autohooks]
mode = "pipenv"
pre-commit = ["autohooks.plugins.pylint"]

4. Activating the Git Hooks

Because installing and activating git hooks automatically isn't reliable (with using source distributions and different versions of pip) and even impossible (with using wheels) the hooks need to be activated manually once in each installation.

To activate the git hooks run

poetry run autohooks activate

Calling activate also allows for overriding the mode defined in the pyproject.toml settings for testing purposes.

Example:

autohooks activate --mode pipenv

Please keep in mind that autohooks will always issue a warning if the mode used in the git hooks is different from the configured mode in the pyproject.toml file.

The activation can always be verified by running autohooks check.

Plugins

  • Python code formatting via black

  • Python code formatting via autopep8

  • Python code linting via pylint

  • Python import sorting via isort

Howto: Writing a Plugin

Plugins need to be available in the Python import path. The easiest way to achieve this is uploading a plugin to PyPI and installing it via pip or pipenv.

Alternatively, a plugin can also be put into a .autohooks directory in the root directory of the git repository where the hooks should be executed.

An autohooks plugin is a Python module which provides a precommit function. The function must accept arbitrary keywords because the keywords are likely to change in future. Therefore using **kwargs is highly recommended. Currently only a config keyword argument is passed to the precommit function.

Example:

def precommit(**kwargs):
    config = kwargs.get('config')

The config can be used to receive settings from the pyproject.toml file, e.g.,

[tool.autohooks.plugins.foo]
bar = 2

can be received with

def precommit(**kwargs):
    config = kwargs.get('config')
    default_value = 1
    setting = config
      .get('tool', 'autohooks', 'plugins', 'foo')
      .get_value('bar', default_value)
    return 0

With autohooks it is possible to write all kinds of plugins. Most common are plugins for linting and formatting.

Linting Plugin

Usually the standard call sequence for a linting plugin is the following:

  1. get list of staged files
  2. filter list of files for a specific file type
  3. stash unrelated changes
  4. apply checks on filtered list of files by calling some external tool
  5. raise exception if something did go wrong
  6. return 1 if check was not successful
  7. stage changes made by the tool
  8. unstash unrelated changes
  9. return 0

Example plugin:

import subprocess

from autohooks.api import ok, fail
from autohooks.api.git import get_staged_status, stash_unstaged_changes
from autohooks.api.path import match

DEFAULT_INCLUDE = ('*.ext')


def get_include(config)
    if not config:
        return DEFAULT_INCLUDE

    config = config.get('tool', 'autohooks', 'plugins', 'foo')
    return config.get_value('include', DEFAULT_INCLUDE)


def precommit(**kwargs):
    config = kwargs.get('config')
    include = get_include(config)

    files = [f for f in get_staged_status() if match(f.path, include)]

    if not files:
      # not files to lint
      return 0

    with stash_unstaged_changes(files):
        const failed = False
        for file in files:
            status = subprocess.call(['foolinter', str(file)])
            if status:
                fail('Could not validate {str(file)}')
                failed = True
            else:
                ok('Validated {str(file)}')

        return 1 if failed else 0

Formatting Plugin

Usually the standard call sequence for a formatting plugin is the following:

  1. get list of staged files
  2. filter list of files for a specific file type
  3. stash unrelated changes
  4. apply formatting on filtered list of files by calling some external tool
  5. raise exception if something did go wrong
  6. stage changes made by the tool
  7. unstash unrelated changes
  8. return 0

Example plugin:

import subprocess

from autohooks.api import ok, error
from autohooks.api.git import (
    get_staged_status,
    stage_files_from_status_list,
    stash_unstaged_changes,
)
from autohooks.api.path import match

DEFAULT_INCLUDE = ('*.ext')


def get_include(config)
    if not config:
        return DEFAULT_INCLUDE

    config = config.get('tool', 'autohooks', 'plugins', 'bar')
    return config.get_value('include', DEFAULT_INCLUDE)


def precommit(**kwargs):
    config = kwargs.get('config')
    include = get_include(config)

    files = [f for f in get_staged_status() if match(f.path, include)]

    if not files:
      # not files to format
      return 0

    with stash_unstaged_changes(files):
        for file in files:
            # run formatter and raise exception if it fails
            subprocess.run(['barformatter', str(file)], check=True)
            ok('Formatted {str(file)}')

        return 0

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.

Comments
  • add template for pipenv, update install routine

    add template for pipenv, update install routine

    There is an issue with autohooks being installed in pipenv environments. The hook is installed correctly but it cannot be run because it starts a python3 environment outside of the pipenv. However, autohooks cannot be imported in this case as it is only known in the virtual environment.

    This PR checks if a Pipenv is present in the current project. If this is the case, it uses a different template that starts the hook with pipenv run python3.

    Checklist:

    • [ ] Tests
    • [ ] CHANGELOG Entry
    • [x] Documentation
    opened by LeoIV 17
  • autohooks.utils.GitError: Git command '['git', '-C', '...', 'rev-parse', '--git-dir']' returned non-zero exit status 128

    autohooks.utils.GitError: Git command '['git', '-C', '...', 'rev-parse', '--git-dir']' returned non-zero exit status 128

    Hi,

    I have autohooks installed using pythonpath method.

    If I run git commit --amend -m "Test" in root directory of repository, the autohooks runs correctly:

    ➜  test git:(temp) ✗ gc --amend -m "Test"
    ℹ autohooks => pre-commit
    ℹ     Running check_top_directory_names
    ✖         Could not validate top directory name of path testes/dsdsa
    

    However if I run it inside the testes directory, I get following error:

    ➜  testes git:(temp) ✗ gc --amend -m "Test"
    fatal: not a git repository: '.git'
    could not determine .git directory. 
    Traceback (most recent call last):
      File ".git/hooks/pre-commit", line 8, in <module>
        sys.exit(run())
      File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/autohooks/precommit/run.py", line 90, in run
        pre_commit_hook = PreCommitHook()
      File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/autohooks/hooks.py", line 44, in __init__
        self.pre_commit_hook_path = get_pre_commit_hook_path()
      File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/autohooks/hooks.py", line 35, in get_pre_commit_hook_path
        git_hook_dir_path = get_git_hook_directory_path()
      File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/autohooks/utils.py", line 70, in get_git_hook_directory_path
        git_dir_path = get_git_directory_path()
      File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/autohooks/utils.py", line 54, in get_git_directory_path
        raise e from None
      File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/autohooks/utils.py", line 49, in get_git_directory_path
        git_dir = exec_git('-C', pwd, 'rev-parse', '--git-dir').rstrip()
      File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/autohooks/utils.py", line 42, in exec_git
        raise GitError(e.returncode, e.cmd, e.output, e.stderr) from None
    autohooks.utils.GitError: Git command '['git', '-C', '...', 'rev-parse', '--git-dir']' returned non-zero exit status 128
    

    If I run git -C `pwd` rev-parse --git-dir command inside the tested directory, I get proper result - a path which points to .git directory in repository root path.

    Why command executed using exec_git method returns non-zero exit status 128 and the same command executed directly from the terminal returns proper result?

    Btw. In my case .autohooks directory is another git submodule, because I want to store code of hooks in other repository than the one where pre-commit hooks are used.

    bug 
    opened by VictorAtPL 15
  • Output overwritten by carriage return

    Output overwritten by carriage return

    Often -- but not always -- the output of autohooks is overwritten in my terminal by itself. For example, running autohooks check very briefly flashes single lines of text before they are overwritten by the following line. The final line is also overwritten, meaning no output is visible once the command is finished.

    The behaviour described above is consistent among multiple terminal emulators and shells. However, sometimes the lines are displayed properly and then change back to being overwritten, in the same environment in subsequent runs of autohooks.

    I strongly suspect this is related to erikrose/blessings#146. Capturing the output with script(1) does indeed show carriage return control characters (\r, ^M) being present at the end of every line:

    Script started on 2019-12-20 08:49:42+01:00 [TERM="xterm-256color" TTY="/dev/pts/5" COLUMNS="212" LINES="58"]
    ^[7^[7^[[1Gautohooks pre-commit hook is active. ^[[206G [ ^[[32mok^[(B^[[m ]^M
    ^[8^[8^[7^[7^[[1Gautohooks pre-commit hook is outdated. Please run 'autohooks activate --force' to update your pre-commit hook. ^[[201G [ ^[[33mwarning^[(B^[[m ]^M
    ^[8^[8^[7^[7^[[1Gautohooks mode "pythonpath" in pre-commit hook python-gvm/.git/hooks/pre-commit differs from mode "pipenv" in python-gvm/pyproject.toml. ^[[201G [ ^[[33mwarning^[(B^[[m ]^M
    ^[8^[8^[7^[7^[[1GUsing autohooks mode "pythonpath". ^[[204G [ ^[[36minfo^[(B^[[m ]^M
    ^[8^[8^[7^[7^[[1GPlugin "autohooks.plugins.black" active and loadable. ^[[206G [ ^[[32mok^[(B^[[m ]^M
    ^[8^[8^[7^[7^[[1GPlugin "autohooks.plugins.pylint" active and loadable. ^[[206G [ ^[[32mok^[(B^[[m ]^M
    ^[8^[8
    Script done on 2019-12-20 08:49:42+01:00 [COMMAND_EXIT_CODE="0"]
    
    opened by wiegandm 9
  • Pipenv mode is broken by the --split-string (-S) argument of env in the shebang

    Pipenv mode is broken by the --split-string (-S) argument of env in the shebang

    Hi,

    I found myself stuck for an hour trying to make the pipenv mode work. This made me take a look at the pre-commit script managed by autohooks.

    I noticed that the --split-string (-S) argument of env (coreutils) is used in the shebang. But it doesn't seem to be available in every version of /usr/bin/env and using it breaks pipenv mode for me.

    The change was brought by this commit.

    My platform information

    lsb_release -a
    No LSB modules are available.
    Distributor ID:	Ubuntu
    Description:	Ubuntu 18.04.3 LTS
    Release:	18.04
    Codename:	bionic
    

    My env version

    /usr/bin/env --version
    env (GNU coreutils) 8.28
    Copyright © 2017 Free Software Foundation, Inc.
    License GPLv3+ : GNU GPL version 3 ou ultérieure
    <http://gnu.org/licenses/gpl.html>
    Ceci est un logiciel libre. Vous êtes libre de le modifier et de le redistribuer.
    Ce logiciel n'est accompagné d'ABSOLUMENT AUCUNE GARANTIE, dans les limites
    permises par la loi.
    
    Écrit par Richard Mlynarik et David MacKenzie.
    

    The error I get

    From a pipenv virtualenv:

    $ autohooks activate --force  --mode pipenv
    $ git commit -m "foo"
    /usr/bin/env : option invalide -- 'S'
    Saisissez « /usr/bin/env --help » pour plus d'informations.
    

    This is because the shebang used in the pre-commit script managed by autohooks is #!/usr/bin/env -S pipenv run python3.

    The whole script content is:

    #!/usr/bin/env -S pipenv run python3
    # meta = { version = 1 }
    
    import sys
    
    try:
        from autohooks.precommit import run
        sys.exit(run())
    except ImportError:
        print(
            "Error: autohooks is not installed. To force creating a commit without "
            "verification via autohooks run 'git commit --no-verify'.",
            file=sys.stderr,
        )
        sys.exit(1)
    

    Workaround

    The only way for me to make it work for now is to force the pythonpath mode which rewrites the shebang of the previous script to #!/usr/bin/env python3

    Questions/Recommandations

    What are your recommandation for this problem? I assume that upgrading my /usr/bin/env version should solve everything but maybe a minimum requirement should be explicitly mentioned in the install doc. I found this interesting issue about pipenv shebang and it seems like -S is not available on Ubuntu. Is it a choice to make pipenv mode unavailable on Ubuntu?

    bug 
    opened by jflbr 9
  • Fixing Pipenv mode is broken by the --split-string (-S) argument of env in the shebang

    Fixing Pipenv mode is broken by the --split-string (-S) argument of env in the shebang

    This PR addresses #42 where support is missing for OSs that do not have /usr/bin/env --split-string support for pipenv/poetry modes. It introduces related multi-line shebang modes: https://rosettacode.org/wiki/Multiline_shebang#Python

    The PR supports development teams that are not constrained to host OSs by allowing pipenv/poetry modes configurations to check if --split-string is supported. If not, a related multi-line shebang mode is chosen automatically.

    Performance concerns related to the relative impact on autohooks' due to the --split-string check has been considered given autohooks' targeted operating domain being slow file I/O.

    opened by gkedge 8
  • Windows Support?

    Windows Support?

    autohooks/terminal.py depends on the curses package, which I believe is not supported on Windows. When I run the command poetry run autohooks activate, I receive the error ModuleNotFoundError: No module named _curses. Am I suppose to use a different command to activate the git hooks on Windows?

    help wanted 
    opened by scruffaluff 8
  • commit fails on Windows with Python encoding error

    commit fails on Windows with Python encoding error

    I setup the git pre-commit hook using autohooks. My first attempt at a commit resulted in the following traceback:

    Traceback (most recent call last):
      File "F:\dev\project\user\formatting\.git\hooks\pre-commit", line 8, in <module>
        sys.exit(run())
      File "G:\miniconda\envs\myenv\lib\site-packages\autohooks\precommit\run.py", line 103, in run
        term.bold_info('autohooks => pre-commit')
      File "G:\miniconda\envs\myenv\lib\site-packages\autohooks\terminal.py", line 116, in bold_info
        self._print_status(message, Signs.INFO, cf.cyan, style)
      File "G:\miniconda\envs\myenv\lib\site-packages\autohooks\terminal.py", line 79, in _print_status
        print(style(output))
      File "G:\miniconda\envs\myenv\lib\encodings\cp1252.py", line 19, in encode
        return codecs.charmap_encode(input,self.errors,encoding_table)[0]
    UnicodeEncodeError: 'charmap' codec can't encode character '\u2139' in position 0: character maps to <undefined>
    
    opened by nextstate 7
  • (Feature Request) Mandatory hooks / less graceful ImportError failure

    (Feature Request) Mandatory hooks / less graceful ImportError failure

    Hi team & thanks for a great library!

    Our team uses an app development workflow based on pyenv and poetry - with autohooks and its plugins installed locally to the project+virtual environment.

    Our devs are often not actually in the virtual environment shell when doing stuff: Instead using commands like poetry run to trigger scripts and poetry add to update dependencies.

    Unfortunately this often includes not being in the env when running git commit, and autohooks is currently pretty lax about this per the example pre-commit hook below:

    #!/usr/bin/env python3
    
    import sys
    
    try:
        from autohooks.precommit import run
        sys.exit(run())
    except ImportError:
        print('autohooks not installed. Ignoring pre-commit hook.')
        sys.exit(0)
    

    I would love to see the ability (maybe via configuration if it's not for everybody?) to fail more forcefully in this case: For us it's much more likely that a forgetful developer is committing from the wrong environment than that there's an installation issue we want to tolerate!

    opened by alex-thewsey-ibm 7
  • Bump tomlkit from 0.7.0 to 0.7.2

    Bump tomlkit from 0.7.0 to 0.7.2

    Bumps tomlkit from 0.7.0 to 0.7.2.

    Release notes

    Sourced from tomlkit's releases.

    0.7.2

    Fixed

    • Fixed an error where container's data were lost when copying. (#126)
    • Fixed missing tests in the source distribution of the package. (#127)

    0.7.1

    Fixed

    • Fixed an error with indent for nested table elements when updating. (#122)
    • Fixed various issues with dict behavior compliance for containers. (#122)
    • Fixed an internal error when empty tables were present after existing ones. (#122)
    • Fixed table representation for dotted keys. (#122)
    • Fixed an error in top level keys handling when building documents programmatically. (#122)
    • Fixed compliance with mypy by adding a py.typed file. (#109)
    Changelog

    Sourced from tomlkit's changelog.

    [0.7.2] - 2021-05-20

    Fixed

    • Fixed an error where container's data were lost when copying. (#126)
    • Fixed missing tests in the source distribution of the package. (#127)

    [0.7.1] - 2021-05-19

    Fixed

    • Fixed an error with indent for nested table elements when updating. (#122)
    • Fixed various issues with dict behavior compliance for containers. (#122)
    • Fixed an internal error when empty tables were present after existing ones. (#122)
    • Fixed table representation for dotted keys. (#122)
    • Fixed an error in top level keys handling when building documents programmatically. (#122)
    • Fixed compliance with mypy by adding a py.typed file. (#109)
    Commits
    • a4d43a7 Bump version to 0.7.2
    • d5fa2f1 Merge pull request #127 from sdispater/fix-tests-release
    • c856e3b Include submodules when cloning the project for release
    • 63b96f1 Include tests as standard includes and not packages
    • 351d662 Merge pull request #126 from frostming/patch-1
    • 4cdc2f6 add a test case
    • 60da0c0 Correctly restore data for container
    • 1b610fd Merge pull request #123 from sdispater/release-0.7.1
    • 8783149 Bump version to 0.7.1
    • 7a8c54c Merge pull request #122 from sdispater/fixes
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 6
  • Bump importlib-metadata from 4.3.1 to 4.5.0

    Bump importlib-metadata from 4.3.1 to 4.5.0

    Bumps importlib-metadata from 4.3.1 to 4.5.0.

    Changelog

    Sourced from importlib-metadata's changelog.

    v4.5.0

    • #319: Remove SelectableGroups deprecation exception for flake8.

    v4.4.0

    • #300: Restore compatibility in the result from Distribution.entry_points (EntryPoints) to honor expectations in older implementations and issuing deprecation warnings for these cases:

      • EntryPoints objects are once again mutable, allowing for sort() and other list-based mutation operations. Avoid deprecation warnings by casting to a mutable sequence (e.g. list(dist.entry_points).sort()).

      • EntryPoints results once again allow for access by index. To avoid deprecation warnings, cast the result to a Sequence first (e.g. tuple(dist.entry_points)[0]).

    Commits
    • 1cabd5f Merge pull request #319 from python/feature/uniform
    • dba300f 4.4 is now in Cpython
    • abfe23b Separate release number.
    • f45b755 Merge branch 'main' into feature/uniform
    • 5fb7029 Merge pull request #323 from python/bugfix/300-entry-points-by-index
    • 7afc501 Update changelog.
    • 8214dd1 Implement EntryPoints as a DeprecatedList, deprecating mutability of Distribu...
    • a8c70ee Add compatibility handler for accessing EntryPoints by index. Fixes #300.
    • 8535856 Add test capturing missed expectation. Ref #300.
    • f794723 Remove importlib_metadata as imported by pytest. Fixes #322.
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 4
  • Windows Problem

    Windows Problem

    poetry run autohooks activate not working, giving KeyError PWD and after setting it manually, it's not performing any autohooks task as define in pyproject.toml.

    bug 
    opened by anujydv 4
  • Supported mypy plugin

    Supported mypy plugin

    Hi,

    Someone published autohooks-plugin-mypy but there's no source repository so it's effectively unmaintained. Could an official plugin be created?

    Thanks

    opened by codebutler 1
  • additional hooks (ie commit-msg)

    additional hooks (ie commit-msg)

    Hello there,

    First off: I'm glad i found autohooks as it addresses the downsides i see with pre-commit when using it with python (namely configuration via pyproject.toml and being able to managing dependencies with poetry)

    Now to my question: I'm trying to integrate commitizen which is normally ran in the commit-msg-hook. After digging through autohooks-code it seems like it is only managing the pre-commit-hook.

    It would be great if we could manage all the hooks.

    (I'll call the individual hooks in .git/hooks/ stages from now on)

    The requirements i see:

    • allow managing of all stages
    • have activate register a script for all stages by default
    • add config-option to define which stages to register
    • add argument to activate to define which stages to register (aka "i only want pre-commit and commit-msg")
    • allow plugins to define which stage they run in by default
    • allow the user to override which stage a plugin runs in

    I would be glad to get some feedback on this idea.

    thanks in advance

    opened by betaboon 2
Releases(v22.11.2)
  • v22.11.2(Nov 15, 2022)

  • v22.11.1(Nov 8, 2022)

  • v22.11.0(Nov 7, 2022)

    22.11.0 - 2022-11-07

    Added

    • Add py.typed file (PEP 561) to support finding types 986d55b
    • Add documentation link to python package meto information 1a70dd1

    Changed

    • Format workflows, update actions and support Python 3.11 (#399) 66ebe4e
    • Format workflows, update actions and support Python 3.11 376d795

    Bug Fixes

    • Change pre-commit shebang line when using poetry (#381) e851c7d
    • Fix an issue where is_split_env method is not runable on windows platform (#380) 8de747e
    Source code(tar.gz)
    Source code(zip)
    autohooks-22.11.0.tar.gz.asc(833 bytes)
    autohooks-22.11.0.zip.asc(833 bytes)
  • v22.8.1(Aug 16, 2022)

    22.8.1 - 2022-08-16

    Added

    • Add a sphinx based documentation #340 25e65c2
    • Add new development dependencies for docs with sphinx 9dd0857
    • New CLI autohooks plugins for handling plugins #347 2ce2ba8
    • Add new CLI to add, remove and list autohooks plugins 54173b7
    • Easier setup by writing the settings during activation #345 5f352a8
    • Introduce a new from_dict method for AutohooksConfig db8783b
    • Introduce new dataclass for storing the autohooks settings 534b9e4
    • Add new testing function for writing content to a temporary file 045d9ac

    Removed

    • Drop is_autohooks_enabled method from AutohooksConfig 029826c

    Changed

    • Extract checking a plugin for validity to a separate function 7d92bdd
    • Raise a warning if activate is run with installed hook (#346) 10c3d14
    • autohooks activate CLI will now write the settings too 4cbe779
    • Refactor AutohooksConfig to use AutohooksSettings e28d990
    • Merge BaseToolConfig into AutohooksConfig 8a318e0
    Source code(tar.gz)
    Source code(zip)
    autohooks-22.8.1.tar.gz.asc(833 bytes)
    autohooks-22.8.1.zip.asc(833 bytes)
  • v22.8.0(Aug 2, 2022)

    22.8.0 - 2022-08-02

    Added

    • Add an example for reporting progress to README f99c218
    • Add gif of using autohooks in the console to README b4556c1
    • Use rich library for improved UI #334 3c44e2a
    • Allow plugins to report a progress 2e80991
    • Implement rich progress class for displaying plugin progress 1fee198
    • Add rich as direct dependency 1d8de57

    Changed

    • Update README to reflect new report_progress plugin argument 9f6f7e0
    • Use up-to-date build system for poetry in pyproject.toml 6e1bcc9
    Source code(tar.gz)
    Source code(zip)
    autohooks-22.8.0.tar.gz.asc(833 bytes)
    autohooks-22.8.0.zip.asc(833 bytes)
  • v22.7.2(Jul 6, 2022)

  • v22.7.1(Jul 6, 2022)

  • v22.7.0(Jul 5, 2022)

  • v21.7.0(Jul 19, 2021)

  • v21.6.0(Jun 13, 2021)

  • v21.3.0(Mar 29, 2021)

  • v2.2.0(Aug 28, 2020)

  • v2.1.0(Apr 9, 2020)

    2.1.0 - 2020-04-09

    Added

    • Added tools for version handling in autohooks #51
    • Added static get_width method to Terminal class #53

    Changed

    • Reworked Terminal class from terminal.py #45
    • Replaced pipenv with poetry for dependency management. poetry install works a bit different than pipenv install. It installs dev packages and also autohooks in editable mode by default. #51
    • Activation of the git hooks must be done manually with autohooks activate always. Using source distributions and a setuptools extension to activate the hooks isn't reliable at all #52
    • Recommend the poetry mode instead of the pipenv mode. poetry is more reliable than pipenv #55

    Fixed

    • Windows Support, by exchanging the unmaintained blessing module through colorful #45
    • Fixed running autohooks check if no .git/hooks/pre-commit file exists #49

    Removed

    • Removed code relying on setuptools and switched to a full poetry build process #54
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Nov 20, 2019)

    Git Hooks with Python

    Looking for auto formatting code via black or linting with pylint while creating a git commit using a pure Python implementation? Welcome to autohooks 2.0!

    autohooks 2.0 changes the method of loading Python modules and handling import errors. Previously, it was up to the user how to put the autohooks module and the plugins into the current Python import path. Additionally, errors during the import of autohooks and the plugins have been ignored and allowed the git hook to succeed.

    With autohooks 2.0, import errors will exit the current git hook with an error too, i.e. to be able to create a commit despite of an import error git commit --no-verify must be used now.

    To avoid import errors autohooks 2.0 supports different Modes now. The Mode specifies the method of loading the necessary Python modules.

    • The old pre 2.0 autohooks behavior is called pythonpath Mode and is also the fallback if no or an unknown Mode is configured.

    • The pipenv Mode uses the tool Pipenv to start a virtual environment for autohooks.

    • The poetry Mode is very similar to the pipenv Mode but uses poetry to start a virtual environment containing autohooks instead of Pipenv.

    The Mode of an autohooks based git hook is set during activation. If the Mode is changed in the pyproject.toml file after activation, the git hook needs to be overridden. This can be done by calling autohooks activate --force.

    To review and validate the currently active git hooks autohooks check can be used.

    Updating autohooks

    Before updating autohooks to 2.0 a Mode should be set in the pyproject.toml file:

    • If the dependencies are handled manually, e.g. by using virtualenv and pip, the pythonpath mode should be used.
    • If the dependencies are managed and installed via Pipenv the pipenv Mode should be chosen.
    • If poetry manages the dependencies the poetry Mode fits for this tool.
    • If no Mode is set in the pyproject.toml file, autohooks assumes the pythonpath Mode.

    If a git repository is updated from an earlier version of autohooks, users will get the following warning about an outdated pre-commit hook: autohooks pre-commit hook is outdated. Please run 'autohooks activate --force' to update your pre-commit hook.

    Running autohooks activate --force (or pipenv/poetry run authooks activate --force) in each repository clone will update the installed git pre-commit hook and remove the warning.

    2.0.0 - 2019-11-20

    Added

    • Introduction of autohooks modes. Modes configure how to handle loading autohooks, plugins and dependencies when running the git hook. The pythonpath mode requires to put the necessary python packages into the PYTHONPATH manually. The pipenv mode uses pipenv to handle the dependencies. Using the pipenv mode is recommended. #24
    • Add poetry mode to run autohooks via poetry #29
    • Added type hints/annotations to all methods #32
    • Added version meta information to installed pre commit hook #30
    • Extended autohooks check cli to evaluate current hook version and used mode #30
    • Enhanced autohooks activate cli to show additional information if a autohooks git hook is already installed #30
    • Added plugin API for additional info status output #39
    • Added plugin API for additional message printing #39

    Changed

    • The installed git hook will fail now if autohooks can't be loaded. Before the git hook raised only a warning and was ignored. This a major change compared to the previous versions. To update existing installations it requires overriding the installed git hook by running autohooks activate --force. #24
    • The installed git hook will fail now if a autohooks plugin can't be executed e.g. if the import fails. Before these errors were ignored. #28
    • The version of the installed git hook is checked during its execution #30
    • A warning is raised during git hook execution if the current mode is different to the configured mode #30
    • Improved output formatting #39
    Source code(tar.gz)
    Source code(zip)
Owner
Greenbone
Open Source Vulnerability Management
Greenbone
Extended functionality for Namebase past their web UI

Namebase Extended Extended functionality for Namebase past their web UI.

RunDavidMC 12 Sep 02, 2022
Module 2's katas from Launch X's python introduction course.

Module2Katas Module 2's katas from Launch X's python introduction course. Virtual environment creation process (on Windows): Create a folder in any de

Javier Méndez 1 Feb 10, 2022
This is the DBMS Project done in 5th sem of B.E CS.

Student-Result-Management-System This is the DBMS Project done in 5th sem of B.E CS. You need to install SQlite DB Browser in your pc or laptop to ope

Vivek kulkarni 1 Jan 14, 2022
This is the core of the program which takes 5k SYMBOLS and looks back N years to pull in the daily OHLC data of those symbols and saves them to disc.

This is the core of the program which takes 5k SYMBOLS and looks back N years to pull in the daily OHLC data of those symbols and saves them to disc.

Daniel Caine 1 Jan 31, 2022
A program that makes all 47 textures of Optifine CTM only using 2 textures

A program that makes all 47 textures of Optifine CTM only using 2 textures

1 Jan 22, 2022
Verification of Monty Hall problem by experimental simulation.

Verification of Monty Hall problem by experimental simulation. |中文|English| In the process of learning causal inference, I learned about the Monty Hal

云端听茗 1 Nov 22, 2022
IOP Support for Python (Experimental)

TAGS Experimental IOP Framework for Python WARNING: Currently, this project has NO EXCEPTION HANDLING. USE AT YOUR OWN RISK! I. Introduction to Interf

1 Oct 22, 2021
Multi-Process / Censorship Detection

Multi-Process / Censorship Detection

Baris Dincer 2 Dec 22, 2021
Find all social media accounts with a username!

Aliens_eye FIND ALL SOCIAL MEDIA ACCOUNTS WITH A USERNAME! OSINT To install: Open terminal and type: git clone https://github.com/BLINKING-IDIOT/Alien

Aaron Thomas 84 Dec 28, 2022
A fishing bot script written in Python!

A fishing bot script written in Python!

Anel Drocic 3 Nov 03, 2021
python package to showcase, test and build your own version of Pickhardt Payments

Pickhardt Payments Package The pickhardtpayments package is a collection of classes and interfaces that help you to test and implement your dialect of

Rene Pickhardt 37 Dec 18, 2022
Python solution of advent-of-code 2021

Advent of code 2021 Python solutions of Advent of Code 2021 written by Eric Bouteillon Requirements The solutions were developed and tested using Pyth

Eric Bouteillon 3 Oct 25, 2022
Ingest openldap data into bloodhound

Bloodhound for Linux Ingest a dumped OpenLDAP ldif into neo4j to be visualized in Bloodhound. Usage: ./ldif_to_neo4j.py ./sample.ldif | cypher-shell -

Guillaume Quéré 71 Nov 09, 2022
tox-gh is a tox plugin which helps running tox on GitHub Actions with multiple different Python versions on multiple workers in parallel

tox-gh is a tox plugin which helps running tox on GitHub Actions with multiple different Python versions on multiple workers in parallel. This project is inspired by tox-travis.

tox development team 19 Dec 26, 2022
redun aims to be a more expressive and efficient workflow framework

redun yet another redundant workflow engine redun aims to be a more expressive and efficient workflow framework, built on top of the popular Python pr

insitro 372 Jan 04, 2023
This project is about for notifying moderators about uploaded photos on server.

This project is about for notifying moderators (people who moderate data from photos) about uploaded photos on server.

1 Nov 24, 2021
Python module used to generate random facts

Randfacts is a python library that generates random facts. You can use randfacts.get_fact() to return a random fun fact. Disclaimer: Facts are not gua

Tabulate 14 Dec 14, 2022
MatroSka Mod Compiler for ts4scripts

MMC Current Version: 0.2 MatroSka Mod Compiler for .ts4script files Requirements Have Python 3.7 installed and set as default. Running from Source pip

MatroSka 1 Dec 13, 2021
A program made in PYTHON🐍 that automatically performs data insertions into a POSTGRES database 🐘 , using as base a .CSV file 📁 , useful in mass data insertions

A program made in PYTHON🐍 that automatically performs data insertions into a POSTGRES database 🐘 , using as base a .CSV file 📁 , useful in mass data insertions.

Davi Galdino 1 Oct 17, 2022
Exploring basic lambda calculus in Python

Lambda Exploring basic lambda calculus in Python. In this repo I have used the lambda function built into python to get a more intiutive feel of lambd

Bhardwaj Bhaskar 2 Nov 12, 2021