Skip to content

Commit 1e132f6

Browse files
committed
Demonstrate how to use BUILD files as test inputs
1 parent ee9a500 commit 1e132f6

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
# `python_requirement_library` target. Refer to
66
# https://www.pantsbuild.org/docs/python-third-party-dependencies.
77
python_requirements(name="reqs")
8+
9+
files(name="library_build_files", sources=["helloworld/**/BUILD"])
10+
11+
python_tests(name="tests", dependencies=[":library_build_files"])
12+

library_build_files_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
import importlib.resources
3+
4+
def test_library_build_files() -> None:
5+
def iterate(traversable: importlib.resources.abc.Traversable):
6+
for item in traversable.iterdir():
7+
if item.is_dir():
8+
iterate(item)
9+
elif item.name == "BUILD":
10+
print(f"Validating {item}")
11+
with item.open("r") as fp:
12+
content = fp.read()
13+
print(f" Content: {content}")
14+
print("-------------------------")
15+
16+
iterate(importlib.resources.files("helloworld"))

pants.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[GLOBAL]
55
pants_version = "2.26.0"
66
backend_packages.add = [
7-
"pants.backend.build_files.fmt.black",
7+
"pants.backend.build_files.fmt.black",
88
"pants.backend.python",
99
"pants.backend.python.lint.docformatter",
1010
"pants.backend.python.lint.black",
@@ -29,7 +29,7 @@ root_patterns = ["/"]
2929
# Modify this if you don't have Python 3.9 on your machine.
3030
# This can be a range, such as [">=3.8,<3.11"], but it's usually recommended to restrict
3131
# to a single minor version.
32-
interpreter_constraints = ["==3.9.*"]
32+
interpreter_constraints = ["==3.11.*"]
3333

3434
# Enable the "resolves" mechanism, which turns on lockfiles for user code. See
3535
# https://www.pantsbuild.org/docs/python-third-party-dependencies. This also adds the

0 commit comments

Comments
 (0)