reuse package

Module contents

reuse is a tool for compliance with the REUSE Initiative recommendations.

exception reuse.IdentifierNotFound[source]

Bases: reuse.ReuseException

Could not find SPDX identifier for license file.

class reuse.Project(root)[source]

Bases: object

Simple object that holds the project’s root, which is necessary for many interactions.

all_files(directory=None)[source]

Yield all files in directory and its subdirectories.

The files that are not yielded are:

  • Files ignored by VCS (e.g., see .gitignore)
  • Files/directories matching IGNORE_*_PATTERNS.

If directory is a file, yield it if it is not ignored.

Return type:Iterator[Path]
bill_of_materials(out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, ignore_debian=False)[source]

Generate a bill of materials from the project. The bill of materials is written to out.

See https://spdx.org/specifications.

Return type:None
licenses

Return a dictionary of all licenses in the project, with their SPDX identifiers as names and paths as values.

If no name could be found for a license file, name it “LicenseRef-Unknown0” and count upwards for every other unknown file.

Return type:Dict[str, Path]
lint(path=None, spdx_mandatory=True, copyright_mandatory=True, ignore_debian=False, ignore_missing=False)[source]

Yield all files under path that are not compliant with the REUSE recommendations.

If path is not specified, it becomes root.

The modifiers are explained in lint_file().

Return type:Iterator[Path]
lint_file(path, spdx_mandatory=True, copyright_mandatory=True, ignore_debian=False, ignore_missing=False)[source]
Parameters:
  • path (Union[Path, str]) – A path to a file. If it is not a file, raise an OSError.
  • spdx_mandatory (bool) – The file must have an SPDX expression in its reuse information.
  • copyright_mandatory (bool) – The file must have a copyright line in its reuse information.
  • ignore_debian (bool) – copyright/debian will not be checked for reuse information.
  • ignore_missing (bool) – Declared licences in SPDX expression that could not be found in licenses will not affect the linter.

Check whether path complies with the REUSE recommendations. If it does, return 0. If it does not, return a non-zero integer. In a future version, the non-zero integer may be a bit mask.

If both spdx_mandatory and copyright_mandatory are false, this function more or less becomes useless. Common sense is advised.

Return type:int
reuse_info_of(path, ignore_debian=False)[source]

Get the reuse information of path.

This function will return any reuse information that it can find, both from within the file and from the debian/copyright file. If none is found, an empty ReuseInfo object is returned.

Return type:ReuseInfo
root

Path to the root of the project.

Return type:Path
exception reuse.ReuseException[source]

Bases: Exception

Base exception.

class reuse.ReuseInfo(spdx_expressions, copyright_lines)

Bases: tuple

Simple structure for holding REUSE information.

copyright_lines

Alias for field number 1

spdx_expressions

Alias for field number 0

reuse.extract_reuse_info(text)[source]

Extract reuse information from comments in a string.

Return type:ReuseInfo
reuse.extract_valid_license(text)[source]

Extract SPDX identifier from a string.

Return type:Set[str]