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 ea80366

Browse filesBrowse files
andponlin-canvaaignasrickeylev
authored
feat: env-var for additional interpreter args in bootstrap stage 1 (#2654)
There is no means to be able to provide additional interpreter arguments to the `bash`-based stage 1 bootstrap system at launch time. The Intelli-J / Bazel plugin typically launches a `py_*` rule build product with something like this (abridged) using a Python interpreter from the local environment; ``` python3 /path/to/pydev/pydevd.py --client 127.0.0.1 --port 12344 --file /path/to/built/python-file ``` When the `bash`-based bootstrap process is used, this mechanism not longer works. This PR will mean that a potential future Intelli-j / Bazel plugin version may be able to launch the build product differently and inject additional interpreter arguments so that the debug system can be stood up in this sort of a way; ``` RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS="/path/to/pydev/pydevd.py --client 127.0.0.1 --port 12344 --file" /path/to/bash-bootstrap-stage1-script ``` The work to support this in the Intelli-J / Bazel plugin has not been done; it would have to be undertaken some time after this change were available. --------- Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Co-authored-by: Richard Levasseur <rlevasseur@google.com>
1 parent 4079953 commit ea80366
Copy full SHA for ea80366

File tree

Expand file treeCollapse file tree

4 files changed

+42
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+42
-0
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ Unreleased changes template.
9494
* (rules) APIs for creating custom rules based on the core py_binary, py_test,
9595
and py_library rules
9696
([#1647](https://github.com/bazelbuild/rules_python/issues/1647))
97+
* (rules) Added env-var to allow additional interpreter args for stage1 bootstrap.
98+
See {obj}`RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS` environment variable.
99+
Only applicable for {obj}`--bootstrap_impl=script`.
97100
* (rules) Added {obj}`interpreter_args` attribute to `py_binary` and `py_test`,
98101
which allows pass arguments to the interpreter before the regular args.
99102

‎docs/environment-variables.md

Copy file name to clipboardExpand all lines: docs/environment-variables.md
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
# Environment Variables
22

3+
::::{envvar} RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS
4+
5+
This variable allows for additional arguments to be provided to the Python interpreter
6+
at bootstrap time when the `bash` bootstrap is used. If
7+
`RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS` were provided as `-Xaaa`, then the command
8+
would be;
9+
10+
```
11+
python -Xaaa /path/to/file.py
12+
```
13+
14+
This feature is likely to be useful for the integration of debuggers. For example,
15+
it would be possible to configure the `RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS` to
16+
be set to `/path/to/debugger.py --port 12344 --file` resulting
17+
in the command executed being;
18+
19+
```
20+
python /path/to/debugger.py --port 12345 --file /path/to/file.py
21+
```
22+
23+
:::{seealso}
24+
The {bzl:obj}`interpreter_args` attribute.
25+
:::
26+
27+
:::{versionadded} VERSION_NEXT_FEATURE
28+
29+
::::
30+
331
:::{envvar} RULES_PYTHON_BOOTSTRAP_VERBOSE
432

533
When `1`, debug information about bootstrapping of a program is printed to

‎python/private/py_executable.bzl

Copy file name to clipboardExpand all lines: python/private/py_executable.bzl
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ CPython, see https://docs.python.org/3/using/cmdline.html.
9898
Only supported for {obj}`--bootstrap_impl=script`. Ignored otherwise.
9999
:::
100100
101+
:::{seealso}
102+
The {obj}`RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS` environment variable
103+
:::
104+
101105
:::{versionadded} VERSION_NEXT_FEATURE
102106
:::
103107
""",

‎python/private/stage1_bootstrap_template.sh

Copy file name to clipboardExpand all lines: python/private/stage1_bootstrap_template.sh
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ stage2_bootstrap="$RUNFILES_DIR/$STAGE2_BOOTSTRAP"
202202

203203
declare -a interpreter_env
204204
declare -a interpreter_args
205+
declare -a additional_interpreter_args
205206

206207
# Don't prepend a potentially unsafe path to sys.path
207208
# See: https://docs.python.org/3.11/using/cmdline.html#envvar-PYTHONSAFEPATH
@@ -220,6 +221,12 @@ if [[ "$IS_ZIPFILE" == "1" ]]; then
220221
interpreter_args+=("-XRULES_PYTHON_ZIP_DIR=$zip_dir")
221222
fi
222223

224+
if [[ -n "${RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS}" ]]; then
225+
read -a additional_interpreter_args <<< "${RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS}"
226+
interpreter_args+=("${additional_interpreter_args[@]}")
227+
unset RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS
228+
fi
229+
223230
export RUNFILES_DIR
224231

225232
command=(

0 commit comments

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