diff --git a/python/private/py_executable_bazel.bzl b/python/private/py_executable_bazel.bzl index 8db867e64e..3778c192b4 100644 --- a/python/private/py_executable_bazel.bzl +++ b/python/private/py_executable_bazel.bzl @@ -360,7 +360,8 @@ def relative_path(from_, to): to_parts = to.split("/") # Strip common leading parts from both paths - for _ in range(len(to)): + n = min(len(from_parts), len(to_parts)) + for _ in range(n): if from_parts[0] == to_parts[0]: from_parts.pop(0) to_parts.pop(0)