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

25 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-07-02 14: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( 

24 manifest_path, os.strerror(errno.ENOENT), manifest_path 

25 ) 

26 

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

28 manifest_in = f.read() 

29 

30 manifest = Manifest(self.root) 

31 lines = manifest_in.splitlines() 

32 

33 if verifying: 

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

35 

36 for line in lines: 

37 line = line.strip() 

38 

39 # distlib.manifest bombs on empty lines. 

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

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

42 continue 

43 

44 manifest.process_directive(line) 

45 

46 for path in manifest.files: 

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

48 

49 return files_set