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
2 changes: 1 addition & 1 deletion py/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ bzl_library(
srcs = ["defs.bzl"],
visibility = ["//visibility:public"],
deps = [
"//py/private:py_binary",
"//py/private:py_image_layer",
"//py/private:py_library",
"//py/private:py_pex_binary",
Expand All @@ -21,6 +20,7 @@ bzl_library(
"//py/private:py_wheel",
"//py/private:virtual",
"//py/private/py_venv",
"//py/private/py_venv:py_venv_exec",
"@bazel_lib//lib:utils",
],
)
Expand Down
2 changes: 1 addition & 1 deletion py/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ python.toolchain(python_version = "3.9", is_default = True)
```
"""

load("//py/private:py_binary.bzl", _py_venv_exec = "py_venv_exec", _py_venv_exec_test = "py_venv_exec_test")
load("//py/private:py_image_layer.bzl", _py_image_layer = "py_image_layer")
load("//py/private:py_library.bzl", _py_library = "py_library")
load("//py/private:py_pex_binary.bzl", _py_pex_binary = "py_pex_binary")
Expand All @@ -26,6 +25,7 @@ load(
_py_venv = "py_venv",
_py_venv_link = "py_venv_link",
)
load("//py/private/py_venv:py_venv_exec.bzl", _py_venv_exec = "py_venv_exec", _py_venv_exec_test = "py_venv_exec_test")

py_pex_binary = _py_pex_binary
py_pytest_main = _py_pytest_main
Expand Down
20 changes: 0 additions & 20 deletions py/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ package(default_visibility = ["//py:__subpackages__"])

exports_files(
[
"run.tmpl.sh",
"pytest.py.tmpl",
"pytest_main.py",
"venv_activate.tmpl.sh",
"_virtualenv.py",
"modify_mtree.awk",
],
visibility = ["//visibility:public"],
Expand Down Expand Up @@ -43,23 +40,6 @@ bzl_library(
],
)

bzl_library(
name = "py_binary",
srcs = ["py_binary.bzl"],
deps = [
":pth",
":py_library",
"@bazel_lib//lib:expand_make_vars",
"@bazel_lib//lib:paths",
],
)

bzl_library(
name = "venv",
srcs = ["venv.bzl"],
deps = [":py_library"],
)

bzl_library(
name = "py_library",
srcs = ["py_library.bzl"],
Expand Down
29 changes: 25 additions & 4 deletions py/private/py_venv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ load("//py:defs.bzl", "py_test")
package(default_visibility = ["//py:__subpackages__"])

exports_files([
"venv.tmpl.sh",
"_virtualenv.py",
"link.py",
"run.tmpl.sh",
"venv.tmpl.sh",
"venv_activate.tmpl.sh",
])

bool_flag(
Expand Down Expand Up @@ -39,16 +42,34 @@ bzl_library(
],
)

bzl_library(
name = "venv",
srcs = ["venv.bzl"],
deps = ["//py/private:py_library"],
)

bzl_library(
name = "py_venv_exec",
srcs = ["py_venv_exec.bzl"],
deps = [
":types",
"//py/private:py_library",
"//py/private:py_semantics",
"@bazel_lib//lib:expand_make_vars",
"@bazel_lib//lib:paths",
],
)

bzl_library(
name = "py_venv",
srcs = ["py_venv.bzl"],
deps = [
":types.bzl",
"//py/private:providers",
":py_venv_exec",
":types",
":venv",
"//py/private:py_library",
"//py/private:py_semantics",
"//py/private:transitions",
"//py/private:venv",
"//py/private/toolchain:types",
"@bazel_lib//lib:expand_make_vars",
"@bazel_lib//lib:paths",
Expand Down
File renamed without changes.
18 changes: 9 additions & 9 deletions py/private/py_venv/py_venv.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
your IDE a stable `.venv` symlink to point at.

Shared venv-assembly logic lives in
`//py/private:venv.bzl::assemble_venv`. See that file's header for the
`//py/private/py_venv:venv.bzl::assemble_venv`. See that file's header for the
layout details.
"""

load("@bazel_lib//lib:expand_make_vars.bzl", "expand_locations", "expand_variables")
load("@bazel_lib//lib:paths.bzl", "BASH_RLOCATION_FUNCTION", "to_rlocation_path")
load("//py/private:py_binary.bzl", _py_venv_exec = "py_venv_exec")
load("//py/private:py_library.bzl", _py_library = "py_library_utils")
load("//py/private:py_semantics.bzl", _py_semantics = "semantics")
load("//py/private:transitions.bzl", "python_version_transition")
load("//py/private:venv.bzl", "assemble_venv")
load("//py/private/toolchain:types.bzl", "PY_TOOLCHAIN")
load(":py_venv_exec.bzl", _py_venv_exec = "py_venv_exec")
load(":types.bzl", "VirtualenvInfo")
load(":venv.bzl", "assemble_venv")

def _interpreter_flags(ctx, include_main = False):
py_toolchain = _py_semantics.resolve_toolchain(ctx)
Expand All @@ -41,7 +41,7 @@ def _interpreter_flags(ctx, include_main = False):
# py_venv strips `-I` so the interpreter picks up PYTHONPATH and
# script dir — useful when users `bazel run` the venv for an
# interactive python session and want their shell's env to apply.
# The per-binary py_binary launcher keeps `-I` (see py_binary.bzl).
# The per-binary py_binary launcher keeps `-I` (see py_venv_exec.bzl).
args = [it for it in args if it not in ["-I"]]

if include_main and hasattr(ctx.file, "main") and ctx.file.main:
Expand Down Expand Up @@ -150,7 +150,7 @@ def _py_venv_rule_impl(ctx):
# Forwarded to the sibling py_binary/py_test consumer (created
# by `expose_venv = True`) so env vars declared on the venv
# apply to the binary using it. The binary's own `env` wins on
# key conflicts; see py_binary.bzl.
# key conflicts; see py_venv_exec.bzl.
RunEnvironmentInfo(
environment = passed_env,
inherited_environment = ctx.attr.env_inherit,
Expand Down Expand Up @@ -224,7 +224,7 @@ environment. Forwarded to the sibling py_binary/py_test consumer
),
"_run_tmpl": attr.label(
allow_single_file = True,
default = "//py/private/py_venv:venv.tmpl.sh",
default = ":venv.tmpl.sh",
),
"_runfiles_lib": attr.label(
default = "@bazel_tools//tools/bash/runfiles",
Expand All @@ -237,11 +237,11 @@ environment. Forwarded to the sibling py_binary/py_test consumer
# Shared with py_binary via the venv-assembly helper.
"_venv_activate_tmpl": attr.label(
allow_single_file = True,
default = "//py/private:venv_activate.tmpl.sh",
default = ":venv_activate.tmpl.sh",
),
"_virtualenv_shim": attr.label(
allow_single_file = True,
default = "//py/private:_virtualenv.py",
default = ":_virtualenv.py",
),
})

Expand Down Expand Up @@ -379,7 +379,7 @@ def py_venv_link(name, venv, link_name = None, **kwargs):
target's package + venv name.
**kwargs: Forwarded to the underlying `py_binary`.
"""
link_script = str(Label("//py/private/py_venv:link.py"))
link_script = str(Label(":link.py"))
_py_venv_exec(
name = name,
main = link_script,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ internal `venv` attr) and exec its `bin/python`. The public
attrs to the auto-generated sibling.
"""

# TODO: rename this file to py_venv_exec.bzl.

load("@bazel_lib//lib:expand_make_vars.bzl", "expand_locations", "expand_variables")
load("@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/py_venv:types.bzl", "VirtualenvInfo")
load(":types.bzl", "VirtualenvInfo")

def _dict_to_exports(env):
return [
Expand Down Expand Up @@ -182,7 +180,7 @@ match their historical permissive behaviour.""",
),
"_run_tmpl": attr.label(
allow_single_file = True,
default = "//py/private:run.tmpl.sh",
default = ":run.tmpl.sh",
),
"_runfiles_lib": attr.label(
default = "@bazel_tools//tools/bash/runfiles",
Expand Down
File renamed without changes.
File renamed without changes.