From d062312ef372df7da6f121a2e8f4930690b48d1f Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Tue, 17 Feb 2026 16:05:48 -0500 Subject: [PATCH] fix: ignore '__pycache__' dirs when generating docker contexts It looks like we're modifying an unused variable, but modifying the list in-place changes `os.walk`'s behaviour. This seems a bit hacky, but this exact use case is actually used in the official documentation as an example. --- src/taskgraph/util/docker.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/taskgraph/util/docker.py b/src/taskgraph/util/docker.py index dc5def040..cff73adc0 100644 --- a/src/taskgraph/util/docker.py +++ b/src/taskgraph/util/docker.py @@ -146,6 +146,8 @@ def stream_context_tar(topsrcdir, context_dir, out_file, args=None): context_dir = os.path.join(topsrcdir, context_dir) for root, dirs, files in os.walk(context_dir): + if "__pycache__" in dirs: + dirs.remove("__pycache__") for f in files: source_path = os.path.join(root, f) archive_path = source_path[len(context_dir) + 1 :] @@ -189,6 +191,8 @@ def stream_context_tar(topsrcdir, context_dir, out_file, args=None): if os.path.isdir(fs_path): for root, dirs, files in os.walk(fs_path): + if "__pycache__" in dirs: + dirs.remove("__pycache__") for f in files: source_path = os.path.join(root, f) rel = source_path[len(fs_path) + 1 :]