Skip to content

Commit 9683616

Browse files
committed
black
1 parent 3dee5d0 commit 9683616

File tree

15 files changed

+119
-167
lines changed

15 files changed

+119
-167
lines changed

glitch/analysis/design.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,9 @@ def check_atomicunit(self, au: AtomicUnit, file: str) -> list[Error]:
370370
errors += self.misplaced_attr.check(au, file)
371371

372372
if au.type in DesignVisitor.__EXEC:
373-
if isinstance(au.name, str) and ("&&" in au.name or ";" in au.name or "|" in au.name):
373+
if isinstance(au.name, str) and (
374+
"&&" in au.name or ";" in au.name or "|" in au.name
375+
):
374376
errors.append(
375377
Error("design_multifaceted_abstraction", au, file, repr(au))
376378
)

glitch/analysis/terraform/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
for file in os.listdir(os.path.dirname(__file__)):
77
if file.endswith(".py") and file != "__init__.py":
8-
__all__.append(file[:-3]) # type: ignore
8+
__all__.append(file[:-3]) # type: ignore

glitch/analysis/terraform/access_control.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
class TerraformAccessControl(TerraformSmellChecker):
1010
def _check_attribute(
11-
self, attribute: Attribute | KeyValue, atomic_unit: AtomicUnit, parent_name: str, file: str
11+
self,
12+
attribute: Attribute | KeyValue,
13+
atomic_unit: AtomicUnit,
14+
parent_name: str,
15+
file: str,
1216
) -> List[Error]:
1317
for item in SecurityVisitor.POLICY_KEYWORDS:
1418
if item.lower() == attribute.name:

glitch/parsers/docker.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dataclasses import dataclass, field
55
from typing import List, Dict, Tuple, Optional, Union
66

7-
import bashlex # type: ignore
7+
import bashlex # type: ignore
88
from dockerfile_parse import DockerfileParser
99

1010
import glitch.parsers.parser as p
@@ -287,7 +287,7 @@ def to_atomic_unit(self) -> AtomicUnit:
287287
au.add_attribute(sudo)
288288
for key, (value, _) in self.options.items():
289289
has_variable = "$" in value if isinstance(value, str) else False
290-
attr = Attribute(key, value, has_variable) # type: ignore
290+
attr = Attribute(key, value, has_variable) # type: ignore
291291
attr.code = self.code
292292
attr.line = self.line
293293
au.add_attribute(attr)
@@ -311,7 +311,7 @@ def __init__(self, command: DFPStructure) -> None:
311311
def parse_command(self) -> List[AtomicUnit]:
312312
# TODO: Fix get commands lines for scripts with multiline values
313313
commands = self.__get_sub_commands()
314-
aus:List[AtomicUnit] = []
314+
aus: List[AtomicUnit] = []
315315
for line, c in commands:
316316
try:
317317
aus.append(self.__parse_single_command(c, line))
@@ -362,7 +362,7 @@ def __parse_shell_command(command: ShellCommand) -> None:
362362
command.main_arg = command.args[-1]
363363
if reference:
364364
reference[0]
365-
command.options["reference"] = (reference.split("=")[1], reference) # type: ignore
365+
command.options["reference"] = (reference.split("=")[1], reference) # type: ignore
366366
else:
367367
command.options["mode"] = command.args[0], command.args[0]
368368
else:
@@ -405,13 +405,13 @@ def __get_sub_commands(self) -> List[Tuple[int, List[str]]]:
405405
)
406406
current_line = self.line
407407
for i, line in enumerate(lines):
408-
for part in bashlex.split(line): # type: ignore
408+
for part in bashlex.split(line): # type: ignore
409409
if part in ["&&", "&", "|", ";"]:
410410
commands.append((current_line, tmp))
411411
current_line = self.line + i
412412
tmp = []
413413
continue
414-
tmp.append(part) # type: ignore
414+
tmp.append(part) # type: ignore
415415
commands.append((current_line, tmp))
416416
return commands
417417

glitch/parsers/terraform.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ def __get_element_code(start_line: int, end_line: int, code: List[str]) -> str:
1919
res += line
2020
return res
2121

