Skip to content

Commit 019fb4b

Browse files
honglookerlaramielrickeylev
authored
backport: PR#3178 to 1.5 (#3217)
fix(local_runtime): Search for libs in sys._base_executable when available. (#3178) Search directory for libraries should look in the same directory as sys._base_executable. Since sys._base_executable may be unset, fallback to sys.executable Found this when trying to build using a venv for [tensorstore](https://github.com/google/tensorstore) on Windows: * Github CI uses nuget to download Python. * Build sets up a Python venv. The venv does not include all the lib directories required to link an extension. Fixes #3172 --------- Co-authored-by: Richard Levasseur <[email protected]> --------- Co-authored-by: Laramie Leavitt <[email protected]> Co-authored-by: Richard Levasseur <[email protected]>
1 parent 34051e0 commit 019fb4b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ BEGIN_UNRELEASED_TEMPLATE
4747
END_UNRELEASED_TEMPLATE
4848
-->
4949

50+
{#1-5-4}
51+
## [1.5.4] - 2025-08-26
52+
53+
[1.5.4]: https://github.com/bazel-contrib/rules_python/releases/tag/1.5.4
54+
55+
{#v1-5-4-fixed}
56+
### Fixed
57+
58+
* (local toolchains) Search for libs in sys._base_executable when available
59+
([#3178](https://github.com/bazel-contrib/rules_python/issues/3178)).
60+
5061
{#1-5-3}
5162
## [1.5.3] - 2025-08-11
5263

python/private/get_local_runtime_info.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,27 @@
1616
import sys
1717
import sysconfig
1818

19+
def _get_base_executable():
20+
"""Returns the base executable path."""
21+
try:
22+
if sys._base_executable: # pylint: disable=protected-access
23+
return sys._base_executable # pylint: disable=protected-access
24+
except AttributeError:
25+
# Bug reports indicate sys._base_executable doesn't exist in some cases,
26+
# but it's not clear why.
27+
# See https://github.com/bazel-contrib/rules_python/issues/3172
28+
pass
29+
# The normal sys.executable is the next-best guess if sys._base_executable
30+
# is missing.
31+
return sys.executable
32+
1933
data = {
2034
"major": sys.version_info.major,
2135
"minor": sys.version_info.minor,
2236
"micro": sys.version_info.micro,
2337
"include": sysconfig.get_path("include"),
2438
"implementation_name": sys.implementation.name,
25-
"base_executable": sys._base_executable,
39+
"base_executable": _get_base_executable(),
2640
}
2741

2842
config_vars = [

0 commit comments

Comments
 (0)