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
1 change: 1 addition & 0 deletions py/private/entry.tmpl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ ln -snf "${VENV_SOURCE}/lib" "${VENV_LOCATION}/lib"
mkdir "${VBIN_LOCATION}" 2>/dev/null || true
ln -snf ${VENV_SOURCE}/bin/* "${VBIN_LOCATION}/"
ln -snf "${PYTHON_LOCATION}" "${VBIN_LOCATION}/python3"
ln -snf "${VBIN_LOCATION}/python3" "${VBIN_LOCATION}/python"

echo "home = ${VBIN_LOCATION}" > "${VENV_LOCATION}/pyvenv.cfg"
echo "include-system-site-packages = false" >> "${VENV_LOCATION}/pyvenv.cfg"
Expand Down
4 changes: 3 additions & 1 deletion py/private/py_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ def _py_binary_rule_imp(ctx):
"BAZEL_TARGET_NAME": ctx.attr.name,
}, **ctx.attr.env)

python_interpreter_path = interpreter.python.path if interpreter.uses_interpreter_path else to_manifest_path(ctx, interpreter.python)

common_substitutions = {
"{{BASH_BIN}}": bash_bin,
"{{BASH_RLOCATION_FN}}": BASH_RLOCATION_FUNCTION,
"{{BINARY_ENTRY_POINT}}": to_manifest_path(ctx, main),
"{{INTERPRETER_FLAGS}}": " ".join(interpreter.flags),
"{{PYTHON_INTERPRETER_PATH}}": to_manifest_path(ctx, interpreter.python),
"{{PYTHON_INTERPRETER_PATH}}": python_interpreter_path,
"{{RUN_BINARY_ENTRY_POINT}}": "true",
"{{VENV_SOURCE}}": to_manifest_path(ctx, venv_info.venv_directory),
"{{VENV_NAME}}": "%s.venv" % ctx.attr.name,
Expand Down
16 changes: 15 additions & 1 deletion py/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,28 @@ def resolve_toolchain(ctx):

py3_toolchain = toolchain_info.py3_runtime

interpreter = None
uses_interpreter_path = False

if py3_toolchain.interpreter != None:
files = depset([py3_toolchain.interpreter], transitive = [py3_toolchain.files])
interpreter = py3_toolchain.interpreter
else:
files = py3_toolchain.files
interpreter = struct(
path = py3_toolchain.interpreter_path,
short_path = py3_toolchain.interpreter_path,
)
files = depset([])
uses_interpreter_path = True

if interpreter == None:
fail("Unable to resolve interpreter to a path or file. Ensure `interpreter` or `interpreter_file` is defined on the py3_runtime")

return struct(
toolchain = py3_toolchain,
files = files,
python = py3_toolchain.interpreter,
python = interpreter,
uses_interpreter_path = uses_interpreter_path,
flags = ["-B", "-s", "-I"],
)
3 changes: 1 addition & 2 deletions py/private/venv/venv.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def _make_venv(ctx, name = None, main = None, strip_pth_workspace_root = None):
**{
"{{WHL_REQUIREMENTS_FILE}}": to_manifest_path(ctx, whl_requirements),
"{{PTH_FILE}}": to_manifest_path(ctx, pth),
"{{PYTHON_INTERPRETER_PATH}}": interpreter.python.path,
"{{VENV_LOCATION}}": "${BUILD_WORKSPACE_DIRECTORY}/.%s" % name,
"{{USE_MANIFEST_PATH}}": "true",
}
Expand All @@ -143,7 +142,7 @@ def _make_venv(ctx, name = None, main = None, strip_pth_workspace_root = None):
inputs = venv_creation_depset,
command = make_venv_for_action_sh.path,
tools = [
interpreter.toolchain.files,
interpreter.files,
],
progress_message = "Creating virtual environment for %{label}",
mnemonic = "CreateVenv",
Expand Down