Skip to content

Commit

Permalink
pw_presubmit: Fix incl-lang when not at repo root
Browse files Browse the repository at this point in the history
Change-Id: Ib43b4a4ee86b8f071f9b3beffeafac069816d2f8
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/227185
Commit-Queue: Auto-Submit <[email protected]>
Lint: Lint 🤖 <[email protected]>
Pigweed-Auto-Submit: Rob Mohr <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Reviewed-by: Jason Graffius <[email protected]>
  • Loading branch information
mohrr authored and CQ Bot Account committed Aug 2, 2024
1 parent 474eecb commit 61f8b7e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pw_presubmit/py/pw_presubmit/inclusive_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def check_file(
found_words: dict[Path, list[PathMatch | LineMatch]],
words_regex: re.Pattern = NON_INCLUSIVE_WORDS_REGEX,
check_path: bool = True,
root: Path | None = None,
):
"""Check one file for non-inclusive language.
Expand All @@ -118,6 +119,7 @@ def check_file(
words_regex: Pattern of non-inclusive terms.
check_path: Whether to check the path instead of just the contents.
(Used for testing.)
root: Path to add as a prefix to path.
"""
if check_path:
match = words_regex.search(str(path))
Expand All @@ -129,6 +131,9 @@ def check_file(
return

try:
if root:
path = root / path

with open(path, 'r') as ins:
enabled = True
prev = ''
Expand Down Expand Up @@ -174,7 +179,12 @@ def presubmit_check(
ctx.paths = presubmit_context.apply_exclusions(ctx)

for path in ctx.paths:
check_file(path.relative_to(ctx.root), found_words, words_regex)
check_file(
path.relative_to(ctx.root),
found_words,
words_regex,
root=ctx.root,
)

if found_words:
with open(ctx.failure_summary_log, 'w') as outs:
Expand Down

0 comments on commit 61f8b7e

Please sign in to comment.