Skip to content

Commit 34a3090

Browse files
committed
add test
1 parent 23cb11d commit 34a3090

File tree

22 files changed

+74
-0
lines changed

22 files changed

+74
-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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
rctx.watch_tree(root)
14+
15+
output = rctx.path(rctx.attr.output)
16+
repo_utils.execute_checked(
17+
rctx,
18+
# cd to root so zip recursively takes everything there.
19+
working_directory = str(root),
20+
op = "WhlFromDir",
21+
arguments = [
22+
"zip",
23+
"-0", # Skip compressing
24+
"-X", # Don't store file time or metadata
25+
str(output),
26+
"-r",
27+
".",
28+
],
29+
)
30+
rctx.file("BUILD.bazel", 'exports_files(glob(["*"]))')
31+
32+
whl_from_dir_repo = repository_rule(
33+
implementation = _whl_from_dir_repo,
34+
attrs = {
35+
"root": attr.label(),
36+
"output": attr.string(),
37+
},
38+
)
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)