reuse.project module

Module that contains the central Project class.

exception reuse.project.GlobalLicensingConflict[source]

Bases: Exception

There are two global licensing files in the project that are not compatible.

class reuse.project.GlobalLicensingFound(path, cls)[source]

Bases: tuple

path: Path

Alias for field number 0

cls: Type[GlobalLicensing]

Alias for field number 1

class reuse.project.Project(root: str | PathLike, vcs_strategy: Type[VCSStrategy] | None = None, license_map: Dict[str, Dict] | None = None, licenses: Dict[str, Path] | None = None, global_licensing: GlobalLicensing | None = None, include_submodules: bool = False, include_meson_subprojects: bool = False)[source]

Bases: object

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

classmethod from_directory(root: str | PathLike, include_submodules: bool = False, include_meson_subprojects: bool = False) Project[source]

A factory method that reads various files in the root directory to correctly build the Project object.

Parameters:
  • root – The root of the project.

  • include_submodules – Whether to also lint VCS submodules.

  • include_meson_subprojects – Whether to also lint Meson subprojects.

Raises:
all_files(directory: str | PathLike | None = None) Iterator[Path][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.

reuse_info_of(path: str | PathLike) List[ReuseInfo][source]

Return REUSE info of path.

This function will return any REUSE information that it can find: from within the file, the .license file, from REUSE.toml, and/or from the .reuse/dep5 file.

The presence of a .license file always means that the file itself will not be parsed for REUSE information.

When information is found from multiple sources, and if the precedence for that file in REUSE.toml is ‘aggregate’ (or if .reuse/dep5 is used), then two (or more) ReuseInfo objects are returned in list set, each with respective discovered REUSE information and information about the source.

Alternatively, if the precedence is set to ‘closest’ or ‘toml’, or if information was found in only one source, then a list of one item is returned.

The exact precedence handling is detailed in the specification.

An empty list is returned if no information was found whatsoever.

relative_from_root(path: str | PathLike) Path[source]

If the project root is /tmp/project, and path is /tmp/project/src/file, then return src/file.

classmethod find_global_licensing(root: Path) GlobalLicensingFound | None[source]

Find the path and corresponding class of a project directory’s GlobalLicensing.

Raises:

GlobalLicensingConflict – if more than one global licensing config file is present.