Skip to main content

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

Metadata

Release files for pre-commit-license-headers 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pre-commit-license-headers 0.1.0
File Size Uploaded Provenance Actions
pre-commit-license-headers-0.1.0.tar.gz 6.2 kB Without provenance Details for pre-commit-license-headers-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pre-commit-license-headers 0.1.0
File Interpreter ABI Platform Actions
pre_commit_license_headers-0.1.0-py3-none-any.whl Python 3 none any Details for pre_commit_license_headers-0.1.0-py3-none-any.whl

Total release size: 13.4 kB

Release files / pre-commit-license-headers-0.1.0.tar.gz

Download URL pre-commit-license-headers-0.1.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e853163a21d2c7253439e6d9745422dd0baad2b89e8f8eb83c5dfedab2bc8fce
BLAKE2b-256 checksum
How to use checksums
d99cd16274b770a30438cf76ed20d9221d85d9a8972678f325821267b6403bc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.10 CPython/3.6.9 Linux/4.15.0-173-generic

Release files / pre_commit_license_headers-0.1.0-py3-none-any.whl

Download URL pre_commit_license_headers-0.1.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60af1be0bc84d5de5203db37dca97a3f7151f7aa18f27c5c7562e8481c0b5d4d
BLAKE2b-256 checksum
How to use checksums
69d87c64c628d7d30d72af6c69dac613e368dd0c8458434164bedf5ff4d51c62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.10 CPython/3.6.9 Linux/4.15.0-173-generic

Security for pre-commit-license-headers 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page