Allow METADATA files in pip_repository generated targets (#637)

diff --git a/examples/pip_repository_annotations/WORKSPACE b/examples/pip_repository_annotations/WORKSPACE
index 8234e57..8c01461 100644
--- a/examples/pip_repository_annotations/WORKSPACE
+++ b/examples/pip_repository_annotations/WORKSPACE
@@ -34,6 +34,7 @@
         copy_executables = {"@pip_repository_annotations_example//:data/copy_executable.py": "copied_content/executable.py"},
         copy_files = {"@pip_repository_annotations_example//:data/copy_file.txt": "copied_content/file.txt"},
         data = [":generated_file"],
+        data_exclude_glob = ["*.dist-info/WHEEL"],
     ),
 }
 
diff --git a/examples/pip_repository_annotations/pip_repository_annotations_test.py b/examples/pip_repository_annotations/pip_repository_annotations_test.py
index 0e2e8b3..79c354d 100644
--- a/examples/pip_repository_annotations/pip_repository_annotations_test.py
+++ b/examples/pip_repository_annotations/pip_repository_annotations_test.py
@@ -64,6 +64,34 @@
         stdout = proc.stdout.decode("utf-8").strip()
         self.assertEqual(stdout, "Hello world from copied executable")
 
+    def test_data_exclude_glob(self):
+        current_wheel_version = "0.37.1"
+
+        r = runfiles.Create()
+        dist_info_dir = (
+            "pip_repository_annotations_example/external/{}/wheel-{}.dist-info".format(
+                self.wheel_pkg_dir(),
+                current_wheel_version,
+            )
+        )
+
+        # Note: `METADATA` is important as it's consumed by https://docs.python.org/3/library/importlib.metadata.html
+        # `METADATA` is expected to be there to show dist-info files are included in the runfiles.
+        metadata_path = r.Rlocation("{}/METADATA".format(dist_info_dir))
+
+        # However, `WHEEL` was explicitly excluded, so it should be missing
+        wheel_path = r.Rlocation("{}/WHEEL".format(dist_info_dir))
+
+        # Because windows does not have `--enable_runfiles` on by default, the
+        # `runfiles.Rlocation` results will be different on this platform vs
+        # unix platforms. See `@rules_python//python/runfiles` for more details.
+        if platform.system() == "Windows":
+            self.assertIsNotNone(metadata_path)
+            self.assertIsNone(wheel_path)
+        else:
+            self.assertTrue(Path(metadata_path).exists())
+            self.assertFalse(Path(wheel_path).exists())
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/python/pip_install/extract_wheels/lib/bazel.py b/python/pip_install/extract_wheels/lib/bazel.py
index 0ec55c4..3c8697b 100644
--- a/python/pip_install/extract_wheels/lib/bazel.py
+++ b/python/pip_install/extract_wheels/lib/bazel.py
@@ -139,12 +139,10 @@
     there may be no Python sources whatsoever (e.g. packages written in Cython: like `pymssql`).
     """
 
-    # `dist-info` contains non-determinisitc files which can change any time
-    # the repository rules run. Below is a list of known patterns to these
-    # files. However, not all files should be ignored as certain packages
-    # require things like `top_level.txt`.
     dist_info_ignores = [
-        "**/*.dist-info/METADATA",
+        # RECORD is known to contain sha256 checksums of files which might include the checksums
+        # of generated files produced when wheels are installed. The file is ignored to avoid
+        # Bazel caching issues.
         "**/*.dist-info/RECORD",
     ]