Coverage for rust2rpm/project/meta.py: 100%

31 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-25 18:52 +0100

1"""Module containing base project classes.""" 

2 

3from abc import ABCMeta, abstractmethod 

4from dataclasses import dataclass 

5 

6from cargo2rpm.metadata import Metadata 

7 

8 

9class InvalidVersionError(ValueError): 

10 """Raised for version arguments that either don't parse as valid SemVer or don't resolve to an existing version.""" 

11 

12 

13@dataclass(frozen=True) 

14class PatchFile: 

15 """Representation of an automatically generated or manually applied Patch for Cargo.toml.""" 

16 

17 name: str 

18 """File name of the patch.""" 

19 

20 contents: list[str] 

21 """Contents of the patch as a list of lines.""" 

22 

23 

24@dataclass(frozen=True) 

25class Project(metaclass=ABCMeta): 

26 """Base class for loaded cargo projects.""" 

27 

28 name: str 

29 """Name of the project.""" 

30 

31 version: str 

32 """Version of the project.""" 

33 

34 metadata: Metadata 

35 """Metadata associated with the project (from `cargo metadata`).""" 

36 

37 license_files: list[str] 

38 """List of license files found by crawling the project sources.""" 

39 

40 doc_files: list[str] 

41 """List of documentation files found by crawling the project sources.""" 

42 

43 auto_patch: PatchFile | None 

44 """Automatically generated patch for Cargo.toml (if present).""" 

45 

46 manual_patch: PatchFile | None 

47 """Manually applied patch for Cargo.toml (if present).""" 

48 

49 vendor_tarball: str | None 

50 """File name of the tarball that contains vendored dependencies (if present).""" 

51 

52 @property 

53 @abstractmethod 

54 def rpm_name(self) -> str: 

55 """RPM source package name based on project metadata."""