reuse.header module#

Functions for manipulating the comment headers of files.

exception reuse.header.MissingReuseInfo[source]#

Bases: Exception

Some REUSE information is missing from the result.

reuse.header.add_arguments(parser)[source]#

Add arguments to parser.

Return type:

None

reuse.header.add_new_header(text, reuse_info, template=None, template_is_commented=False, style=None, force_multi=False, merge_copyrights=False)[source]#

Add a new header at the very top of text, similar to find_and_replace_header. But in this function, do not replace any headers or search for any existing REUSE information.

Raises:

CommentCreateError – if a comment could not be created.

Return type:

str

reuse.header.create_header(reuse_info, header=None, template=None, template_is_commented=False, style=None, force_multi=False, merge_copyrights=False)[source]#

Create a header containing reuse_info. header is an optional argument containing a header which should be modified to include reuse_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:
Return type:

str

reuse.header.find_and_replace_header(text, reuse_info, template=None, template_is_commented=False, style=None, force_multi=False, merge_copyrights=False)[source]#

Find the first SPDX comment block in text. That comment block is replaced by a new comment block containing reuse_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 REUSE information, that information is merged into reuse_info.

If no header exists, one is simply created.

text is returned with a new header.

Raises:
Return type:

str

reuse.header.run(args, project, out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]#

Add headers to files.

Return type:

int