python: Don't require `python` binary for Bazel tests.

This fixes the failures on MacOS after the recent upgrade to CI.

When `//src/test/py/baze:runfiles_test` sets
`--incompatible_use_python_toolchains=false`, it eventuallys tries to search
`PATH` for `python`. This is because it falls back to the `--python_path`
flag, which has a computed default of "python". Since new Mac versions no
longer provide Python 2, this doesn't work.

To fix, enable Python toolchains. Comments indicate they were only disabled
because Python 3 wasn't available on the Mac CI machines at the time.

For pywrapper_test: this was failing because it copies system utilities (e.g
`/usr/bin/which`) to another location and tries to run them. For newer MacOS
versions, this results in a failure due AMFI (a security mechanism, see
https://theevilbit.github.io/posts/amfi_launch_constraints/)

To fix, instead of copying the binary, write a wrapper that re-execs the
original binary.

Work towards #16526, #8169

PiperOrigin-RevId: 507526814
Change-Id: Ifaacc30cb155af30af606254eb7ffcd9304478f6
diff --git a/tools/python/pywrapper_test.py b/tools/python/pywrapper_test.py
index 14fd0d7..f5eacd5 100644
--- a/tools/python/pywrapper_test.py
+++ b/tools/python/pywrapper_test.py
@@ -86,7 +86,12 @@
     path = which(cmd)
     self.assertIsNotNone(
         path, msg="Could not locate '%s' command on PATH" % cmd)
-    self.CopyFile(path, os.path.join("dir", cmd), executable=True)
+    # On recent MacOs versions, copying the coreutils tools elsewhere doesn't
+    # work -- they simply fail with "Killed: 9". To workaround that, just
+    # re-exec the actual binary.
+    self.ScratchFile("dir/" + cmd,
+                     ["#!/bin/sh", 'exec {} "$@"'.format(cmd)],
+                     executable=True)
 
   def locate_runfile(self, runfile_path):
     resolved_path = self.Rlocation(runfile_path)