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, header=None, template=None, template_is_commented=False, style=None)[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.
- Return type
-
reuse.header.
find_and_replace_header
(text, spdx_info, template=None, template_is_commented=False, style=None)[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.
- Return type