Skip to content

Commit b3c635c

Browse files
github-actions[bot]potiuk
authored andcommitted
[v3-2-test] Speed up cleanup_python_generated_files by skipping irrelevant dirs (#64927) (#64930)
Replace two rglob calls with a single os.walk that prunes node_modules and hidden directories (e.g. .git, .venv) in-place, avoiding unnecessary traversal of large directory trees that never contain relevant .pyc files. (cherry picked from commit 27258d5) Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
1 parent 1a04cd3 commit b3c635c

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -418,22 +418,26 @@ def cleanup_python_generated_files():
418418
if get_verbose():
419419
console_print("[info]Cleaning .pyc and __pycache__")
420420
permission_errors = []
421-
for path in AIRFLOW_ROOT_PATH.rglob("*.pyc"):
422-
try:
423-
path.unlink()
424-
except FileNotFoundError:
425-
# File has been removed in the meantime.
426-
pass
427-
except PermissionError:
428-
permission_errors.append(path)
429-
for path in AIRFLOW_ROOT_PATH.rglob("__pycache__"):
430-
try:
431-
shutil.rmtree(path)
432-
except FileNotFoundError:
433-
# File has been removed in the meantime.
434-
pass
435-
except PermissionError:
436-
permission_errors.append(path)
421+
for dirpath, dirnames, filenames in os.walk(AIRFLOW_ROOT_PATH):
422+
# Skip node_modules and hidden directories (.*) — modify in place to prune os.walk
423+
dirnames[:] = [d for d in dirnames if d != "node_modules" and not d.startswith(".")]
424+
for filename in filenames:
425+
if filename.endswith(".pyc"):
426+
path = Path(dirpath) / filename
427+
try:
428+
path.unlink()
429+
except FileNotFoundError:
430+
pass
431+
except PermissionError:
432+
permission_errors.append(path)
433+
if Path(dirpath).name == "__pycache__":
434+
try:
435+
shutil.rmtree(dirpath)
436+
except FileNotFoundError:
437+
pass
438+
except PermissionError:
439+
permission_errors.append(Path(dirpath))
440+
dirnames.clear()
437441
if permission_errors:
438442
if platform.uname().system.lower() == "linux":
439443
console_print("[warning]There were files that you could not clean-up:\n")

0 commit comments

Comments
 (0)