22-
def parse_keyvalues(self, unit_block: UnitBlock, keyvalues: Dict[Any, Any], code: List[str], type: str) -> List[KeyValue]:
22+
def parse_keyvalues(
23+
self,
24+
unit_block: UnitBlock,
25+
keyvalues: Dict[Any, Any],
26+
code: List[str],
27+
type: str,
28+
) -> List[KeyValue]:
2329
def create_keyvalue(start_line: int, end_line: int, name: str, value: str):
2430
has_variable = (
25-
("${" in f"{value}") and ("}" in f"{value}") if value != None else False # type: ignore
31+
("${" in f"{value}") and ("}" in f"{value}") if value != None else False # type: ignore
2632
)
2733
pattern = r"^[+-]?\d+(\.\d+)?$"
2834
if has_variable and re.match(pattern, re.sub(r"^\${(.*)}$", r"\1", value)):
@@ -43,13 +49,13 @@ def create_keyvalue(start_line: int, end_line: int, name: str, value: str):
4349
keyvalue.code = TerraformParser.__get_element_code(
4450
start_line, end_line, code
4551
)
46-
52+
4753
return keyvalue
4854

4955
def process_list(name: str, value: str, start_line: int, end_line: int) -> None:
5056
for i, v in enumerate(value):
5157
if isinstance(v, dict):
52-
k = create_keyvalue(start_line, end_line, name + f"[{i}]", None) # type: ignore
58+
k = create_keyvalue(start_line, end_line, name + f"[{i}]", None) # type: ignore
5359
k.keyvalues = self.parse_keyvalues(unit_block, v, code, type)
5460
k_values.append(k)
5561
elif isinstance(v, list):
@@ -69,7 +75,7 @@ def process_list(name: str, value: str, start_line: int, end_line: int) -> None:
6975
value = keyvalue["value"]
7076
if isinstance(value, dict): # (ex: labels = {})
7177
k = create_keyvalue(
72-
keyvalue["__start_line__"], keyvalue["__end_line__"], name, None # type: ignore
78+
keyvalue["__start_line__"], keyvalue["__end_line__"], name, None # type: ignore
7379
)
7480
k.keyvalues = self.parse_keyvalues(unit_block, value, code, type)
7581
k_values.append(k)
@@ -90,7 +96,7 @@ def process_list(name: str, value: str, start_line: int, end_line: int) -> None:
9096
value,
9197
)
9298
k_values.append(k)
93-
elif isinstance(keyvalue, list) and type == "attribute": # type: ignore
99+
elif isinstance(keyvalue, list) and type == "attribute": # type: ignore
94100
# block (ex: access {} or dynamic setting {}; blocks of attributes; not allowed inside local values (variables))
95101
try:
96102
for block_attributes in keyvalue:
@@ -120,7 +126,9 @@ def process_list(name: str, value: str, start_line: int, end_line: int) -> None:
120126

121127
return k_values
122128

123-
def parse_atomic_unit(self, type: str, unit_block: UnitBlock, dict, code: List[str]) -> None:
129+
def parse_atomic_unit(
130+
self, type: str, unit_block: UnitBlock, dict, code: List[str]
131+
) -> None:
124132
def create_atomic_unit(
125133
start_line: int, end_line: int, type: str, name: str, code: List[str]
126134
) -> AtomicUnit:

glitch/repair/interactive/compiler/compiler.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ def add_attribute(self, attribute: Attribute) -> None:
2323
attribute.name, self.au_type, self.__tech
2424
)
2525

