Skip to content
Merged
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
18 changes: 11 additions & 7 deletions py/private/py_binary.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Implementation for the py_binary and py_test rules."""

load("@rules_python//python:defs.bzl", "PyInfo")
load("@aspect_bazel_lib//lib:paths.bzl", "BASH_RLOCATION_FUNCTION", "to_rlocation_path")
load("@aspect_bazel_lib//lib:expand_make_vars.bzl", "expand_locations", "expand_variables")
load("@aspect_bazel_lib//lib:paths.bzl", "BASH_RLOCATION_FUNCTION", "to_rlocation_path")
load("@rules_python//python:defs.bzl", "PyInfo")
load("//py/private:py_library.bzl", _py_library = "py_library_utils")
load("//py/private:py_semantics.bzl", _py_semantics = "semantics")
load("//py/private/toolchain:types.bzl", "PY_TOOLCHAIN", "VENV_TOOLCHAIN")
Expand Down Expand Up @@ -49,14 +49,15 @@ def _py_binary_rule_impl(ctx):
content = pth_lines,
)

env = dict({
default_env = {
"BAZEL_TARGET": str(ctx.label).lstrip("@"),
"BAZEL_WORKSPACE": ctx.workspace_name,
"BAZEL_TARGET_NAME": ctx.attr.name,
}, **ctx.attr.env)
}

for k, v in env.items():
env[k] = expand_variables(
passed_env = dict(ctx.attr.env)
for k, v in passed_env.items():
passed_env[k] = expand_variables(
ctx,
expand_locations(ctx, v, ctx.attr.data),
attribute_name = "env",
Expand All @@ -75,7 +76,7 @@ def _py_binary_rule_impl(ctx):
"{{ARG_VENV_NAME}}": ".{}.venv".format(ctx.attr.name),
"{{ARG_PTH_FILE}}": to_rlocation_path(ctx, site_packages_pth_file),
"{{ENTRYPOINT}}": to_rlocation_path(ctx, ctx.file.main),
"{{PYTHON_ENV}}": "\n".join(_dict_to_exports(env)).strip(),
"{{PYTHON_ENV}}": "\n".join(_dict_to_exports(default_env)).strip(),
"{{EXEC_PYTHON_BIN}}": "python{}".format(
py_toolchain.interpreter_version_info.major,
),
Expand Down Expand Up @@ -123,6 +124,9 @@ def _py_binary_rule_impl(ctx):
uses_shared_libraries = False,
),
instrumented_files_info,
RunEnvironmentInfo(
environment = passed_env,
),
]

_attrs = dict({
Expand Down
Loading