reuse.global_licensing module - reuse 6.1.2 documentation

Skip to content
Back to top
View this page

# 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)

  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)

  Bases: `ABC`

  An abstract class that represents a configuration file that contains licensing information that is pertinent to other files in the project.

  source: str
  abstract classmethod from_file(path: str | PathLike[str], **kwargs: Any) → GlobalLicensing

    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]]

    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)

  Bases: `GlobalLicensing`

  A soft wrapper around `Copyright`.

  dep5_copyright: Copyright
  classmethod from_file(path: str | PathLike[str], **kwargs: Any) → ReuseDep5

    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]]

    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: Any | None, precedence: Any = PrecedenceType.CLOSEST, copyright_notices: Any | None = None, spdx_expressions: Any | None = None)

  Bases: `object`

  A class that maps to a single [[annotations]] table element in REUSE.toml.

  paths: set[str]
  precedence: PrecedenceType
  copyright_notices: set[CopyrightNotice]
  spdx_expressions: set[SpdxExpression]
  classmethod from_dict(values: dict[str, Any]) → AnnotationsItem

    Create an `AnnotationsItem` from a dictionary that uses the key-value pairs for an [[annotations]] table in REUSE.toml.

  matches(path: str) → bool

    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])

  Bases: `GlobalLicensing`

  A class that contains the data parsed from a REUSE.toml file.

  version: int
  annotations: list[AnnotationsItem]
  classmethod from_dict(values: dict[str, Any], source: str) → ReuseTOML

    Create a `ReuseTOML` from the dict version of REUSE.toml.

  classmethod from_toml(toml: str, source: str) → ReuseTOML

    Create a `ReuseTOML` from TOML text.

  classmethod from_file(path: str | PathLike[str], **kwargs: Any) → ReuseTOML

    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

    Find a `AnnotationsItem` that matches path. The latest match in `annotations` is returned.

  reuse_info_of(path: str | PathLike[str]) → dict[PrecedenceType, list[ReuseInfo]]

    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.

  property directory: PurePath

    The directory in which the REUSE.toml file is located.

class reuse.global_licensing.NestedReuseTOML(source: str, reuse_tomls: list[ReuseTOML])

  Bases: `GlobalLicensing`

  A class that represents a hierarchy of `ReuseTOML` objects.

  reuse_tomls: list[ReuseTOML]
  classmethod from_file(path: str | PathLike[str], **kwargs: Any) → NestedReuseTOML

    TODO: path is a directory instead of a file.

  reuse_info_of(path: str | PathLike[str]) → dict[PrecedenceType, list[ReuseInfo]]

    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.

  classmethod find_reuse_tomls(path: str | PathLike[str], include_submodules: bool = False, include_meson_subprojects: bool = False, vcs_strategy: VCSStrategy | None = None) → Generator[Path, None, None]

    Find all REUSE.toml files in path. path should be the root of the directory. If it is not, REUSE.toml files which are in ignored directories may not be correctly ignored.