diff --git a/docs/py_binary.md b/docs/py_binary.md index ce1efa34..7a0efcc8 100644 --- a/docs/py_binary.md +++ b/docs/py_binary.md @@ -42,8 +42,8 @@ python.toolchain(python_version = "3.9", is_default = True) ## py_binary_rule
-py_binary_rule(name, data, deps, env, imports, main, package_collisions, python_version, - resolutions, srcs) +py_binary_rule(name, data, deps, env, imports, interpreter_options, main, package_collisions, + python_version, resolutions, srcs)Run a Python program under Bazel. Most users should use the [py_binary macro](#py_binary) instead of loading this directly. @@ -58,6 +58,7 @@ Run a Python program under Bazel. Most users should use the [py_binary macro](#p | deps | Targets that produce Python code, commonly
py_library
rules. | List of labels | optional | []
|
| env | Environment variables to set when running the binary. | Dictionary: String -> String | optional | {}
|
| imports | List of import directories to be added to the PYTHONPATH. | List of strings | optional | []
|
+| interpreter_options | Additional options to pass to the Python interpreter in addition to -B and -I passed by rules_py | List of strings | optional | []
|
| main | Script to execute with the Python interpreter. | Label | required | |
| package_collisions | The action that should be taken when a symlink collision is encountered when creating the venv. A collision can occour when multiple packages providing the same file are installed into the venv. The possible values are:"error"
|
| python_version | Whether to build this target and its transitive deps for a specific python version. | String | optional | ""
|
diff --git a/docs/py_test.md b/docs/py_test.md
index d1b440a5..247964d5 100644
--- a/docs/py_test.md
+++ b/docs/py_test.md
@@ -42,8 +42,8 @@ python.toolchain(python_version = "3.9", is_default = True)
## py_test_rule
-py_test_rule(name, data, deps, env, env_inherit, imports, main, package_collisions, python_version, - resolutions, srcs) +py_test_rule(name, data, deps, env, env_inherit, imports, interpreter_options, main, + package_collisions, python_version, resolutions, srcs)Run a Python program under Bazel. Most users should use the [py_test macro](#py_test) instead of loading this directly. @@ -59,6 +59,7 @@ Run a Python program under Bazel. Most users should use the [py_test macro](#py_ | env | Environment variables to set when running the binary. | Dictionary: String -> String | optional |
{}
|
| env_inherit | Specifies additional environment variables to inherit from the external environment when the test is executed by bazel test. | List of strings | optional | []
|
| imports | List of import directories to be added to the PYTHONPATH. | List of strings | optional | []
|
+| interpreter_options | Additional options to pass to the Python interpreter in addition to -B and -I passed by rules_py | List of strings | optional | []
|
| main | Script to execute with the Python interpreter. | Label | required | |
| package_collisions | The action that should be taken when a symlink collision is encountered when creating the venv. A collision can occour when multiple packages providing the same file are installed into the venv. The possible values are:"error"
|
| python_version | Whether to build this target and its transitive deps for a specific python version. | String | optional | ""
|
diff --git a/py/private/py_binary.bzl b/py/private/py_binary.bzl
index e8247ef3..575ff1ce 100644
--- a/py/private/py_binary.bzl
+++ b/py/private/py_binary.bzl
@@ -69,7 +69,7 @@ def _py_binary_rule_impl(ctx):
output = executable_launcher,
substitutions = {
"{{BASH_RLOCATION_FN}}": BASH_RLOCATION_FUNCTION,
- "{{INTERPRETER_FLAGS}}": " ".join(py_toolchain.flags),
+ "{{INTERPRETER_FLAGS}}": " ".join(py_toolchain.flags + ctx.attr.interpreter_options),
"{{VENV_TOOL}}": to_rlocation_path(ctx, venv_toolchain.bin),
"{{ARG_COLLISION_STRATEGY}}": ctx.attr.package_collisions,
"{{ARG_PYTHON}}": to_rlocation_path(ctx, py_toolchain.python) if py_toolchain.runfiles_interpreter else py_toolchain.python.path,
@@ -154,6 +154,10 @@ A collision can occour when multiple packages providing the same file are instal
default = "error",
values = ["error", "warning", "ignore"],
),
+ "interpreter_options": attr.string_list(
+ doc = "Additional options to pass to the Python interpreter in addition to -B and -I passed by rules_py",
+ default = [],
+ ),
"_run_tmpl": attr.label(
allow_single_file = True,
default = "//py/private:run.tmpl.sh",