add-license-headers setup#
The add-license-headers hook adds and updates license headers in specified directories and
file types using REUSE. Here is a sample license header for a
Python file generated by the template with a start year of 2023:
To get started, add the hook to your .pre-commit-config.yaml file:
- repo: https://github.com/ansys/pre-commit-hooks
rev: v0.5.2
hooks:
- id: add-license-headers
The hook runs on protocol buffer (PROTO) files in any directory, as well as Python files within
directories named src, examples, and tests.
If your repository was created before the current year, add the --start_year argument with the
year that your first file was committed. The ansys-pre-commit-hooks repository started in 2023,
so the .pre-commit-config.yaml file looks like this:
- repo: https://github.com/ansys/pre-commit-hooks
rev: v0.5.2
hooks:
- id: add-license-headers
args:
- --start_year=2023
By default, the ansys.jinja2 template is used to generate the license headers for files.
The template contains the following variables:
{{ copyright_line }}: Contains the current year and the phrase “ANSYS, Inc. and/or its affiliates.” by default.{{ expression }}: Contains the SPDX-License-Identifier expression, which is “MIT” by default.
add-license-headers hook arguments#
Argument |
Default value |
Description |
|---|---|---|
|
|
Copyright line to include in the license header. |
|
|
Name of the |
|
|
SPDX-License-Identifier expression to include in the license header. To view the list of valid SPDX license expressions, see the SPDX License List. |
|
|
Year that the first file was committed to the repository. |
|
|
Whether to check for the license in the header. |