MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / LintManager

Class LintManager

misc/python/materialize/cli/lint.py:47–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45
46
47class LintManager:
48 def __init__(self, print_duration: bool, verbose_output: bool, offline: bool):
49 self.print_duration = print_duration
50 self.verbose_output = verbose_output
51 self.offline = offline
52
53 def run(self) -> int:
54 failed_checks = self.run_and_validate_if_no_previous_failures(
55 CHECK_BEFORE_PATH, previous_failures=[]
56 )
57 failed_checks = self.run_and_validate_if_no_previous_failures(
58 MAIN_CHECKS_PATH, previous_failures=failed_checks
59 )
60 failed_checks = self.run_and_validate_if_no_previous_failures(
61 CHECK_AFTER_PATH, previous_failures=failed_checks
62 )
63
64 success = len(failed_checks) == 0
65
66 print(
67 _prefix("+++") + f"{OK} All checks successful"
68 if success
69 else f"{FAIL} Checks failed: {failed_checks}"
70 )
71
72 return 0 if success else 1
73
74 def is_ignore_file(self, path: Path) -> bool:
75 return os.path.isdir(path)
76
77 def run_and_validate_if_no_previous_failures(
78 self, checks_path: Path, previous_failures: list[str]
79 ) -> list[str]:
80 if len(previous_failures) > 0:
81 print(
82 f"{_prefix()}Skipping checks in '{checks_path}' due to previous failures"
83 )
84 return previous_failures
85 else:
86 return self.run_and_validate(checks_path)
87
88 def run_and_validate(self, checks_path: Path) -> list[str]:
89 """
90 Runs checks in the given directory and validates their outcome.
91 :return: names of failed checks
92 """
93
94 lint_files = [
95 lint_file
96 for lint_file in os.listdir(checks_path)
97 if lint_file.endswith(".sh")
98 and not self.is_ignore_file(checks_path / lint_file)
99 ]
100 lint_files.sort()
101
102 check = "check" if len(lint_files) == 1 else "checks"
103 rel_path = checks_path.relative_to(MZ_ROOT)
104

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected