This is an automated email from the ASF dual-hosted git repository. potiuk pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push: new a4ee43024a Avoid to use `functools.lru_cache` in class methods in dev (#38627) a4ee43024a is described below commit a4ee43024a105786af33f74d1354403050759193 Author: Andrey Anshin <andrey.ans...@taragol.is> AuthorDate: Sat Mar 30 03:53:36 2024 +0400 Avoid to use `functools.lru_cache` in class methods in dev (#38627) --- .../src/airflow_breeze/utils/selective_checks.py | 60 ++++++++++++---------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/dev/breeze/src/airflow_breeze/utils/selective_checks.py b/dev/breeze/src/airflow_breeze/utils/selective_checks.py index d38cf61e4d..1118901748 100644 --- a/dev/breeze/src/airflow_breeze/utils/selective_checks.py +++ b/dev/breeze/src/airflow_breeze/utils/selective_checks.py @@ -357,6 +357,38 @@ def find_all_providers_affected( return sorted(all_providers) +def _match_files_with_regexps(files: tuple[str, ...], matched_files, matching_regexps): + for file in files: + if any(re.match(regexp, file) for regexp in matching_regexps): + matched_files.append(file) + + +def _exclude_files_with_regexps(files: tuple[str, ...], matched_files, exclude_regexps): + for file in files: + if any(re.match(regexp, file) for regexp in exclude_regexps): + if file in matched_files: + matched_files.remove(file) + + +@lru_cache(maxsize=None) +def _matching_files( + files: tuple[str, ...], match_group: FileGroupForCi, match_dict: HashableDict, exclude_dict: HashableDict +) -> list[str]: + matched_files: list[str] = [] + match_regexps = match_dict[match_group] + excluded_regexps = exclude_dict.get(match_group) + _match_files_with_regexps(files, matched_files, match_regexps) + if excluded_regexps: + _exclude_files_with_regexps(files, matched_files, excluded_regexps) + count = len(matched_files) + if count > 0: + get_console().print(f"[warning]{match_group} matched {count} files.[/]") + get_console().print(matched_files) + else: + get_console().print(f"[warning]{match_group} did not match any file.[/]") + return matched_files + + class SelectiveChecks: __HASHABLE_FIELDS = {"_files", "_default_branch", "_commit_ref", "_pr_labels", "_github_event"} @@ -588,34 +620,10 @@ class SelectiveChecks: ) return " ".join(short_combo_titles) - def _match_files_with_regexps(self, matched_files, matching_regexps): - for file in self._files: - if any(re.match(regexp, file) for regexp in matching_regexps): - matched_files.append(file) - - def _exclude_files_with_regexps(self, matched_files, exclude_regexps): - for file in self._files: - if any(re.match(regexp, file) for regexp in exclude_regexps): - if file in matched_files: - matched_files.remove(file) - - @lru_cache(maxsize=None) def _matching_files( - self, match_group: T, match_dict: dict[T, list[str]], exclude_dict: dict[T, list[str]] + self, match_group: FileGroupForCi, match_dict: HashableDict, exclude_dict: HashableDict ) -> list[str]: - matched_files: list[str] = [] - match_regexps = match_dict[match_group] - excluded_regexps = exclude_dict.get(match_group) - self._match_files_with_regexps(matched_files, match_regexps) - if excluded_regexps: - self._exclude_files_with_regexps(matched_files, excluded_regexps) - count = len(matched_files) - if count > 0: - get_console().print(f"[warning]{match_group} matched {count} files.[/]") - get_console().print(matched_files) - else: - get_console().print(f"[warning]{match_group} did not match any file.[/]") - return matched_files + return _matching_files(self._files, match_group, match_dict, exclude_dict) def _should_be_run(self, source_area: FileGroupForCi) -> bool: if self.full_tests_needed: