reuse.project module#

Module that contains the central Project class.

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, dep5_copyright: Copyright | 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.

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.

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.

  • root – The root of the project.

  • include_submodules – Whether to also lint VCS submodules.

  • include_meson_subprojects – Whether to also lint Meson subprojects.

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.

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 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 the .reuse/dep5 file covers a file and there is also REUSE information within that file (or within its .license file), then two ReuseInfo objects are returned in the set, each with respective discovered REUSE information and information about the source.