diff --git a/py/BUILD.bazel b/py/BUILD.bazel index 6f8acb3a..210cb040 100644 --- a/py/BUILD.bazel +++ b/py/BUILD.bazel @@ -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", @@ -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", ], ) diff --git a/py/defs.bzl b/py/defs.bzl index 60b17092..e15c718c 100644 --- a/py/defs.bzl +++ b/py/defs.bzl @@ -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") @@ -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 diff --git a/py/private/BUILD.bazel b/py/private/BUILD.bazel index f8e3d802..f30f8a33 100644 --- a/py/private/BUILD.bazel +++ b/py/private/BUILD.bazel @@ -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"], @@ -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"], diff --git a/py/private/py_venv/BUILD.bazel b/py/private/py_venv/BUILD.bazel index ed6d42ec..63b53a2f 100644 --- a/py/private/py_venv/BUILD.bazel +++ b/py/private/py_venv/BUILD.bazel @@ -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( @@ -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", diff --git a/py/private/_virtualenv.py b/py/private/py_venv/_virtualenv.py similarity index 100% rename from py/private/_virtualenv.py rename to py/private/py_venv/_virtualenv.py diff --git a/py/private/py_venv/py_venv.bzl b/py/private/py_venv/py_venv.bzl index f8eb01dd..10dab878 100644 --- a/py/private/py_venv/py_venv.bzl +++ b/py/private/py_venv/py_venv.bzl @@ -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) @@ -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: @@ -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, @@ -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", @@ -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", ), }) @@ -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, diff --git a/py/private/py_binary.bzl b/py/private/py_venv/py_venv_exec.bzl similarity index 98% rename from py/private/py_binary.bzl rename to py/private/py_venv/py_venv_exec.bzl index 827bf9bf..d5221c6f 100644 --- a/py/private/py_binary.bzl +++ b/py/private/py_venv/py_venv_exec.bzl @@ -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 [ @@ -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", diff --git a/py/private/run.tmpl.sh b/py/private/py_venv/run.tmpl.sh similarity index 100% rename from py/private/run.tmpl.sh rename to py/private/py_venv/run.tmpl.sh diff --git a/py/private/venv.bzl b/py/private/py_venv/venv.bzl similarity index 100% rename from py/private/venv.bzl rename to py/private/py_venv/venv.bzl diff --git a/py/private/venv_activate.tmpl.sh b/py/private/py_venv/venv_activate.tmpl.sh similarity index 100% rename from py/private/venv_activate.tmpl.sh rename to py/private/py_venv/venv_activate.tmpl.sh