reuse.global_licensing module¶
Code for parsing and validating REUSE.toml.
- reuse.global_licensing.REUSE_TOML_VERSION = 1¶
Current version of REUSE.toml.
- class reuse.global_licensing.PrecedenceType(value)[source]¶
Bases:
Enum
An enum of behaviours surrounding order of precedence for entries in a
GlobalLicensing
.- AGGREGATE = 'aggregate'¶
Aggregate the results from the file with the results from the global licensing file.
- CLOSEST = 'closest'¶
Use the results that are closest to the covered file. This is typically the file itself, or the global licensing file if no REUSE information exists inside of the file.
- OVERRIDE = 'override'¶
Only use the results from the global licensing file.
- class reuse.global_licensing.GlobalLicensing(source: str)[source]¶
Bases:
ABC
An abstract class that represents a configuration file that contains licensing information that is pertinent to other files in the project.
- abstract classmethod from_file(path: str | PathLike[str], **kwargs: Any) GlobalLicensing [source]¶
Parse the file and create a
GlobalLicensing
object from its contents.- Raises:
FileNotFoundError – file doesn’t exist.
OSError – some other error surrounding I/O.
GlobalLicensingParseError – file could not be parsed.
- abstract reuse_info_of(path: str | PathLike[str]) dict[PrecedenceType, list[ReuseInfo]] [source]¶
Find the REUSE information of path defined in the configuration. The path must be relative to the root of a
reuse.project.Project
.The key indicates the precedence type for the subsequent information.
- class reuse.global_licensing.ReuseDep5(source: str, dep5_copyright: Copyright)[source]¶
Bases:
GlobalLicensing
A soft wrapper around
Copyright
.- dep5_copyright: Copyright¶
- classmethod from_file(path: str | PathLike[str], **kwargs: Any) ReuseDep5 [source]¶
Parse the file and create a
GlobalLicensing
object from its contents.- Raises:
FileNotFoundError – file doesn’t exist.
OSError – some other error surrounding I/O.
GlobalLicensingParseError – file could not be parsed.
- reuse_info_of(path: str | PathLike[str]) dict[PrecedenceType, list[ReuseInfo]] [source]¶
Find the REUSE information of path defined in the configuration. The path must be relative to the root of a
reuse.project.Project
.The key indicates the precedence type for the subsequent information.
- class reuse.global_licensing.AnnotationsItem(paths: str | None | _T | Collection[_T], precedence: Any = PrecedenceType.CLOSEST, copyright_lines: str | None | _T | Collection[_T] = None, spdx_expressions: Any | None = None)[source]¶
Bases:
object
A class that maps to a single [[annotations]] table element in REUSE.toml.
- precedence: PrecedenceType¶
- classmethod from_dict(values: dict[str, Any]) AnnotationsItem [source]¶
Create an
AnnotationsItem
from a dictionary that uses the key-value pairs for an [[annotations]] table in REUSE.toml.
- matches(path: str) bool [source]¶
Determine whether path matches any of the paths (or path globs) in
AnnotationsItem
.
- class reuse.global_licensing.ReuseTOML(source: str, version: int, annotations: list[AnnotationsItem])[source]¶
Bases:
GlobalLicensing
A class that contains the data parsed from a REUSE.toml file.
- annotations: list[AnnotationsItem]¶
- classmethod from_dict(values: dict[str, Any], source: str) ReuseTOML [source]¶
Create a
ReuseTOML
from the dict version of REUSE.toml.
- classmethod from_toml(toml: str, source: str) ReuseTOML [source]¶
Create a
ReuseTOML
from TOML text.
- classmethod from_file(path: str | PathLike[str], **kwargs: Any) ReuseTOML [source]¶
Parse the file and create a
GlobalLicensing
object from its contents.- Raises:
FileNotFoundError – file doesn’t exist.
OSError – some other error surrounding I/O.
GlobalLicensingParseError – file could not be parsed.
- find_annotations_item(path: str | PathLike[str]) AnnotationsItem | None [source]¶
Find a
AnnotationsItem
that matches path. The latest match inannotations
is returned.
- reuse_info_of(path: str | PathLike[str]) dict[PrecedenceType, list[ReuseInfo]] [source]¶
Find the REUSE information of path defined in the configuration. The path must be relative to the root of a
reuse.project.Project
.The key indicates the precedence type for the subsequent information.
- class reuse.global_licensing.NestedReuseTOML(source: str, reuse_tomls: list[ReuseTOML])[source]¶
Bases:
GlobalLicensing
A class that represents a hierarchy of
ReuseTOML
objects.- classmethod from_file(path: str | PathLike[str], **kwargs: Any) GlobalLicensing [source]¶
TODO: path is a directory instead of a file.
- reuse_info_of(path: str | PathLike[str]) dict[PrecedenceType, list[ReuseInfo]] [source]¶
Find the REUSE information of path defined in the configuration. The path must be relative to the root of a
reuse.project.Project
.The key indicates the precedence type for the subsequent information.