Skip to content

Commit 9ed5afb

Browse files
committed
fix test and linting
1 parent dcda524 commit 9ed5afb

File tree

3 files changed

+36
-39
lines changed

3 files changed

+36
-39
lines changed

src/gardenlinux/features/reproducibility/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .markdown_formatter import MarkdownFormatter
1515

1616

17-
def generate(args) -> None:
17+
def generate(args: argparse.Namespace) -> None:
1818
"""
1919
Call Comparator
2020
@@ -41,7 +41,7 @@ def generate(args) -> None:
4141
exit(1)
4242

4343

44-
def format(args) -> None:
44+
def format(args: argparse.Namespace) -> None:
4545
"""
4646
Call MarkdownFormatter
4747

src/gardenlinux/features/reproducibility/comparator.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import tempfile
1212
from os import PathLike
1313
from pathlib import Path
14+
from typing import Optional
1415

1516

1617
class Comparator(object):
@@ -26,7 +27,7 @@ class Comparator(object):
2627
Apache License, Version 2.0
2728
"""
2829

29-
_default_whitelist = []
30+
_default_whitelist: list[str] = []
3031

3132
_nightly_whitelist = [
3233
r"/etc/apt/sources\.list\.d/gardenlinux\.sources",
@@ -56,7 +57,7 @@ def __init__(
5657
self.whitelist += self._nightly_whitelist
5758

5859
@staticmethod
59-
def _unpack(file: PathLike[str]) -> tempfile.TemporaryDirectory:
60+
def _unpack(file: PathLike[str]) -> tempfile.TemporaryDirectory[str]:
6061
"""
6162
Unpack a .tar archive or .oci image into a temporary dictionary
6263
@@ -112,8 +113,8 @@ def _unpack(file: PathLike[str]) -> tempfile.TemporaryDirectory:
112113
return output_dir
113114

