Skip to content
Open
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
5 changes: 5 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import %workspace%/bazel/defaults.bazelrc

# TODO: re-enable once https://github.com/hermeticbuild/hermetic-launcher/pull/34
# lands — adds the missing toolchain= arg to hermetic_launcher's
# _compile_stub ctx.actions.run, which currently breaks under this flag.
common --noincompatible_auto_exec_groups

common --test_output=errors
common --incompatible_disallow_empty_glob=False

Expand Down
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bazel_dep(name = "rules_python", version = "1.0.0")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "tar.bzl", version = "0.10.1")
bazel_dep(name = "with_cfg.bzl", version = "0.14.6")
bazel_dep(name = "hermetic_launcher", version = "0.0.8")

bazel_lib_toolchains = use_extension("@tar.bzl//tar:extensions.bzl", "toolchains")
use_repo(bazel_lib_toolchains, "bsd_tar_toolchains")
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions py/private/py_pex_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ py_pex_binary(
```
"""

load("@bazel_lib//lib:paths.bzl", "to_rlocation_path")
load("@rules_python//python:defs.bzl", "PyInfo")
load("//py/private:py_semantics.bzl", _py_semantics = "semantics")
load("//py/private/py_venv:types.bzl", "PyExecutableInfo")
load("//py/private/toolchain:types.bzl", "PY_TOOLCHAIN")

def _runfiles_path(file, workspace):
Expand Down Expand Up @@ -106,7 +108,7 @@ def _py_python_pex_impl(ctx):
# this is needed to allow passing a lambda (with workspace_name) to map_each
allow_closure = True,
)
args.add(binary[DefaultInfo].files_to_run.executable, format = "--executable=%s")
args.add(to_rlocation_path(ctx, binary[PyExecutableInfo].entrypoint), format = "--entrypoint=%s")
args.add(ctx.attr.python_shebang, format = "--python-shebang=%s")

if ctx.attr.inherit_path != "":
Expand Down Expand Up @@ -137,7 +139,7 @@ def _py_python_pex_impl(ctx):
]

_attrs = dict({
"binary": attr.label(executable = True, cfg = "target", mandatory = True, doc = "A py_binary target"),
"binary": attr.label(executable = True, cfg = "target", mandatory = True, providers = [PyExecutableInfo], doc = "A py_binary target"),
"inject_env": attr.string_dict(
doc = "Environment variables to set when running the pex binary.",
default = {},
Expand Down
2 changes: 1 addition & 1 deletion py/private/py_venv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package(default_visibility = ["//py:__subpackages__"])
exports_files([
"_virtualenv.py",
"link.py",
"run.tmpl.sh",
"venv.tmpl.sh",
"venv_activate.tmpl.sh",
])
Expand Down Expand Up @@ -57,6 +56,7 @@ bzl_library(
"//py/private:py_semantics",
"@bazel_lib//lib:expand_make_vars",
"@bazel_lib//lib:paths",
"@hermetic_launcher//launcher:lib_bzl",
],
)

Expand Down
8 changes: 8 additions & 0 deletions py/private/py_venv/_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
import os
import sys

# Make wheel-declared console scripts reachable via `subprocess.run("name", ...)`.
# Use dirname(sys.executable) so this works on Windows too, where the scripts
# dir is `Scripts/` rather than `bin/`.
_venv_bin = os.path.dirname(sys.executable)
if _venv_bin not in os.environ.get("PATH", "").split(os.pathsep):
os.environ["PATH"] = _venv_bin + os.pathsep + os.environ.get("PATH", "")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anyone know of a better way of doing this? Should it be opt-in?

del _venv_bin

VIRTUALENV_PATCH_FILE = os.path.join(__file__)


Expand Down
Loading
Loading