From adbaca1fd04d73aeb74c1bf4e8d54239107d5209 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Mon, 22 Jun 2026 15:37:24 +0000 Subject: [PATCH] fix(bootstrap): use retry loop for win32 version lookup in site init template Align the Windows path resolution in the site initialization template with the bootstrap template to prevent flaky platform lookup errors on Windows 2022. This is achieved by wrapping the win32 version retrieval in a retrying loop. Fixes https://github.com/bazel-contrib/rules_python/issues/3721 --- news/win32_version_lookup.fixed.md | 3 +++ python/private/site_init_template.py | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 news/win32_version_lookup.fixed.md 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