Skip to main content

A pre-commit hook to check source code license headers

Project description

Pre-Commit License Headers

A pre-commit hook to check the license headers of your source code files.

At present, it only supports checking files that use hash mark # comment syntax. For more info, see Supported file types.

Usage

Add an entry like this to your .pre-commit-config.yaml

- repo: https://github.com/johannsdg/pre-commit-license-headers
  rev: v0.1.0 # Use the ref you want to point at
  hooks:
    - id: check-license-headers
      args:
        - "--template"
        - |
          Copyright (c) [YEARS] [OWNER]
          Use of this source code is governed by a BSD-3-clause license that can
          be found in the LICENSE file or at https://opensource.org/licenses/BSD-3-Clause
        - "--owner=The Pre-Commit License Headers Authors"

(Note that the template provided above is the default, so if you are using BSD-3-clause and are happy with the wording, you can skip --template and just provide --owner)

[YEARS] and [OWNER] are optional variables in the header template. If used, they will automatically be replaced with:

  • [YEARS]: a regular expression that accepts various combinations of years, such as:
    • Single years, such as '2019' or '2021'
    • Year ranges, such as '2018-2020'
    • Combinations, such as '2014, 2016-2018, 2020'
    • Note that ranges ending in '-present' are not supported
  • [OWNER]: the contents of the --owner argument
    • Note that --owner is optional unless the template uses the [OWNER] variable

Supported file types

Pre-Commit License Headers supports checking file types that use hash mark # comment syntax.

This includes:

  • python
  • shell
  • yaml
  • toml
  • plain-text
  • etc

For the list of file types checked by default, see file_types.py You may override the default list with your own via the -f or --file-type option (may be specified multiple times).

File types are determined using the identify library. For more information about file types, see: https://pre-commit.com/#filtering-files-with-types

As a standalone package

Pre-Commit License Headers is also available as a standalone package.

To install via pip:

pip install pre-commit-license-headers

You may also clone this repo and install via poetry:

poetry install --no-dev

Either installation option will place the check-license-headers executable in your environment's configured binary directory (e.g., '.venv/bin')

To use:

foo@bar:~$ check-license-headers --help
usage: check-license-headers [-h] [-d] [--list-file-types] [-s] [-f FILE_TYPE]
                             [-o COPYRIGHT_OWNER] -t TEMPLATE
                             [FILE [FILE ...]]

Checks if file headers match a provided template.

positional arguments:
  FILE

optional arguments:
  -h, --help            show this help message and exit
  -d, --debug
  --list-file-types     lists all text file types and exits
  -s, --summary         prints a summary after checking the files
  -f FILE_TYPE, --file-type FILE_TYPE
                        may be specified multiple times
  -o COPYRIGHT_OWNER, --owner COPYRIGHT_OWNER
  -t TEMPLATE, --template TEMPLATE

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

pre-commit-license-headers-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file pre-commit-license-headers-0.1.0.tar.gz.

File metadata

  • Download URL: pre-commit-license-headers-0.1.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.10 CPython/3.6.9 Linux/4.15.0-173-generic

File hashes

Hashes for pre-commit-license-headers-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e853163a21d2c7253439e6d9745422dd0baad2b89e8f8eb83c5dfedab2bc8fce
MD5 4c628a53294cb53ce7e68f36fd07cf10
BLAKE2b-256 d99cd16274b770a30438cf76ed20d9221d85d9a8972678f325821267b6403bc8

See more details on using hashes here.

File details

Details for the file pre_commit_license_headers-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pre_commit_license_headers-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60af1be0bc84d5de5203db37dca97a3f7151f7aa18f27c5c7562e8481c0b5d4d
MD5 8b81aee50982baa614af0cc9fff81627
BLAKE2b-256 69d87c64c628d7d30d72af6c69dac613e368dd0c8458434164bedf5ff4d51c62

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