Skip to content

Commit 3edab06

Browse files
committed
add test
1 parent 23cb11d commit 3edab06

File tree

22 files changed

+90
-0
lines changed

22 files changed

+90
-0
lines changed

MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ use_repo(
103103
internal_dev_deps,
104104
"buildkite_config",
105105
"rules_python_runtime_env_tc_info",
106+
"somepkg_with_build_files",
107+
"whl_with_build_files",
106108
)
107109

108110
# Add gazelle plugin so that we can run the gazelle example as an e2e integration

python/private/internal_dev_deps.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"""Module extension for internal dev_dependency=True setup."""
1515

1616
load("@bazel_ci_rules//:rbe_repo.bzl", "rbe_preconfig")
17+
load("//python/private/pypi:whl_library.bzl", "whl_library")
18+
load("//tests/support/whl_from_dir:whl_from_dir_repo.bzl", "whl_from_dir_repo")
1719
load(":runtime_env_repo.bzl", "runtime_env_repo")
1820

1921
def _internal_dev_deps_impl(mctx):
@@ -28,6 +30,17 @@ def _internal_dev_deps_impl(mctx):
2830
)
2931
runtime_env_repo(name = "rules_python_runtime_env_tc_info")
3032

33+
whl_from_dir_repo(
34+
name = "whl_with_build_files",
35+
root = "//tests/whl_with_build_files/testdata:BUILD.bazel",
36+
output = "somepkg-1.0-any-none-any.whl",
37+
)
38+
whl_library(
39+
name = "somepkg_with_build_files",
40+
whl_file = "@whl_with_build_files//:somepkg-1.0-any-none-any.whl",
41+
requirement = "somepkg",
42+
)
43+
3144
internal_dev_deps = module_extension(
3245
implementation = _internal_dev_deps_impl,
3346
doc = "This extension creates internal rules_python dev dependencies.",

python/private/pypi/whl_library.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def _whl_library_impl(rctx):
249249

250250
whl_path = None
251251
if rctx.attr.whl_file:
252+
rctx.watch(rctx.attr.whl_file)
252253
whl_path = rctx.path(rctx.attr.whl_file)
253254

254255
# Simulate the behaviour where the whl is present in the current directory.

tests/support/whl_from_dir/BUILD.bazel

Whitespace-only changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Creates a whl file from a directory tree.
2+
3+
Used to test wheels. Avoids checking in prebuilt files and their associated
4+
security risks.
5+
"""
6+
7+
load("//python/private:repo_utils.bzl", "repo_utils")
8+
9+
def _whl_from_dir_repo(rctx):
10+
manifest = []
11+
12+
root = rctx.path(rctx.attr.root).dirname
13+
# todo: recursively watch so it regens automatically
14+
##paths = list(root.readdir(watch = "yes"))
15+
##for _ in range(1000):
16+
## if not paths:
17+
## break
18+
## path = paths.pop()
19+
## if path.is_dir:
20+
## paths.extend(path.readdir(watch = "yes"))
21+
## else:
22+
## zip_path = str(path).removeprefix(root + "/")
23+
## actual_path = str(path)
24+
## manifest.append("{}={}".format(zip_path, actual_path))
25+
26+
print("Watch: {}".format(root))
27+
rctx.watch_tree(root)
28+
29+
##rctx.file("files.txt", manifest)
30+
output = rctx.path(rctx.attr.output)
31+
output = repo_utils.execute_checked_stdout(
32+
rctx,
33+
# cd to root so zip recursively takes everything there.
34+
working_directory = str(root),
35+
op = "WhlFromDir",
36+
arguments = [
37+
"zip",
38+
"-v",
39+
"-0",
40+
str(output),
41+
"-r",
42+
".",
43+
],
44+
)
45+
print(output)
46+
rctx.file("BUILD.bazel", 'exports_files(glob(["*"]))')
47+
48+
whl_from_dir_repo = repository_rule(
49+
implementation = _whl_from_dir_repo,
50+
attrs = {
51+
"root": attr.label(),
52+
"output": attr.string(),
53+
},
54+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("//python:py_test.bzl", "py_test")
2+
3+
py_test(
4+
name = "verify_files_test",
5+
srcs = ["verify_files_test.py"],
6+
deps = ["@somepkg_with_build_files//:pkg"],
7+
)

tests/whl_with_build_files/testdata/BUILD

Whitespace-only changes.

tests/whl_with_build_files/testdata/BUILD.bazel

Whitespace-only changes.

tests/whl_with_build_files/testdata/somepkg-1.0.dist-info/BUILD

Whitespace-only changes.

tests/whl_with_build_files/testdata/somepkg-1.0.dist-info/BUILD.bazel

Whitespace-only changes.

0 commit comments

Comments
 (0)