Skip __init__.py in __pycache__ dir.
RELNOTES: None.
PiperOrigin-RevId: 211644731
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
index c524a30..a53ae8f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
@@ -36,6 +36,7 @@
public final class PythonUtils {
public static final PathFragment INIT_PY = PathFragment.create("__init__.py");
public static final PathFragment INIT_PYC = PathFragment.create("__init__.pyc");
+ public static final PathFragment PYCACHE = PathFragment.create("__pycache__");
private static final FileType REQUIRES_INIT_PY = FileType.of(".py", ".so", ".pyc");
@@ -64,14 +65,17 @@
for (PathFragment source : manifestFiles) {
// If we have a python or .so file at this level...
if (REQUIRES_INIT_PY.matches(source)) {
- // ...then record that we need an __init__.py in this directory...
+ // ...then record that we need an __init__.py in this and all parents directories...
while (source.segmentCount() > 1) {
source = source.getParentDirectory();
- PathFragment initpy = source.getRelative(INIT_PY);
- PathFragment initpyc = source.getRelative(INIT_PYC);
+ // ...unless it's a Python .pyc cache or we already have __init__ there.
+ if (!source.endsWith(PYCACHE)) {
+ PathFragment initpy = source.getRelative(INIT_PY);
+ PathFragment initpyc = source.getRelative(INIT_PYC);
- if (!manifestFiles.contains(initpy) && !manifestFiles.contains(initpyc)) {
- result.add(initpy);
+ if (!manifestFiles.contains(initpy) && !manifestFiles.contains(initpyc)) {
+ result.add(initpy);
+ }
}
}
}