Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ Unreleased changes template.
* (rules) APIs for creating custom rules based on the core py_binary, py_test,
and py_library rules
([#1647](https://github.com/bazelbuild/rules_python/issues/1647))
* (rules) Added env-var to allow additional interpreter args for stage1 bootstrap.
See {obj}`RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS` environment variable.
Only applicable for {obj}`--bootstrap_impl=script`.
* (rules) Added {obj}`interpreter_args` attribute to `py_binary` and `py_test`,
which allows pass arguments to the interpreter before the regular args.

Expand Down
28 changes: 28 additions & 0 deletions docs/environment-variables.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Environment Variables

::::{envvar} RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS

This variable allows for additional arguments to be provided to the Python interpreter
at bootstrap time when the `bash` bootstrap is used. If
`RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS` were provided as `-Xaaa`, then the command
would be;

```
python -Xaaa /path/to/file.py
```

This feature is likely to be useful for the integration of debuggers. For example,
it would be possible to configure the `RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS` to
be set to `/path/to/debugger.py --port 12344 --file` resulting
in the command executed being;

```
python /path/to/debugger.py --port 12345 --file /path/to/file.py
```

:::{seealso}
The {bzl:obj}`interpreter_args` attribute.
:::

:::{versionadded} VERSION_NEXT_FEATURE

::::

:::{envvar} RULES_PYTHON_BOOTSTRAP_VERBOSE

When `1`, debug information about bootstrapping of a program is printed to
Expand Down
4 changes: 4 additions & 0 deletions python/private/py_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ CPython, see https://docs.python.org/3/using/cmdline.html.
Only supported for {obj}`--bootstrap_impl=script`. Ignored otherwise.
:::

:::{seealso}
The {obj}`RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS` environment variable
:::

:::{versionadded} VERSION_NEXT_FEATURE
:::
""",
Expand Down
7 changes: 7 additions & 0 deletions python/private/stage1_bootstrap_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ stage2_bootstrap="$RUNFILES_DIR/$STAGE2_BOOTSTRAP"

declare -a interpreter_env
declare -a interpreter_args
declare -a additional_interpreter_args

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

if [[ -n "${RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS}" ]]; then
read -a additional_interpreter_args <<< "${RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS}"
interpreter_args+=("${additional_interpreter_args[@]}")
unset RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS
fi

export RUNFILES_DIR

command=(
Expand Down