[engine] Ignore pycache dirs in emptiness check

Ignore the '__pycache__' dirs when evaluating if a module directory is
empty. See also http://crrev.com/c/5443305.

Change-Id: Ic5649eabd100e881f6c05aa8e089c3b89fb99033
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/recipes-py/+/5468261
Reviewed-by: Oliver Newman <olivernewman@google.com>
Commit-Queue: Chan Li <chanli@chromium.org>
Reviewed-by: Chan Li <chanli@chromium.org>
Auto-Submit: Rob Mohr <mohrr@google.com>
diff --git a/recipe_engine/internal/recipe_deps.py b/recipe_engine/internal/recipe_deps.py
index 4604024..72c8040 100644
--- a/recipe_engine/internal/recipe_deps.py
+++ b/recipe_engine/internal/recipe_deps.py
@@ -448,11 +448,16 @@
           modules[entry_name] = mod
           for recipe in mod.recipes.values():
             recipes[recipe.name] = recipe
-        elif any(os.scandir(possible_mod_path)):
+        else:
           # Only emit this log if the module directory is non-empty. If the
           # module directory is empty then it goes without saying that it will
-          # be ignored.
-          LOG.warn('ignoring %r: missing __init__.py', possible_mod_path)
+          # be ignored. Ignore '__pycache__' subdirectories.
+          for entry in os.scandir(possible_mod_path):
+            if entry.name == '__pycache__':
+              continue
+
+            LOG.warn('ignoring %r: missing __init__.py', possible_mod_path)
+            break
 
     for recipe_name in _scan_recipe_directory(ret.recipes_dir):
       recipes[recipe_name] = Recipe(
diff --git a/recipe_modules/time/examples/full.expected/exponential_retry_from_import_on_helper_fn_no_api.json b/recipe_modules/time/examples/full.expected/exponential_retry_from_import_on_helper_fn_no_api.json
index 07ce86a..e41cd89 100644
--- a/recipe_modules/time/examples/full.expected/exponential_retry_from_import_on_helper_fn_no_api.json
+++ b/recipe_modules/time/examples/full.expected/exponential_retry_from_import_on_helper_fn_no_api.json
@@ -21,7 +21,7 @@
       "  File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/engine.py\", line 597, in run_steps",
       "    raw_result = recipe_obj.run_steps(api, engine)",
       "                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
-      "  File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/recipe_deps.py\", line 1012, in run_steps",
+      "  File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/recipe_deps.py\", line 1017, in run_steps",
       "    recipe_result = invoke_with_properties(",
       "                    ^^^^^^^^^^^^^^^^^^^^^^^",
       "  File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/property_invoker.py\", line 88, in invoke_with_properties",
diff --git a/recipes/engine_tests/expect_exception.expected/basic.json b/recipes/engine_tests/expect_exception.expected/basic.json
index 5c81da5..8f1fe52 100644
--- a/recipes/engine_tests/expect_exception.expected/basic.json
+++ b/recipes/engine_tests/expect_exception.expected/basic.json
@@ -10,7 +10,7 @@
       "  File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/engine.py\", line 597, in run_steps",
       "    raw_result = recipe_obj.run_steps(api, engine)",
       "                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
-      "  File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/recipe_deps.py\", line 1012, in run_steps",
+      "  File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/recipe_deps.py\", line 1017, in run_steps",
       "    recipe_result = invoke_with_properties(",
       "                    ^^^^^^^^^^^^^^^^^^^^^^^",
       "  File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/property_invoker.py\", line 88, in invoke_with_properties",
diff --git a/recipes/engine_tests/expect_exceptions.expected/basic.json b/recipes/engine_tests/expect_exceptions.expected/basic.json
index 3f4f13a..613aa62 100644
--- a/recipes/engine_tests/expect_exceptions.expected/basic.json
+++ b/recipes/engine_tests/expect_exceptions.expected/basic.json
@@ -10,7 +10,7 @@
       "  |   File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/engine.py\", line 597, in run_steps",
       "  |     raw_result = recipe_obj.run_steps(api, engine)",
       "  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
-      "  |   File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/recipe_deps.py\", line 1012, in run_steps",
+      "  |   File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/recipe_deps.py\", line 1017, in run_steps",
       "  |     recipe_result = invoke_with_properties(",
       "  |                     ^^^^^^^^^^^^^^^^^^^^^^^",
       "  |   File \"RECIPE_REPO[recipe_engine]/recipe_engine/internal/property_invoker.py\", line 88, in invoke_with_properties",