diff --git a/news/win32_version_lookup.fixed.md b/news/win32_version_lookup.fixed.md new file mode 100644 index 0000000000..6f01c9e73c --- /dev/null +++ b/news/win32_version_lookup.fixed.md @@ -0,0 +1,3 @@ +Fixed a flaky error on Windows 2022 when looking up the win32 version during +site initialization by retrying the lookup +([#3721](https://github.com/bazel-contrib/rules_python/issues/3721)). diff --git a/python/private/site_init_template.py b/python/private/site_init_template.py index af80b22a24..12be98eb57 100644 --- a/python/private/site_init_template.py +++ b/python/private/site_init_template.py @@ -98,7 +98,15 @@ def _get_windows_path_with_unc_prefix(path): # Related doc: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd#enable-long-paths-in-windows-10-version-1607-and-later import platform - if platform.win32_ver()[1] >= "10.0.14393": + win32_version = None + # Windows 2022 with Python 3.12.8 gives flakey errors, so try a couple times. + for _ in range(3): + try: + win32_version = platform.win32_ver()[1] + break + except (ValueError, KeyError): + pass + if win32_version and win32_version >= "10.0.14393": return path # import sysconfig only now to maintain python 2.6 compatibility