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
« 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
5from .base import ChecksumFileExistenceDiffer
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 """
14 always_added_files = set(["MANIFEST.in"])
16 def gather_files(self, verifying=False):
17 files_set = set()
19 manifest_path = os.path.join(self.root, "MANIFEST.in")
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)
25 with open(manifest_path, "r") as f:
26 manifest_in = f.read()
28 manifest = Manifest(self.root)
29 lines = manifest_in.splitlines()
31 if verifying:
32 lines = ["global-include *"] + lines
34 for line in lines:
35 line = line.strip()
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
42 manifest.process_directive(line)
44 for path in manifest.files:
45 files_set.add(os.path.relpath(path, start=self.root))
47 return files_set