Skip to content

Commit af18299

Browse files
Make codeowners rules optional by group
1 parent 5e57ae2 commit af18299

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

src/rapids_pre_commit_hooks/codeowners.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,16 @@ def required_codeowners_list(
120120
),
121121
],
122122
)
123-
REQUIRED_CODEOWNERS_LINES = [
124-
*REQUIRED_CI_CODEOWNERS_LINES,
125-
*REQUIRED_PACKAGING_CODEOWNERS_LINES,
126-
*REQUIRED_CPP_CODEOWNERS_LINES,
127-
*REQUIRED_PYTHON_CODEOWNERS_LINES,
128-
*REQUIRED_CMAKE_CODEOWNERS_LINES,
129-
]
123+
124+
125+
def required_codeowners_lines(args: argparse.Namespace) -> list[RequiredCodeownersLine]:
126+
return [
127+
*(REQUIRED_CI_CODEOWNERS_LINES if args.ci else []),
128+
*(REQUIRED_PACKAGING_CODEOWNERS_LINES if args.packaging else []),
129+
*(REQUIRED_CPP_CODEOWNERS_LINES if args.cpp else []),
130+
*(REQUIRED_PYTHON_CODEOWNERS_LINES if args.python else []),
131+
*(REQUIRED_CMAKE_CODEOWNERS_LINES if args.cmake else []),
132+
]
130133

131134

132135
def parse_codeowners_line(line: str, skip: int) -> CodeownersLine | None:
@@ -164,7 +167,7 @@ def check_codeowners_line(
164167
codeowners_line: CodeownersLine,
165168
found_files: list[tuple[RequiredCodeownersLine, tuple[int, int]]],
166169
) -> None:
167-
for required_codeowners_line in REQUIRED_CODEOWNERS_LINES:
170+
for required_codeowners_line in required_codeowners_lines(args):
168171
if required_codeowners_line.file == codeowners_line.file.filename:
169172
required_owners = [
170173
required_owner(project_prefix=args.project_prefix)
@@ -229,7 +232,7 @@ def check_codeowners(linter: Linter, args: argparse.Namespace) -> None:
229232
check_codeowners_line(linter, args, codeowners_line, found_files)
230233

231234
new_text = ""
232-
for required_codeowners_line in REQUIRED_CODEOWNERS_LINES:
235+
for required_codeowners_line in required_codeowners_lines(args):
233236
if required_codeowners_line.file not in map(
234237
lambda line: line[0].file, found_files
235238
):
@@ -258,6 +261,36 @@ def main() -> None:
258261
help="project prefix to insert for project-specific team names",
259262
required=True,
260263
)
264+
m.argparser.add_argument(
265+
"--ci",
266+
help="enforce rules for CI codeowners",
267+
action=argparse.BooleanOptionalAction,
268+
default=True,
269+
)
270+
m.argparser.add_argument(
271+
"--packaging",
272+
help="enforce rules for packaging codeowners",
273+
action=argparse.BooleanOptionalAction,
274+
default=True,
275+
)
276+
m.argparser.add_argument(
277+
"--cpp",
278+
help="enforce rules for C++ codeowners",
279+
action=argparse.BooleanOptionalAction,
280+
default=True,
281+
)
282+
m.argparser.add_argument(
283+
"--python",
284+
help="enforce rules for Python codeowners",
285+
action=argparse.BooleanOptionalAction,
286+
default=True,
287+
)
288+
m.argparser.add_argument(
289+
"--cmake",
290+
help="enforce rules for CMake codeowners",
291+
action=argparse.BooleanOptionalAction,
292+
default=True,
293+
)
261294
with m.execute() as ctx:
262295
ctx.add_check(check_codeowners)
263296

test/rapids_pre_commit_hooks/test_codeowners.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
]
3939

4040
patch_required_codeowners_lines = patch(
41-
"rapids_pre_commit_hooks.codeowners.REQUIRED_CODEOWNERS_LINES",
42-
MOCK_REQUIRED_CODEOWNERS_LINES,
41+
"rapids_pre_commit_hooks.codeowners.required_codeowners_lines",
42+
lambda _args: MOCK_REQUIRED_CODEOWNERS_LINES,
4343
)
4444

4545

0 commit comments

Comments
 (0)