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
11 changes: 11 additions & 0 deletions py/tests/containers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ py_binary(
name = "main_bin",
srcs = ["__main__.py"],
deps = [
"//py/tests/containers/branding",
"//py/tests/internal-deps/adder",
"@pypi_colorama//:pkg",
],
)

# py3_image container support reverts us back to the rules_python way of invoking the binary,
# (as really there is a py_binary in the py3_image).
# This test ensures that rules_py can still run in that mode, but there are a few notable exceptions:
# * There is no longer a virtual env to run in
# * The rules_py launcher isn't invoked
# * There is no pip
# * Dependencies that were consumed via wheel targets are lost
# Perhaps rules_container can provide a suitable alternative here, or rules_py provides a thin wrapper around the
# rules_docker container_image that produces the expected output, but it would be limited in terms of customisation.
py3_image(
name = "py_image",
srcs = ["__main__.py"],
Expand Down
5 changes: 4 additions & 1 deletion py/tests/containers/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from colorama import Fore, Style

from branding import get_branding
from adder.add import add

if __name__ == "__main__":
print(f"{Fore.GREEN}Hello rules_py{Style.RESET_ALL}")
print(f"{Fore.GREEN}Hello {get_branding()} - {add(3, .14)}{Style.RESET_ALL}")
8 changes: 8 additions & 0 deletions py/tests/containers/branding/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("//py:defs.bzl", "py_library")

py_library(
name = "branding",
srcs = ["__init__.py"],
imports = [".."],
visibility = ["//py/tests/containers:__pkg__"],
)
2 changes: 2 additions & 0 deletions py/tests/containers/branding/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def get_branding():
return "rules_py"
2 changes: 1 addition & 1 deletion py/tests/containers/py_image_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ commandTests:
command: /usr/bin/python
args:
- /app/py/tests/containers/py_image.binary
expectedOutput: ["Hello rules_py"]
expectedOutput: ["Hello rules_py - 3.14"]
14 changes: 2 additions & 12 deletions py/tests/internal-deps/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ rules_py_py_library(
],
)

rules_py_py_library(
name = "add",
srcs = [
"add.py",
],
deps = [
":init",
],
)

rules_py_py_library(
name = "sub",
srcs = [
Expand All @@ -44,9 +34,9 @@ py_binary(
"__main__.py",
],
deps = [
":add",
":pi",
":sub",
"//py/tests/internal-deps/adder",
],
)

Expand All @@ -56,8 +46,8 @@ py_test(
"__main__.py",
],
deps = [
":add",
":pi",
":sub",
"//py/tests/internal-deps/adder",
],
)
2 changes: 1 addition & 1 deletion py/tests/internal-deps/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from add import add
from adder.add import add
from sub import sub
from pi import format_pi

Expand Down
16 changes: 16 additions & 0 deletions py/tests/internal-deps/adder/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("//py:defs.bzl", "py_library")

py_library(
name = "adder",
srcs = [
"__init__.py",
"add.py",
],
imports = [".."],
# This library contributes to the container test, testing we can pull in and use a library from another
# package in the repo.
visibility = [
"//py/tests/containers:__pkg__",
"//py/tests/internal-deps:__pkg__",
],
)
Empty file.
File renamed without changes.