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
- Note that
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pre-commit-license-headers-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e853163a21d2c7253439e6d9745422dd0baad2b89e8f8eb83c5dfedab2bc8fce |
|
MD5 | 4c628a53294cb53ce7e68f36fd07cf10 |
|
BLAKE2b-256 | d99cd16274b770a30438cf76ed20d9221d85d9a8972678f325821267b6403bc8 |
Hashes for pre_commit_license_headers-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60af1be0bc84d5de5203db37dca97a3f7151f7aa18f27c5c7562e8481c0b5d4d |
|
MD5 | 8b81aee50982baa614af0cc9fff81627 |
|
BLAKE2b-256 | 69d87c64c628d7d30d72af6c69dac613e368dd0c8458434164bedf5ff4d51c62 |