licenseheaders is a Python 3 command-line tool designed to add or change license headers for all files of supported types in a given directory tree. It supports various predefined templates and allows for custom templates and variable substitutions. The current version is 0.8.8, and it appears to be actively maintained, with the last PyPI update on April 8, 2021, and GitHub issues still being addressed.
pip install licenseheadersVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `licenseheaders` via its command-line interface to add a predefined license template (LGPLv3) to a specific Python file, including a custom copyright owner.
Define variables explicitly using command-line arguments (e.g., `-o 'Your Name'`) or set corresponding environment variables (e.g., `export LICENSE_HEADERS_OWNER='Your Name'`).
For unsupported extensions or custom file types, consider using a custom template that includes the correct comment delimiters. Avoid using extensions with multiple dots.
Provide the full, absolute path to the template file instead of just its name (e.g., `-t /path/to/my_template.tmpl`). Ensure the template file is accessible within the hook's environment.
Ensure all template files are saved in UTF-8 encoding. If issues persist, verify file content manually or consider pre-processing templates to ensure correct encoding before passing them to the tool.
When specifying a template, use the full path to a custom template file (e.g., `licenseheaders -t /path/to/my_license.tmpl ...`) instead of relying on built-in template names.
Use the `--exclude` option to prevent `licenseheaders` from processing XML files (e.g., `licenseheaders ... -x '**/*.xml'`). Manually add headers to XML files, ensuring the XML processing instruction remains the first line.
Review the `--years` or `--current-year` arguments carefully. If using custom templates, ensure the year variable (`${YEARS}`) is clearly isolated from other numerical content. If the issue persists, consider manually inspecting and correcting affected files, or contributing a more specific regex to the project.