Merge pull request #14622 from protocolbuffers/win2019-23.x

Backport CI fixes to 23.x
diff --git a/.github/workflows/staleness_check.yml b/.github/workflows/staleness_check.yml
index 5911b75..9364d04 100644
--- a/.github/workflows/staleness_check.yml
+++ b/.github/workflows/staleness_check.yml
@@ -50,6 +50,7 @@
         # tests along with user changes.  Any stale files will be automatically fixed in a follow-up
         # commit.
         run: |
+          set -ex
           if [[ -z $COMMIT_TRIGGERED_RUN || -z $MAIN_RUN ]]; then
             bazel query 'attr(tags, "staleness_test", //...)' | xargs bazel test $BAZEL_FLAGS
           else
diff --git a/.github/workflows/test_cpp.yml b/.github/workflows/test_cpp.yml
index 38248dd..360b622 100644
--- a/.github/workflows/test_cpp.yml
+++ b/.github/workflows/test_cpp.yml
@@ -326,6 +326,16 @@
         uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
         with:
           ref: ${{ inputs.safe-checkout }}
+      # Workaround for incompatibility between gcloud and windows-2019 runners.
+      - name: Install Python
+        uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
+        if: runner.os == 'Windows'
+        with:
+          python-version: '3.8'
+      - name: Use custom python for gcloud
+        run: echo "CLOUDSDK_PYTHON=${Python3_ROOT_DIR}\\python3" >> $GITHUB_ENV
+        if: runner.os == 'Windows'
+        shell: bash
       - name: Run tests
         uses: protocolbuffers/protobuf-ci/bazel@v1
         with:
@@ -348,6 +358,8 @@
               -Dprotobuf_BUILD_SHARED_LIBS=OFF
               -Dprotobuf_BUILD_EXAMPLES=ON
             vsversion: '2019'
+            # windows-2019 has python3.7 installed, which is incompatible with the latest gcloud
+            python-version: '3.8'
           # TODO(b/285566773) Re-enable this test.
           # This is broken due to a github runner update.
           # See https://github.com/actions/runner-images/issues/7662 for more details
@@ -364,6 +376,8 @@
               -G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
               -Dprotobuf_BUILD_SHARED_LIBS=ON
             vsversion: '2019'
+            # windows-2019 has python3.7 installed, which is incompatible with the latest gcloud
+            python-version: '3.8'
           - name: Windows CMake Install
             os: windows-2019
             install-flags: -G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF -Dprotobuf_BUILD_TESTS=OFF
@@ -372,6 +386,8 @@
               -Dprotobuf_REMOVE_INSTALLED_HEADERS=ON
               -Dprotobuf_BUILD_PROTOBUF_BINARIES=OFF
             vsversion: '2019'
+            # windows-2019 has python3.7 installed, which is incompatible with the latest gcloud
+            python-version: '3.8'
     name: ${{ matrix.name }}
     runs-on: ${{ matrix.os }}
     steps:
@@ -381,6 +397,17 @@
           ref: ${{ inputs.safe-checkout }}
           submodules: recursive
 
+      # Workaround for incompatibility between gcloud and windows-2019 runners.
+      - name: Install Python
+        if: ${{ matrix.python-version }}
+        uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
+        with:
+          python-version: ${{ matrix.python-version }}
+      - name: Use custom python for gcloud
+        if: ${{ matrix.python-version }}
+        run: echo "CLOUDSDK_PYTHON=${Python3_ROOT_DIR}\\python3" >> $GITHUB_ENV
+        shell: bash
+
       - name: Setup ccache
         uses: protocolbuffers/protobuf-ci/ccache@v1
         with:
diff --git a/.github/workflows/test_python.yml b/.github/workflows/test_python.yml
index 36f4e5a..283065d 100644
--- a/.github/workflows/test_python.yml
+++ b/.github/workflows/test_python.yml
@@ -17,7 +17,7 @@
         version: [ "3.7", "3.8", "3.9", "3.10" ]
         include:
           - type: Pure
-            targets: //python/... @upb//python/... //python:python_version
+            targets: //python/... //python:python_version
             flags: --define=use_fast_cpp_protos=false
           - type: C++
             targets: //python/... //python:python_version
@@ -54,7 +54,7 @@
         version: [ "3.10" ]
         include:
           - type: Pure
-            targets: //python/... @upb//python/... //python:python_version
+            targets: //python/... //python:python_version
           - type: C++
             targets: //python/... //python:python_version
             flags: --define=use_fast_cpp_protos=true
diff --git a/WORKSPACE b/WORKSPACE
index 4145483..2e3123c 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -95,18 +95,6 @@
     minimum_python_version = "3.7",
 )
 
-load("@system_python//:pip.bzl", "pip_parse")
-pip_parse(
-    name="pip_deps",
-    requirements = "@upb//python:requirements.txt",
-    requirements_overrides = {
-        "3.11": "@upb//python:requirements_311.txt",
-    },
-)
-
-load("@pip_deps//:requirements.bzl", "install_deps")
-install_deps()
-
 load("@utf8_range//:workspace_deps.bzl", "utf8_range_deps")
 utf8_range_deps()
 
diff --git a/pkg/cc_dist_library.bzl b/pkg/cc_dist_library.bzl
index 42553ca..9fc2c41 100644
--- a/pkg/cc_dist_library.bzl
+++ b/pkg/cc_dist_library.bzl
@@ -170,12 +170,12 @@
 
     return [CcFileList(
         hdrs = _get_transitive_sources(
-            _flatten_target_files(rule_attr.hdrs).to_list(),
+            _flatten_target_files(getattr(rule_attr, "hdrs", [])).to_list(),
             "hdrs",
             rule_attr.deps,
         ),
         textual_hdrs = _get_transitive_sources(
-            _flatten_target_files(rule_attr.textual_hdrs).to_list(),
+            _flatten_target_files(getattr(rule_attr, "textual_hdrs", [])).to_list(),
             "textual_hdrs",
             rule_attr.deps,
         ),
diff --git a/python/google/protobuf/internal/numpy/BUILD.bazel b/python/google/protobuf/internal/numpy/BUILD.bazel
index d88ae8a..28e6249 100644
--- a/python/google/protobuf/internal/numpy/BUILD.bazel
+++ b/python/google/protobuf/internal/numpy/BUILD.bazel
@@ -1,7 +1,8 @@
 # Protobuf python numpy Tests
 # This is removed from other tests to keep numpy (and @pip_deps) as a test-only dependency
 
-load("@pip_deps//:requirements.bzl", "requirement")
+# It's no longer feasible to test this in our CI, and python is out of it's support window.
+#load("@pip_deps//:requirements.bzl", "requirement")
 load("//python:internal.bzl", "internal_py_test")
 
 # TODO: b/278896688 - Remove this target and replace with py_library
@@ -10,14 +11,14 @@
   "numpy_test.py",
 ])
 
-internal_py_test(
-    name = "numpy_test",
-    srcs = ["numpy_test.py"],
-    deps = [
-        requirement("numpy"),
-    ],
-    visibility = [
-      "//python:__pkg__",
-      "@upb//python/pb_unit_tests:__pkg__",
-    ]
-)
+#internal_py_test(
+#    name = "numpy_test",
+#    srcs = ["numpy_test.py"],
+#    deps = [
+#        requirement("numpy"),
+#    ],
+#    visibility = [
+#      "//python:__pkg__",
+#      "@upb//python/pb_unit_tests:__pkg__",
+#    ]
+#)