The add_license_headers.py
module#
Summary#
Add lint arguments to the parser for REUSE. |
|
Link the default template and/or license from the assets folder to your git repo. |
|
Make .reuse or LICENSES directory and create symbolic link to file. |
|
Get a list of the files that are missing license headers. |
|
Set arguments for REUSE. |
|
Check if the committed file is missing its header. |
|
Check if the committed file is missing its header. |
|
Check if file before the hook ran is the same as after the hook ran. |
|
Add earlier hook changes to updated file with header. |
|
Update file paths to be absolute paths with system separators. |
|
Update the year or year range in the LICENSE file. |
|
Update the LICENSE file to match MIT.txt, adjusting the year span to each repository. |
|
Unlink the default asset files, and remove directories if empty. |
|
Find files that are missing license headers and run REUSE on them. |
|
Find files missing license headers and run REUSE on them. |
Default template to use for license headers. |
|
Default copyright line for license headers. |
|
Default license for headers. |
|
Description#
Module for running REUSE to add missing license headers to files.
A license header consists of the Ansys copyright statement and licensing information.
Module detail#
- add_license_headers.set_lint_args(parser: argparse.ArgumentParser) argparse.Namespace #
Add lint arguments to the parser for REUSE.
- Parameters:
- parser: argparse.ArgumentParser
Parser without any lint arguments.
- Returns:
argparse.Namespace
Parser namespace containing lint arguments.
- add_license_headers.link_assets(assets: dict, git_root: str, args: argparse.Namespace) None #
Link the default template and/or license from the assets folder to your git repo.
- Parameters:
- assets: dict
Dictionary containing the asset folder information.
- git_root: str
Full path of the repository’s root directory.
- args: argparse.Namespace
Namespace of arguments with their values.
- add_license_headers.mkdirs_and_link(asset_dir: str, hook_asset_dir: str, repo_asset_dir: str, filename: str) None #
Make .reuse or LICENSES directory and create symbolic link to file.
- Parameters:
- asset_dir: str
Path of the asset directory required for REUSE (.reuse/templates or LICENSES).
- hook_asset_dir: str
Full path of the hook’s asset directory.
- repo_asset_dir: str
Full path of the git repository’s asset directory.
- filename: str
Name of the file to be linked from the hook_asset_dir to the repo_asset_dir.
- add_license_headers.list_noncompliant_files(args: argparse.Namespace, proj: reuse.project.Project) list #
Get a list of the files that are missing license headers.
- add_license_headers.set_header_args(parser: argparse.ArgumentParser, start_year: str, current_year: int, file_path: str, copyright: str, template: str) argparse.Namespace #
Set arguments for REUSE.
- Parameters:
- parser: argparse.ArgumentParser
Parser containing default license header arguments.
- year: int
Current year retrieved by datetime.
- file_path: str
Specific file path to create license headers.
- copyright: str
Copyright line for license headers.
- template: str
Name of the template for license headers (name.jinja2).
- Returns:
argparse.Namespace
Namespace of arguments with their values.
- add_license_headers.non_recursive_file_check(changed_headers, parser, values, proj, missing_headers)#
Check if the committed file is missing its header.
- Parameters:
- changed_headers: int
0
if no headers were added or updated.1
if headers were added or updated.- parser: argparse.ArgumentParser
Parser containing default license header arguments.
- values: dict
Dictionary containing the values of files, copyright, template, license, changed_headers, year, and git_repo.
- proj: project.Project
Project to run REUSE on.
- missing_headers: list
Committed files that are missing copyright and/or license information in their headers.
- Returns:
int
0
if all files contain headers and are up to date.1
ifREUSE
changed all noncompliant files.
- add_license_headers.recursive_file_check(changed_headers, parser, values, proj, missing_headers, count)#
Check if the committed file is missing its header.
- Parameters:
- changed_headers: int
0
if no headers were added or updated.1
if headers were added or updated.- parser: argparse.ArgumentParser
Parser containing default license header arguments.
- values: dict
Dictionary containing the values of files, copyright, template, license, changed_headers, year, and git_repo.
- proj: project.Project
Project to run REUSE on.
- missing_headers: list
Committed files that are missing copyright and/or license information in their headers.
- count: int
Integer of the location in the files array.
- Returns:
int
0
if all files contain headers and are up to date.1
ifREUSE
changed all noncompliant files.
- add_license_headers.check_same_content(before_hook, after_hook)#
Check if file before the hook ran is the same as after the hook ran.
- Parameters:
- before_hook: str
Path to file before add-license-headers was run.
- after_hook: str
Path to file after add-license-headers was run.
- Returns:
- bool
True
if the files have the same content.False
if the files have different content.
- add_license_headers.add_hook_changes(before_hook: str, after_hook: str) None #
Add earlier hook changes to updated file with header.
- Parameters:
- before_hook: str
Path to file before add-license-headers was run.
- after_hook: str
Path to file after add-license-headers was run.
- add_license_headers.get_full_paths(file_list: list) list #
Update file paths to be absolute paths with system separators.
- Parameters:
- file_list: list
List containing committed files.
- Returns:
list
List containing the full paths of committed files.
- add_license_headers.update_year_range(user_start_year, match_start_year, current_year, match_end_year)#
Update the year or year range in the LICENSE file.
- Parameters:
- user_start_year: str
The start year supplied by the user in the pre-commit hook configuration.
- match_start_year: str
The start year of the year range in the LICENSE file. For example, the LICENSE file contains the range “2023 - 2024”, so match_start_year is 2023.
- current_year: str
The current year based on the datetime module.
- match_end_year: str
The end year of the year range in the LICENSE file. For example, the LICENSE file contains the range “2023 - 2024”, so match_end_year is 2024.
- add_license_headers.update_license_file(arg_dict: dict) int #
Update the LICENSE file to match MIT.txt, adjusting the year span to each repository.
- Parameters:
- arg_dict: dict
Dictionary containing the committed files, custom copyright, template, license, changed_headers, start & end year, and git_repo
- add_license_headers.cleanup(assets: dict, os_git_root: str) None #
Unlink the default asset files, and remove directories if empty.
- Parameters:
- assets: dict
Dictionary containing assets information
- os_git_root: str
Full path of the repository’s root directory.
- add_license_headers.find_files_missing_header() int #
Find files that are missing license headers and run REUSE on them.
- Returns:
int
1
ifREUSE
changed all noncompliant files.2
if the.reuse
or location directory does not exist in the root path of the GitHub repository.
- add_license_headers.DEFAULT_TEMPLATE = 'ansys'#
Default template to use for license headers.
- add_license_headers.DEFAULT_COPYRIGHT = 'ANSYS, Inc. and/or its affiliates.'#
Default copyright line for license headers.
- add_license_headers.DEFAULT_LICENSE = 'MIT'#
Default license for headers.
- add_license_headers.DEFAULT_START_YEAR#