Skip to content

Releases: greenbone/autohooks

autohooks 2.0.0

20 Nov 14:39
72dffad
Compare
Choose a tag to compare

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