Coverage for src/ansible_sign/checksum/differ/distlib_manifest.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-05 08:12 +0000

1from distlib.manifest import Manifest 

2import errno 

3import os 

4 

5from .base import ChecksumFileExistenceDiffer 

6 

7 

8class DistlibManifestChecksumFileExistenceDiffer(ChecksumFileExistenceDiffer): 

9 """ 

10 Read in a MANIFEST.in file and process it. Use the results for comparing 

11 what is listed in the checksum file with what is "reality". 

12 """ 

13 

14 always_added_files = set(["MANIFEST.in"]) 

15 

16 def gather_files(self, verifying=False): 

17 files_set = set() 

18 

19 manifest_path = os.path.join(self.root, "MANIFEST.in") 

20 

21 if not os.path.exists(manifest_path): 

22 # open() would do this, but let us be explicit, the file must exist. 

23 raise FileNotFoundError(manifest_path, os.strerror(errno.ENOENT), manifest_path) 

24 

25 with open(manifest_path, "r") as f: 

26 manifest_in = f.read() 

27 

28 manifest = Manifest(self.root) 

29 lines = manifest_in.splitlines() 

30 

31 if verifying: 

32 lines = ["global-include *"] + lines 

33 

34 for line in lines: 

35 line = line.strip() 

36 

37 # distlib.manifest bombs on empty lines. 

38 # It also doesn't appear to allow comments, so let's hack those in. 

39 if not line or line[0] == "#": 

40 continue 

41 

42 manifest.process_directive(line) 

43 

44 for path in manifest.files: 

45 files_set.add(os.path.relpath(path, start=self.root)) 

46 

47 return files_set