Skip to content

Commit 9e685d7

Browse files
laramielrickeylev
authored andcommitted
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]>
1 parent 18d0d29 commit 9e685d7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

python/private/get_local_runtime_info.py

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

19+
_IS_WINDOWS = sys.platform == "win32"
20+
_IS_DARWIN = sys.platform == "darwin"
21+
22+
23+
def _get_base_executable():
24+
"""Returns the base executable path."""
25+
try:
26+
if sys._base_executable: # pylint: disable=protected-access
27+
return sys._base_executable # pylint: disable=protected-access
28+
except AttributeError:
29+
# Bug reports indicate sys._base_executable doesn't exist in some cases,
30+
# but it's not clear why.
31+
# See https://github.com/bazel-contrib/rules_python/issues/3172
32+
pass
33+
# The normal sys.executable is the next-best guess if sys._base_executable
34+
# is missing.
35+
return sys.executable
36+
1937
data = {
2038
"major": sys.version_info.major,
2139
"minor": sys.version_info.minor,
2240
"micro": sys.version_info.micro,
2341
"include": sysconfig.get_path("include"),
2442
"implementation_name": sys.implementation.name,
25-
"base_executable": sys._base_executable,
43+
"base_executable": _get_base_executable(),
2644
}
2745

2846
config_vars = [

0 commit comments

Comments
 (0)