Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a0400e9

Browse filesBrowse files
authored
feat(toolchain): Add new make vars for Python interpreter path compliant with --no_legacy_external_runfiles (bazel-contrib#2772)
Using these new make vars in `py_binary` or `py_test` will correctly find the interpreter when setting `--no_legacy_external_runfiles`. Fixes bazel-contrib#2728
1 parent 79abef8 commit a0400e9
Copy full SHA for a0400e9

File tree

Expand file treeCollapse file tree

3 files changed

+14
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+14
-1
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ Unreleased changes template.
124124
* (toolchains) Local Python installs can be used to create a toolchain
125125
equivalent to the standard toolchains. See [Local toolchains] docs for how to
126126
configure them.
127+
* (toolchains) Expose `$(PYTHON2_ROOTPATH)` and `$(PYTHON3_ROOTPATH)` which are runfiles
128+
locations equivalents of `$(PYTHON2)` and `$(PYTHON3) respectively.
127129

128130

129131
{#v0-0-0-removed}

‎docs/toolchains.md

Copy file name to clipboardExpand all lines: docs/toolchains.md
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ attribute. You can obtain the path to the Python interpreter using the
215215
`$(PYTHON2)` and `$(PYTHON3)` ["Make"
216216
Variables](https://bazel.build/reference/be/make-variables). See the
217217
{gh-path}`test_current_py_toolchain <tests/load_from_macro/BUILD.bazel>` target
218-
for an example.
218+
for an example. We also make available `$(PYTHON2_ROOTPATH)` and `$(PYTHON3_ROOTPATH)`
219+
which are Make Variable equivalents of `$(PYTHON2)` and `$(PYTHON3)` but for runfiles
220+
locations. These will be helpful if you need to set env vars of binary/test rules
221+
while using [`--nolegacy_external_runfiles`](https://bazel.build/reference/command-line-reference#flag--legacy_external_runfiles).
222+
The original make variables still work in exec contexts such as genrules.
219223

220224
### Overriding toolchain defaults and adding more versions
221225

‎python/current_py_toolchain.bzl

Copy file name to clipboardExpand all lines: python/current_py_toolchain.bzl
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ def _current_py_toolchain_impl(ctx):
2727
direct.append(toolchain.py3_runtime.interpreter)
2828
transitive.append(toolchain.py3_runtime.files)
2929
vars["PYTHON3"] = toolchain.py3_runtime.interpreter.path
30+
vars["PYTHON3_ROOTPATH"] = toolchain.py3_runtime.interpreter.short_path
3031

3132
if toolchain.py2_runtime and toolchain.py2_runtime.interpreter:
3233
direct.append(toolchain.py2_runtime.interpreter)
3334
transitive.append(toolchain.py2_runtime.files)
3435
vars["PYTHON2"] = toolchain.py2_runtime.interpreter.path
36+
vars["PYTHON2_ROOTPATH"] = toolchain.py2_runtime.interpreter.short_path
3537

3638
files = depset(direct, transitive = transitive)
3739
return [
@@ -49,6 +51,11 @@ current_py_toolchain = rule(
4951
other rules, such as genrule. It allows exposing a python toolchain after toolchain resolution has
5052
happened, to a rule which expects a concrete implementation of a toolchain, rather than a
5153
toolchain_type which could be resolved to that toolchain.
54+
55+
:::{versionchanged} VERSION_NEXT_FEATURE
56+
From now on, we also expose `$(PYTHON2_ROOTPATH)` and `$(PYTHON3_ROOTPATH)` which are runfiles
57+
locations equivalents of `$(PYTHON2)` and `$(PYTHON3) respectively.
58+
:::
5259
""",
5360
implementation = _current_py_toolchain_impl,
5461
attrs = {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.