License Header Check
raw JSON → 0.2.1 verified Mon Apr 27 auth: no python
A Python tool to check that source files have a license header. It scans files for a given regex pattern and reports files missing the header. Current version 0.2.1, released irregularly.
pip install license-header-check Common errors
error TypeError: 'str' object is not callable ↓
cause Trying to call the string instead of the checker object, e.g., `checker = LicenseHeaderCheck(...)` then `checker('...')`.
fix
Use
checker.check(headers=...) instead of checker(...). error ModuleNotFoundError: No module named 'license-header-check' ↓
cause Trying to import with hyphens, but Python modules use underscores.
fix
Use
import license_header_check or from license_header_check import .... Warnings
gotcha The `check` method returns a list of file paths missing the header, not a boolean. Do not use `if checker.check(...):` expecting True/False. ↓
fix Use `if len(missing) > 0:` or `if missing:`.
gotcha The `headers` parameter must be a list of strings. Passing a single string will iterate over characters. ↓
fix Wrap in list: `headers=['# License ...']`.
Imports
- LicenseHeaderCheck wrong
from license-header-check import LicenseHeaderCheckcorrectfrom license_header_check import LicenseHeaderCheck
Quickstart
from license_header_check import LicenseHeaderCheck
checker = LicenseHeaderCheck('.', patterns=['\.py$'], comment='#')
missing = checker.check(headers=['# SPDX-License-Identifier: MIT'])
print('Missing headers in:', missing)