Skip to main content

Hassle free git hooks for python projects.

Project description

barb

Hassle-free, cross-platform git hooks for python projects

PyPi Download PyPi Download

Installation

pip install barb

Initializing a new project

barb init

Running this command both initializes the .barb directory as well as runs the barb install command.

Installing barb

To register the hooks under the .barb directory with git, run barb install

Creating a hook

Create a script under the .barb directory with the same name as the git hook you are attempting to create.

You can create two types of scripts to work as hooks:

  • The standard shell script, which will be executed by the operating system's default cli.
    ex.
./.barb/pre-commit
---
#!/bin/sh
echo "Hello, World!"
  • A python script. The script will enter at the hook() function. Not all hooks pass arguments, but those that provide them do so via the args parameter.
./.barb/pre-push.py
---
def hook(*args):
  print('Hello, World!')

Exceptions and False return values from this function will be considered hook failures.

Hooks can be organized in one of two ways. Top level files will be run on each os, without consideration:

.barb
├── pre-commit
└── post-rewrite.py

Alternatively, when organized in folders, different scripts can be set to run depending on the operating system:

.barb
└── post-rewrite
    ├── linux.py
    ├── darwin
    └── windows.ps1

.barbrc.toml

A configuration file is automatically created when the command barb init is run. The following are valid configurations

  • os-lock
    • If enabled, git hooks will only attempt to execute on the specified operating system. Otherwise, they will be skipped.
    • ex. os-lock = windows
  • [os.$OS$.$FILE_EXT$]
    • interpreter
      • The name (or path) of the interpreter to use for the file extension.
    • args
      • A list of arguments for the interpreter.
      • Note: the arguments are placed before the git hook path.
    • # Special Case: default interpreter for file ext with no interpreter specified
      [os.linux.default] 
      interpreter = 'bash'
      
    • # executes ps1 files as "powershell -ExecutionPolicy Unrestricted -File ./.barb/git-hook-name.ps1"
      [os.windows.ps1]
      interpreter = 'powershell'
      args = ['-ExecutionPolicy', 'Unrestricted', '-File']
      

TODO:

  • line endings, barb sanitize to sanitize the hooks?

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

barb-0.2.5-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file barb-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: barb-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.0

File hashes

Hashes for barb-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 61fa3e7c24b0c77792b4f609c977d725275a39a9550529228d4ce05b34e42b83
MD5 7839c25775f6c5498100a260524aedd7
BLAKE2b-256 d38a76f20f7baeb570f27f949ff45a1868d1d800d2e48558c25cd7823ea8b0a9

See more details on using hashes here.

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