reuse.header module - reuse 6.1.2 documentation

Skip to content
Back to top
View this page

# reuse.header module

Functions for manipulating the comment headers of files.

reuse.header.create_header(reuse_info: ReuseInfo, header: str | None = None, template: Template | None = None, template_is_commented: bool = False, style: type[CommentStyle] | None = None, force_multi: bool = False, merge_copyrights: bool = False) → str

  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:

    - CommentCreateError – if a comment could not be created.

    - MissingReuseInfoError – if the generated comment is missing SPDX information.

reuse.header.place_header(header: str, before: str, after: str, has_existing_header: bool) → str

  Construct the resulting file with the header and the rest of the text in the file.

reuse.header.find_and_replace_header(text: str, reuse_info: ReuseInfo, template: Template | None = None, template_is_commented: bool = False, style: type[CommentStyle] | None = None, force_multi: bool = False, merge_copyrights: bool = False) → str

  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:

    - CommentCreateError – if a comment could not be created.

    - MissingReuseInfoError – if the generated comment is missing SPDX information.

reuse.header.add_new_header(text: str, reuse_info: ReuseInfo, template: Template | None = None, template_is_commented: bool = False, style: type[CommentStyle] | None = None, force_multi: bool = False, merge_copyrights: bool = False) → str

  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.