Skip to content

Commit d643a9d

Browse files
jschefflephraimbuddy
authored andcommitted
[v3-1-test] Backport: Remove global from prek CI scripts #58872 (#58874)
1 parent 18207b5 commit d643a9d

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

scripts/ci/prek/check_providers_subpackages_all_have_init.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@
5555

5656
ALLOWED_SUB_FOLDERS_OF_TESTS = ["unit", "system", "integration"]
5757

58-
should_fail = False
59-
fatal_error = False
58+
59+
class _ErrorSignals:
60+
should_fail: bool = False
61+
fatal_error: bool = False
62+
63+
6064
missing_init_dirs: list[Path] = []
6165
missing_path_extension_dirs: list[Path] = []
6266

@@ -77,11 +81,9 @@ def _what_kind_of_test_init_py_needed(base_path: Path, folder: Path) -> tuple[bo
7781
if folder.name not in ALLOWED_SUB_FOLDERS_OF_TESTS:
7882
console.print(f"[red]Unexpected folder {folder} in {base_path}[/]")
7983
console.print(f"[yellow]Only {ALLOWED_SUB_FOLDERS_OF_TESTS} should be sub-folders of tests.[/]")
80-
global should_fail
81-
global fatal_error
82-
should_fail = True
83-
fatal_error = True
84-
return False, False
84+
_ErrorSignals.should_fail = True
85+
_ErrorSignals.fatal_error = True
86+
return True, True
8587
if depth == 2:
8688
# For known sub-packages that can occur in several packages we need to add __path__ extension
8789
return True, folder.name in KNOWN_SECOND_LEVEL_PATHS
@@ -162,20 +164,20 @@ def check_dir_init_src_folders(folders: list[Path]) -> None:
162164
init_file = missing_init_dir / "__init__.py"
163165
init_file.write_text("".join(prefixed_licensed_txt))
164166
console.print(f"[yellow]Added missing __init__.py file:[/] {init_file}")
165-
should_fail = True
167+
_ErrorSignals.should_fail = True
166168

167169
for missing_extension_dir in missing_path_extension_dirs:
168170
init_file = missing_extension_dir / "__init__.py"
169171
init_file.write_text(init_file.read_text() + PATH_EXTENSION_STRING + "\n")
170172
console.print(f"[yellow]Added missing path extension to __init__.py file[/] {init_file}")
171-
should_fail = True
173+
_ErrorSignals.should_fail = True
172174

173-
if should_fail:
175+
if _ErrorSignals.should_fail:
174176
console.print(
175177
"\n[yellow]The missing __init__.py files have been created. "
176178
"Please add these new files to a commit."
177179
)
178-
if fatal_error:
180+
if _ErrorSignals.fatal_error:
179181
console.print("[red]Also please remove the extra test folders listed above!")
180182
sys.exit(1)
181183
console.print("[green]All __init__.py files are present and have necessary extensions.[/]")

scripts/in_container/run_check_imports_in_providers.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@
2626
sys.path.insert(0, str(Path(__file__).parent.resolve()))
2727
from in_container_utils import console, get_provider_base_dir_from_path, get_provider_id_from_path
2828

29-
errors_found = False
3029

31-
32-
def check_imports():
33-
global errors_found
30+
def check_imports() -> bool:
31+
errors_found = False
3432
cmd = [
3533
"ruff",
3634
"analyze",
@@ -80,11 +78,10 @@ def check_imports():
8078
f"\n"
8179
)
8280
errors_found = True
81+
return errors_found
8382

8483

85-
check_imports()
86-
87-
if errors_found:
84+
if check_imports():
8885
console.print("\n[red]Errors found in imports![/]\n")
8986
sys.exit(1)
9087
else:

0 commit comments

Comments
 (0)