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 27258d56788 Speed up cleanup_python_generated_files by skipping
irrelevant dirs (#64927)
27258d56788 is described below
commit 27258d567887a93f43af25a9d79d773198751bd9
Author: Jarek Potiuk <[email protected]>
AuthorDate: Thu Apr 9 00:37:14 2026 +0300
Speed up cleanup_python_generated_files by skipping irrelevant dirs (#64927)
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.
---
dev/breeze/src/airflow_breeze/utils/path_utils.py | 36 +++++++++++++----------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/dev/breeze/src/airflow_breeze/utils/path_utils.py
b/dev/breeze/src/airflow_breeze/utils/path_utils.py
index 03877d64761..7f2625a0bcc 100644
--- a/dev/breeze/src/airflow_breeze/utils/path_utils.py
+++ b/dev/breeze/src/airflow_breeze/utils/path_utils.py
@@ -418,22 +418,26 @@ def cleanup_python_generated_files():
if get_verbose():
console_print("[info]Cleaning .pyc and __pycache__")
permission_errors = []
- for path in AIRFLOW_ROOT_PATH.rglob("*.pyc"):
- try:
- path.unlink()
- except FileNotFoundError:
- # File has been removed in the meantime.
- pass
- except PermissionError:
- permission_errors.append(path)
- for path in AIRFLOW_ROOT_PATH.rglob("__pycache__"):
- try:
- shutil.rmtree(path)
- except FileNotFoundError:
- # File has been removed in the meantime.
- pass
- except PermissionError:
- permission_errors.append(path)
+ for dirpath, dirnames, filenames in os.walk(AIRFLOW_ROOT_PATH):
+ # Skip node_modules and hidden directories (.*) — modify in place to
prune os.walk
+ dirnames[:] = [d for d in dirnames if d != "node_modules" and not
d.startswith(".")]
+ for filename in filenames:
+ if filename.endswith(".pyc"):
+ path = Path(dirpath) / filename
+ try:
+ path.unlink()
+ except FileNotFoundError:
+ pass
+ except PermissionError:
+ permission_errors.append(path)
+ if Path(dirpath).name == "__pycache__":
+ try:
+ shutil.rmtree(dirpath)
+ except FileNotFoundError:
+ pass
+ except PermissionError:
+ permission_errors.append(Path(dirpath))
+ dirnames.clear()
if permission_errors:
if platform.uname().system.lower() == "linux":
console_print("[warning]There were files that you could not
clean-up:\n")