From 855e820fd418bbfbd6d0ffd95ac777baddaa6765 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 2 Jul 2025 23:58:00 +0000 Subject: [PATCH 1/4] Fix: Check for include directory before watching in local_runtime_repo The local_runtime_repo rule was failing on macOS when the Python interpreter's metadata pointed to an include directory that did not exist. This change modifies the rule to check if the include directory exists and is a directory before attempting to watch it with `watch_tree`. --- python/private/local_runtime_repo.bzl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/python/private/local_runtime_repo.bzl b/python/private/local_runtime_repo.bzl index ec0643e497..47ec705fc9 100644 --- a/python/private/local_runtime_repo.bzl +++ b/python/private/local_runtime_repo.bzl @@ -99,7 +99,14 @@ def _local_runtime_repo_impl(rctx): interpreter_path = info["base_executable"] # NOTE: Keep in sync with recursive glob in define_local_runtime_toolchain_impl - repo_utils.watch_tree(rctx, rctx.path(info["include"])) + include_path = rctx.path(info["include"]) + if include_path.exists and include_path.is_dir: + repo_utils.watch_tree(rctx, include_path) + else: + # If the path doesn't exist or is not a directory, do not watch it. + # This handles the case where the include path specified in Python metadata + # is invalid or points to a file. + pass # The cc_library.includes values have to be non-absolute paths, otherwise # the toolchain will give an error. Work around this error by making them From d31b245fdbaeec1990765416ef90f486597fc6d6 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Wed, 2 Jul 2025 17:02:17 -0700 Subject: [PATCH 2/4] fixup comment --- python/private/local_runtime_repo.bzl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/private/local_runtime_repo.bzl b/python/private/local_runtime_repo.bzl index 47ec705fc9..3b4b4c020d 100644 --- a/python/private/local_runtime_repo.bzl +++ b/python/private/local_runtime_repo.bzl @@ -100,12 +100,13 @@ def _local_runtime_repo_impl(rctx): # NOTE: Keep in sync with recursive glob in define_local_runtime_toolchain_impl include_path = rctx.path(info["include"]) + + # The reported include path may not exist, and watching a non-existant + # path is an error. Silently skip, since includes are only necessary + # if C extensions are built. if include_path.exists and include_path.is_dir: repo_utils.watch_tree(rctx, include_path) else: - # If the path doesn't exist or is not a directory, do not watch it. - # This handles the case where the include path specified in Python metadata - # is invalid or points to a file. pass # The cc_library.includes values have to be non-absolute paths, otherwise From e1e0d9709318d0585ebdbae8d3c587f743916e47 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 3 Jul 2025 00:17:08 +0000 Subject: [PATCH 3/4] Docs: Add changelog entry for local_runtime_repo include dir fix References issue #3043. --- CHANGELOG.md | 3 +++ python/private/local_runtime_repo.bzl | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da59ecf8b5..b5ed7b4148 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,9 @@ END_UNRELEASED_TEMPLATE * (pypi) Wheels with BUILD.bazel (or other special Bazel files) no longer result in missing files at runtime ([#2782](https://github.com/bazel-contrib/rules_python/issues/2782)). +* (toolchains) `local_runtime_repo` now checks if the include directory exists + before attempting to watch it, fixing issues on macOS with system Python + ({gh-issue}`3043`). {#v0-0-0-added} ### Added diff --git a/python/private/local_runtime_repo.bzl b/python/private/local_runtime_repo.bzl index 3b4b4c020d..47ec705fc9 100644 --- a/python/private/local_runtime_repo.bzl +++ b/python/private/local_runtime_repo.bzl @@ -100,13 +100,12 @@ def _local_runtime_repo_impl(rctx): # NOTE: Keep in sync with recursive glob in define_local_runtime_toolchain_impl include_path = rctx.path(info["include"]) - - # The reported include path may not exist, and watching a non-existant - # path is an error. Silently skip, since includes are only necessary - # if C extensions are built. if include_path.exists and include_path.is_dir: repo_utils.watch_tree(rctx, include_path) else: + # If the path doesn't exist or is not a directory, do not watch it. + # This handles the case where the include path specified in Python metadata + # is invalid or points to a file. pass # The cc_library.includes values have to be non-absolute paths, otherwise From e40f1c9d1806c8d9d7d30cd613e1152075e9239b Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Wed, 2 Jul 2025 17:20:10 -0700 Subject: [PATCH 4/4] fixup comment. again. --- python/private/local_runtime_repo.bzl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/private/local_runtime_repo.bzl b/python/private/local_runtime_repo.bzl index 47ec705fc9..3b4b4c020d 100644 --- a/python/private/local_runtime_repo.bzl +++ b/python/private/local_runtime_repo.bzl @@ -100,12 +100,13 @@ def _local_runtime_repo_impl(rctx): # NOTE: Keep in sync with recursive glob in define_local_runtime_toolchain_impl include_path = rctx.path(info["include"]) + + # The reported include path may not exist, and watching a non-existant + # path is an error. Silently skip, since includes are only necessary + # if C extensions are built. if include_path.exists and include_path.is_dir: repo_utils.watch_tree(rctx, include_path) else: - # If the path doesn't exist or is not a directory, do not watch it. - # This handles the case where the include path specified in Python metadata - # is invalid or points to a file. pass # The cc_library.includes values have to be non-absolute paths, otherwise