114115
def _diff_files(
115-
self, cmp: filecmp.dircmp, left_root: PathLike[str] = None
116-
) -> list[Path]:
116+
self, cmp: filecmp.dircmp[str], left_root: Optional[Path] = None
117+
) -> list[str]:
117118
"""
118119
Recursively compare files
119120
@@ -126,14 +127,14 @@ def _diff_files(
126127

127128
result = []
128129
if not left_root:
129-
left_root = cmp.left
130+
left_root = Path(cmp.left)
130131
for name in cmp.diff_files:
131-
result.append(f"/{Path(cmp.left).relative_to(left_root).joinpath(name)}")
132+
result.append(f"/{left_root.relative_to(left_root).joinpath(name)}")
132133
for sub_cmp in cmp.subdirs.values():
133134
result += self._diff_files(sub_cmp, left_root=left_root)
134135
return result
135136

136-
def generate(self, a: PathLike[str], b: PathLike[str]) -> tuple[list[Path], bool]:
137+
def generate(self, a: PathLike[str], b: PathLike[str]) -> tuple[list[str], bool]:
137138
"""
138139
Compare two .tar/.oci images with each other
139140
@@ -144,7 +145,7 @@ def generate(self, a: PathLike[str], b: PathLike[str]) -> tuple[list[Path], bool
144145
:since: 1.0.0
145146
"""
146147

147-
if filecmp.cmp(a, b):
148+
if filecmp.cmp(a, b, shallow=False):
148149
return [], False
149150

150151
with self._unpack(a) as unpacked_a, self._unpack(b) as unpacked_b:

src/gardenlinux/features/reproducibility/diff_parser.py

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import re
1010
from os import PathLike
1111
from pathlib import Path
12-
from typing import Any, Optional
12+
from typing import Any, Dict, Optional
1313

1414
import networkx as nx
1515

@@ -56,30 +56,30 @@ def __init__(
5656
self._parser = Parser(gardenlinux_root, feature_dir_name, logger)
5757
self._feature_dir_name = Path(self._gardenlinux_root).joinpath(feature_dir_name)
5858

59-
self.all = set()
60-
self.successful = []
61-
self.whitelist = []
62-
self.expected_falvors = set()
63-
self.missing_flavors = set()
64-
self.unexpected_falvors = set()
59+
self.all: set[str] = set()
60+
self.successful: set[str] = set()
61+
self.whitelist: set[str] = set()
62+
self.expected_falvors: set[str] = set()
63+
self.missing_flavors: set[str] = set()
64+
self.unexpected_falvors: set[str] = set()
6565

66-
def read_feature_info(self, feature: str) -> dict[str, Any]:
66+
def read_feature_info(self, feature: str) -> Any:
6767
"""
6868
Read the content of the feature info.yaml
6969
7070
:param feature: The queried feature
7171
72-
:return: dict[str, Any] Parsed content of the features' info.yaml file
72+
:return: Dict[str, Any] Parsed content of the features' info.yaml file
7373
:since: 1.0.0
7474
"""
7575
return self._parser.read_feature_yaml(
76-
self._feature_dir_name.joinpath(f"{feature}/info.yaml")
76+
str(self._feature_dir_name.joinpath(f"{feature}/info.yaml"))
7777
)["content"]
7878

7979
def parse(
8080
self,
81-
flavors_matrix: dict[str, list[dict[str, str]]],
82-
bare_flavors_matrix: dict[str, list[dict[str, str]]],
81+
flavors_matrix: Dict[str, list[Dict[str, str]]],
82+
bare_flavors_matrix: Dict[str, list[Dict[str, str]]],
8383
diff_dir: PathLike[str] = Path("diffs"),
8484
) -> None:
8585
"""
@@ -93,20 +93,16 @@ def parse(
9393
"""
9494

9595
self.all = set()
96-
self.successful = []
97-
self.whitelist = []
96+
self.successful = set()
97+
self.whitelist = set()
9898
failed = {} # {flavor: [files...]}
9999

100100
diff_dir = Path(self._gardenlinux_root).joinpath(diff_dir)
101101

102-
self.expected_falvors = set(
103-
[
104-
f"{variant['flavor']}-{variant['arch']}"
105-
for variant in (
106-
flavors_matrix["include"] + bare_flavors_matrix["include"]
107-
)
108-
]
109-
)
102+
self.expected_falvors = {
103+
f"{variant['flavor']}-{variant['arch']}"
104+
for variant in (flavors_matrix["include"] + bare_flavors_matrix["include"])
105+
}
110106

111107
for flavor in os.listdir(diff_dir):
112108
if flavor.endswith(self._SUFFIX):
@@ -116,38 +112,38 @@ def parse(
116112
flavor = flavor.rstrip(self._SUFFIX)
117113
self.all.add(flavor)
118114
if content == "":
119-
self.successful.append(flavor)
115+
self.successful.add(flavor)
120116
elif content == "whitelist\n":
121-
self.successful.append(flavor)
122-
self.whitelist.append(flavor)
117+
self.successful.add(flavor)
118+
self.whitelist.add(flavor)
123119
else:
124120
failed[flavor] = content.split("\n")[:-1]
125121

126122
self.missing_flavors = self.expected_falvors - self.all
127123
self.unexpected_falvors = self.all - self.expected_falvors
128124

129125
# Map files to flavors
130-
affected: dict[str, set[str]] = {} # {file: {flavors...}}
126+
affected: Dict[str, set[str]] = {} # {file: {flavors...}}
131127
for flavor in failed:
132128
for file in failed[flavor]:
133129
if file not in affected:
134130
affected[file] = set()
135131
affected[file].add(flavor)
136132

137133
# Merge files affected by the same flavors by mapping flavor sets to files
138-
self._bundled: dict[frozenset[str], set[str]] = {} # {{flavors...}: {files...}}
134+
self._bundled: Dict[frozenset[str], set[str]] = {} # {{flavors...}: {files...}}
139135
for file in affected:
140136
if frozenset(affected[file]) not in self._bundled:
141137
self._bundled[frozenset(affected[file])] = set()
142138
self._bundled[frozenset(affected[file])].add(file)
143139

144140
def intersectionTrees(
145141
self,
146-
) -> dict[frozenset[str], tuple[frozenset[str], nx.DiGraph]]:
142+
) -> Dict[frozenset[str], tuple[frozenset[str], nx.DiGraph]]:
147143
"""
148144
Intersects all features of the affected flavors and removes all features from unaffected flavors to identify features causing the issue
149145
150-
:return: (dict[frozenset[str], tuple[frozenset[str], nx.DiGraph]]) Dict in the form of {{files...}: ({flavors..., intersectionTree})}
146+
:return: (Dict[frozenset[str], tuple[frozenset[str], nx.DiGraph]]) Dict in the form of {{files...}: ({flavors..., intersectionTree})}
151147
:since: 1.0.0
152148
"""
153149

0 commit comments

Comments
 (0)