@@ -120,13 +120,16 @@ def required_codeowners_list(
120
120
),
121
121
],
122
122
)
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
+ ]
130
133
131
134
132
135
def parse_codeowners_line (line : str , skip : int ) -> CodeownersLine | None :
@@ -164,7 +167,7 @@ def check_codeowners_line(
164
167
codeowners_line : CodeownersLine ,
165
168
found_files : list [tuple [RequiredCodeownersLine , tuple [int , int ]]],
166
169
) -> None :
167
- for required_codeowners_line in REQUIRED_CODEOWNERS_LINES :
170
+ for required_codeowners_line in required_codeowners_lines ( args ) :
168
171
if required_codeowners_line .file == codeowners_line .file .filename :
169
172
required_owners = [
170
173
required_owner (project_prefix = args .project_prefix )
@@ -229,7 +232,7 @@ def check_codeowners(linter: Linter, args: argparse.Namespace) -> None:
229
232
check_codeowners_line (linter , args , codeowners_line , found_files )
230
233
231
234
new_text = ""
232
- for required_codeowners_line in REQUIRED_CODEOWNERS_LINES :
235
+ for required_codeowners_line in required_codeowners_lines ( args ) :
233
236
if required_codeowners_line .file not in map (
234
237
lambda line : line [0 ].file , found_files
235
238
):
@@ -258,6 +261,36 @@ def main() -> None:
258
261
help = "project prefix to insert for project-specific team names" ,
259
262
required = True ,
260
263
)
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
+ )
261
294
with m .execute () as ctx :
262
295
ctx .add_check (check_codeowners )
263
296
0 commit comments