@@ -51,7 +51,20 @@ def _resolve_python_interpreter(mrctx, *, python_interpreter = None, python_inte
51
51
python_interpreter = _get_python_interpreter_attr (mrctx , python_interpreter = python_interpreter )
52
52
53
53
if python_interpreter_target != None :
54
- python_interpreter = mrctx .path (python_interpreter_target )
54
+ # The following line would make the MODULE.bazel.lock platform
55
+ # independent, because the lock file will then contain a hash of the
56
+ # file so that the lock file can be recalculated, hence the best way is
57
+ # to add this directory to PATH.
58
+ #
59
+ # hence we add the root BUILD.bazel file and get the directory of that
60
+ # and construct the path differently. At the end of the day we don't
61
+ # want the hash of the interpreter to end up in the lock file.
62
+ if hasattr (python_interpreter_target , "same_package_label" ):
63
+ root_build_bazel = python_interpreter_target .same_package_label ("BUILD.bazel" )
64
+ else :
65
+ root_build_bazel = python_interpreter_target .relative (":BUILD.bazel" )
66
+
67
+ python_interpreter = mrctx .path (root_build_bazel ).dirname .get_child (python_interpreter_target .name )
55
68
56
69
os = repo_utils .get_platforms_os_name (mrctx )
57
70
@@ -110,7 +123,7 @@ def _execute_checked(mrctx, *, srcs, **kwargs):
110
123
# This will ensure that we will re-evaluate the bzlmod extension or
111
124
# refetch the repository_rule when the srcs change. This should work on
112
125
# Bazel versions without `mrctx.watch` as well.
113
- repo_utils .watch (mrctx .path (src ))
126
+ repo_utils .watch (mrctx , mrctx .path (src ))
114
127
115
128
env = kwargs .pop ("environment" , {})
116
129
pythonpath = env .get ("PYTHONPATH" , "" )
0 commit comments