Skip to content

Commit 44a1fe7

Browse files
Taragolisjedcunningham
authored andcommitted
Avoid to use functools.lru_cache in class methods in dev (#38627)
(cherry picked from commit a4ee430)
1 parent fe7dd31 commit 44a1fe7

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

dev/breeze/src/airflow_breeze/utils/selective_checks.py

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,38 @@ def find_all_providers_affected(
357357
return sorted(all_providers)
358358

359359

360+
def _match_files_with_regexps(files: tuple[str, ...], matched_files, matching_regexps):
361+
for file in files:
362+
if any(re.match(regexp, file) for regexp in matching_regexps):
363+
matched_files.append(file)
364+
365+
366+
def _exclude_files_with_regexps(files: tuple[str, ...], matched_files, exclude_regexps):
367+
for file in files:
368+
if any(re.match(regexp, file) for regexp in exclude_regexps):
369+
if file in matched_files:
370+
matched_files.remove(file)
371+
372+
373+
@lru_cache(maxsize=None)
374+
def _matching_files(
375+
files: tuple[str, ...], match_group: FileGroupForCi, match_dict: HashableDict, exclude_dict: HashableDict
376+
) -> list[str]:
377+
matched_files: list[str] = []
378+
match_regexps = match_dict[match_group]
379+
excluded_regexps = exclude_dict.get(match_group)
380+
_match_files_with_regexps(files, matched_files, match_regexps)
381+
if excluded_regexps:
382+
_exclude_files_with_regexps(files, matched_files, excluded_regexps)
383+
count = len(matched_files)
384+
if count > 0:
385+
get_console().print(f"[warning]{match_group} matched {count} files.[/]")
386+
get_console().print(matched_files)
387+
else:
388+
get_console().print(f"[warning]{match_group} did not match any file.[/]")
389+
return matched_files
390+
391+
360392
class SelectiveChecks:
361393
__HASHABLE_FIELDS = {"_files", "_default_branch", "_commit_ref", "_pr_labels", "_github_event"}
362394

@@ -588,34 +620,10 @@ def kubernetes_combos_list_as_string(self) -> str:
588620
)
589621
return " ".join(short_combo_titles)
590622

591-
def _match_files_with_regexps(self, matched_files, matching_regexps):
592-
for file in self._files:
593-
if any(re.match(regexp, file) for regexp in matching_regexps):
594-
matched_files.append(file)
595-
596-
def _exclude_files_with_regexps(self, matched_files, exclude_regexps):
597-
for file in self._files:
598-
if any(re.match(regexp, file) for regexp in exclude_regexps):
599-
if file in matched_files:
600-
matched_files.remove(file)
601-
602-
@lru_cache(maxsize=None)
603623
def _matching_files(
604-
self, match_group: T, match_dict: dict[T, list[str]], exclude_dict: dict[T, list[str]]
624+
self, match_group: FileGroupForCi, match_dict: HashableDict, exclude_dict: HashableDict
605625
) -> list[str]:
606-
matched_files: list[str] = []
607-
match_regexps = match_dict[match_group]
608-
excluded_regexps = exclude_dict.get(match_group)
609-
self._match_files_with_regexps(matched_files, match_regexps)
610-
if excluded_regexps:
611-
self._exclude_files_with_regexps(matched_files, excluded_regexps)
612-
count = len(matched_files)
613-
if count > 0:
614-
get_console().print(f"[warning]{match_group} matched {count} files.[/]")
615-
get_console().print(matched_files)
616-
else:
617-
get_console().print(f"[warning]{match_group} did not match any file.[/]")
618-
return matched_files
626+
return _matching_files(self._files, match_group, match_dict, exclude_dict)
619627

620628
def _should_be_run(self, source_area: FileGroupForCi) -> bool:
621629
if self.full_tests_needed:

0 commit comments

Comments
 (0)