reuse.header module¶
Functions for manipulating the comment headers of files.
- exception reuse.header.MissingSpdxInfo[source]¶
Bases:
Exception
Some SPDX information is missing from the result.
- reuse.header.create_header(spdx_info: reuse.SpdxInfo, header: Optional[str] = None, template: Optional[jinja2.environment.Template] = None, template_is_commented: bool = False, style: Optional[reuse._comment.CommentStyle] = None, force_multi: bool = False) → str[source]¶
Create a header containing spdx_info. header is an optional argument containing a header which should be modified to include spdx_info. If header is not given, a brand new header is created.
template, template_is_commented, and style determine what the header will look like, and whether it will be commented or not.
- Raises
CommentCreateError – if a comment could not be created.
MissingSpdxInfo – if the generated comment is missing SPDX information.
- reuse.header.find_and_replace_header(text: str, spdx_info: reuse.SpdxInfo, template: Optional[jinja2.environment.Template] = None, template_is_commented: bool = False, style: Optional[reuse._comment.CommentStyle] = None, force_multi: bool = False) → str[source]¶
Find the first SPDX comment block in text. That comment block is replaced by a new comment block containing spdx_info. It is formatted as according to template. The template is normally uncommented, but if it is already commented, template_is_commented should be
True
.If both style and template_is_commented are provided, style is only used to find the header comment.
If the comment block already contained some SPDX information, that information is merged into spdx_info.
If no header exists, one is simply created.
text is returned with a new header.
- Raises
CommentCreateError – if a comment could not be created.
MissingSpdxInfo – if the generated comment is missing SPDX information.