Skip to content

Commit e8d2f96

Browse files
armandomontanezCQ Bot Account
authored andcommitted
pw_build: Implement __contains__() in RunfilesManager
Change-Id: I0ecec5da7bbc829bed4c5419d681a3be77a87bd1 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/307900 Commit-Queue: Armando Montanez <[email protected]> Reviewed-by: Keir Mierle <[email protected]> Pigweed-Auto-Submit: Armando Montanez <[email protected]> Lint: Lint 🤖 <[email protected]> Docs-Not-Needed: Armando Montanez <[email protected]> Copybara-Verified: Copybara Prod <[email protected]> Presubmit-Verified: CQ Bot Account <[email protected]>
1 parent 2434409 commit e8d2f96

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pw_build/py/pw_build/runfiles_manager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ def get(self, key: str) -> Path:
273273
def __getitem__(self, key):
274274
return self.get(key)
275275

276+
def __contains__(self, key: str) -> bool:
277+
try:
278+
self.get(key)
279+
except FileNotFoundError:
280+
return False
281+
return True
282+
276283
def _run_tool(
277284
self, tool: str, args, **kwargs
278285
) -> subprocess.CompletedProcess:

pw_build/py/runfiles_manager_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ def test_runfiles_at_root(self):
6262
self.assertTrue(c.is_file())
6363
self.assertEqual(c.read_text(), "OK\n")
6464

65+
def test_contains(self):
66+
self.r.add_bazel_file('b', 'pw_build.test_runfile')
67+
self.r.add_bootstrapped_file(
68+
'b', '${PW_ROOT}/pw_build/test_data/test_runfile.txt'
69+
)
70+
self.assertTrue('b' in self.r)
71+
self.assertFalse('nonexistent' in self.r)
72+
6573
def test_bazel_missing(self):
6674
self.r.add_bootstrapped_file(
6775
'b', '${PW_ROOT}/pw_build/test_data/test_runfile.txt'

0 commit comments

Comments
 (0)