26-
self.__attributes[attr_name] = ( # type: ignore
26+
self.__attributes[attr_name] = ( # type: ignore
2727
DeltaPCompiler._compile_expr(
2828
NamesDatabase.get_attr_value(
29-
attribute.value, # type: ignore
29+
attribute.value, # type: ignore
3030
attr_name,
3131
self.au_type,
3232
self.__tech,
@@ -67,12 +67,14 @@ def create_label_var_pair(
6767
label = labeled_script.get_label(attr)
6868
else:
6969
# Creates sketched attribute
70-
if attr_name == "state" and isinstance(DefaultValue.DEFAULT_STATE.const, PStr): # HACK
70+
if attr_name == "state" and isinstance(
71+
DefaultValue.DEFAULT_STATE.const, PStr
72+
): # HACK
7173
attr = Attribute(
7274
attr_name, DefaultValue.DEFAULT_STATE.const.value, False
7375
)
7476
else:
75-
attr = Attribute(attr_name, PEUndef(), False) # type: ignore
77+
attr = Attribute(attr_name, PEUndef(), False) # type: ignore
7678

7779
attr.line, attr.column = (
7880
DeltaPCompiler._sketched,
@@ -104,7 +106,7 @@ def __handle_file(
104106
path = attributes["path"]
105107
# The path may be defined as the name of the atomic unit
106108
if path == PEUndef():
107-
path = PEConst(PStr(atomic_unit.name)) # type: ignore
109+
path = PEConst(PStr(atomic_unit.name)) # type: ignore
108110

109111
state_label, state_var = attributes.create_label_var_pair(
110112
"state", atomic_unit, labeled_script

glitch/repair/interactive/compiler/labeler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def label_attribute(
124124
"""
125125
type = NamesDatabase.get_au_type(atomic_unit.type, labeled.tech)
126126
name = NamesDatabase.get_attr_name(attribute.name, type, labeled.tech)
127-
labeled.add_label(name, attribute) # type: ignore
127+
labeled.add_label(name, attribute) # type: ignore
128128

129129
@staticmethod
130130
def label_atomic_unit(labeled: LabeledUnitBlock, atomic_unit: AtomicUnit) -> None:

glitch/repair/interactive/compiler/names_database.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def get_au_type(type: str, tech: Tech) -> str:
1919
return "file"
2020
case "ansible.builtin.file", Tech.ansible:
2121
return "file"
22-
case _: pass
22+
case _:
23+
pass
2324
return type
2425

2526
@staticmethod
@@ -47,13 +48,12 @@ def reverse_attr_name(name: str, au_type: str, tech: Tech) -> str:
4748
return "state"
4849
case "state", "file", Tech.puppet:
4950
return "ensure"
50-
case _: pass
51+
case _:
52+
pass
5153
return name
5254

5355
@staticmethod
54-
def reverse_attr_value(
55-
value: str, attr_name: str, au_type: str, tech: Tech
56-
) -> str:
56+
def reverse_attr_value(value: str, attr_name: str, au_type: str, tech: Tech) -> str:
5757
"""Returns the technology-specific value of the attribute with the given value, attribute name, atomic unit type and tech.
5858
5959
Args:
@@ -68,7 +68,8 @@ def reverse_attr_value(
6868
match value, attr_name, au_type, tech:
6969
case "present", "state", "file", Tech.ansible:
7070
return "file"
71-
case _: pass
71+
case _:
72+
pass
7273
return value
7374

7475
@staticmethod
@@ -98,7 +99,8 @@ def get_attr_name(name: str, au_type: str, tech: Tech) -> str:
9899
return "state"
99100
case "state", "file", Tech.ansible:
100101
return "state"
101-
case _: pass
102+
case _:
103+
pass
102104

103105
return name
104106

@@ -123,6 +125,7 @@ def get_attr_value(
123125
return "present"
124126
case "touch", "state", "file", Tech.ansible:
125127
return "present"
126-
case _: pass
128+
case _:
129+
pass
127130

128131
return value

glitch/repair/interactive/delta_p.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __get_str(self, expr: PExpr, vars: Dict[str, PExpr]) -> str:
127127
elif isinstance(expr, PEVar):
128128
return self.__get_str(vars[expr.id], vars)
129129
elif isinstance(expr, PEUndef):
130-
return None # type: ignore
130+
return None # type: ignore
131131

132132
raise RuntimeError(f"Unsupported expression, got {expr}")
133133

@@ -144,7 +144,7 @@ def __eval(self, expr: PExpr, vars: Dict[str, PExpr]) -> PExpr | None:
144144
return PEConst(PBool(True))
145145
else:
146146
return PEConst(PBool(False))
147-
147+
148148
return None
149149
# TODO: Add support for other operators and expressions
150150

glitch/repair/interactive/solver.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from copy import deepcopy
44
from typing import List, Callable, Tuple, Any
55
from z3 import (
6-
Solver,
6+
Solver,
77
sat,
88
If,
99
StringVal,
@@ -17,7 +17,7 @@
1717
Sum,
1818
ModelRef,
1919
Context,
20-
ExprRef
20+
ExprRef,
2121
)
2222

2323
from glitch.repair.interactive.filesystem import FileSystemState
@@ -117,7 +117,9 @@ def __compile_expr(self, expr: PExpr) -> ExprRef:
117117

118118
def __generate_hard_constraints(self, filesystem: FileSystemState) -> None:
119119
for path, state in filesystem.state.items():
120-
self.solver.add(self.__funs.state_fun(StringVal(path)) == StringVal(str(state)))
120+
self.solver.add(
121+
self.__funs.state_fun(StringVal(path)) == StringVal(str(state))
122+
)
121123
content, mode, owner = UNDEF, UNDEF, UNDEF
122124

123125
if isinstance(state, File):
@@ -126,7 +128,9 @@ def __generate_hard_constraints(self, filesystem: FileSystemState) -> None:
126128
mode = UNDEF if state.mode is None else state.mode
127129
owner = UNDEF if state.owner is None else state.owner
128130

129-
self.solver.add(self.__funs.contents_fun(StringVal(path) == StringVal(content)))
131+
self.solver.add(
132+
self.__funs.contents_fun(StringVal(path) == StringVal(content))
133+
)
130134
self.solver.add(self.__funs.mode_fun(StringVal(path) == StringVal(mode)))
131135
self.solver.add(self.__funs.owner_fun(StringVal(path) == StringVal(owner)))
132136

@@ -211,12 +215,12 @@ def __generate_soft_constraints(
211215
hole, var = String(f"loc-{statement.label}"), String(statement.id)
212216
self.holes[f"loc-{statement.label}"] = hole
213217
self.vars[statement.id] = var
214-
unchanged = self.unchanged[statement.label] # type: ignore
218+
unchanged = self.unchanged[statement.label] # type: ignore
215219
constraints.append(
216-
Or( # type: ignore
217-
And(unchanged == 1, var == self.__compile_expr(statement.expr)), # type: ignore
218-
And(unchanged == 0, var == hole), # type: ignore
219-
) # type: ignore
220+
Or( # type: ignore
221+
And(unchanged == 1, var == self.__compile_expr(statement.expr)), # type: ignore
222+
And(unchanged == 0, var == hole), # type: ignore
223+
) # type: ignore
220224
)
221225
body_constraints, funs = self.__generate_soft_constraints(
222226
statement.body, funs
@@ -292,7 +296,7 @@ def solve(self) -> Optional[List[ModelRef]]:
292296

293297
models.append(model)
294298
# Removes conditional variables that were not used
295-
dvars = filter(lambda v: model[v] is not None, self.vars.values()) # type: ignore
299+
dvars = filter(lambda v: model[v] is not None, self.vars.values()) # type: ignore
296300
self.solver.add(Not(And([v == model[v] for v in dvars])))
297301

298302
if elapsed >= self.timeout:
@@ -336,7 +340,7 @@ def apply_patch(
336340
changed: List[Tuple[int, Any]] = []
337341

338342
for label, unchanged in self.unchanged.items():
339-
if model_ref[unchanged] == 0: # type: ignore
343+
if model_ref[unchanged] == 0: # type: ignore
340344
hole = self.holes[f"loc-{label}"]
341345
changed.append((label, model_ref[hole]))
342346

@@ -351,7 +355,7 @@ def apply_patch(
351355
atomic_unit = labeled_script.get_sketch_location(codeelement)
352356
if not isinstance(atomic_unit, AtomicUnit):
353357
raise RuntimeError("Atomic unit not found")
354-
358+
355359
atomic_unit_type = NamesDatabase.get_au_type(
356360
atomic_unit.type, labeled_script.tech
357361
)

glitch/repair/interactive/tracer/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ def t_ID(t: LexToken):
118118
r"[a-zA-Z][a-zA-Z0-9_]*"
119119
if t.value in [flag.name for flag in OpenFlag]:
120120
t.type = "OPEN_FLAG"
121-
t.value = OpenFlag[t.value] # type: ignore
121+
t.value = OpenFlag[t.value] # type: ignore
122122
elif t.value in [flag.name for flag in ORedFlag]:
123123
t.type = "ORED_FLAG"
124-
t.value = ORedFlag[t.value] # type: ignore
124+
t.value = ORedFlag[t.value] # type: ignore
125125
elif t.value in [flag.name for flag in UnlinkFlag]:
126126
t.type = "UNLINK_FLAG"
127-
t.value = UnlinkFlag[t.value] # type: ignore
127+
t.value = UnlinkFlag[t.value] # type: ignore
128128
return t
129129

130130
def t_STRING(t: LexToken):

glitch/repair/interactive/tracer/tracer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, pid: str) -> None:
1212
self.syscalls: List[Syscall] = []
1313
self.pid = pid
1414

15-
def run(self) -> List[Syscall]: # type: ignore
15+
def run(self) -> List[Syscall]: # type: ignore
1616
proc = subprocess.Popen(
1717
[
1818
"sudo",

glitch/repr/inter.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,9 @@ def __repr__(self) -> str:
199199

200200
def print(self, tab: int) -> str:
201201
res = (
202-
(tab * "\t")
203-
+ self.type
204-
+ " "
205-
+ self.name if self.name is not None else ""
206-
+ " (on line "
207-
+ str(self.line)
208-
+ ")\n"
202+
(tab * "\t") + self.type + " " + self.name
203+
if self.name is not None
204+
else "" + " (on line " + str(self.line) + ")\n"
209205
)
210206

211207
for attribute in self.attributes:

0 commit comments

Comments
 (0)