duty 1.3.0__py3-none-any.whl → 1.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,721 @@
1
+ """Callable for [Coverage.py](https://github.com/nedbat/coveragepy)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Literal
6
+
7
+ from duty.tools._base import Tool
8
+
9
+
10
+ class coverage(Tool): # noqa: N801
11
+ """Call [Coverage.py](https://github.com/nedbat/coveragepy)."""
12
+
13
+ cli_name = "coverage"
14
+
15
+ @classmethod
16
+ def annotate(
17
+ cls,
18
+ *,
19
+ rcfile: str | None = None,
20
+ directory: str | None = None,
21
+ data_file: str | None = None,
22
+ ignore_errors: bool | None = None,
23
+ include: list[str] | None = None,
24
+ omit: list[str] | None = None,
25
+ debug_opts: list[str] | None = None,
26
+ ) -> coverage:
27
+ """Annotate source files with execution information.
28
+
29
+ Make annotated copies of the given files, marking statements that are executed
30
+ with `>` and statements that are missed with `!`.
31
+
32
+ Parameters:
33
+ rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
34
+ and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
35
+ directory: Write the output files to this directory.
36
+ data_file: Read coverage data for report generation from this file.
37
+ Defaults to `.coverage` [env: `COVERAGE_FILE`].
38
+ ignore_errors: Ignore errors while reading source files.
39
+ include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
40
+ omit: Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
41
+ debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
42
+ """
43
+ cli_args = ["annotate"]
44
+
45
+ if directory:
46
+ cli_args.append("--directory")
47
+ cli_args.append(directory)
48
+
49
+ if data_file:
50
+ cli_args.append("--data-file")
51
+ cli_args.append(data_file)
52
+
53
+ if ignore_errors:
54
+ cli_args.append("--ignore-errors")
55
+
56
+ if include:
57
+ cli_args.append("--include")
58
+ cli_args.append(",".join(include))
59
+
60
+ if omit:
61
+ cli_args.append("--omit")
62
+ cli_args.append(",".join(omit))
63
+
64
+ if debug_opts:
65
+ cli_args.append("--debug")
66
+ cli_args.append(",".join(debug_opts))
67
+
68
+ if rcfile:
69
+ cli_args.append("--rcfile")
70
+ cli_args.append(rcfile)
71
+
72
+ return cls(cli_args)
73
+
74
+ @classmethod
75
+ def combine(
76
+ cls,
77
+ *paths: str,
78
+ rcfile: str | None = None,
79
+ append: bool | None = None,
80
+ data_file: str | None = None,
81
+ keep: bool | None = None,
82
+ quiet: bool | None = None,
83
+ debug_opts: list[str] | None = None,
84
+ ) -> coverage:
85
+ """Combine a number of data files.
86
+
87
+ Combine data from multiple coverage files. The combined results are written to
88
+ a single file representing the union of the data. The positional arguments are
89
+ data files or directories containing data files. If no paths are provided,
90
+ data files in the default data file's directory are combined.
91
+
92
+ Parameters:
93
+ paths: Paths to combine.
94
+ rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
95
+ and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
96
+ append: Append coverage data to .coverage, otherwise it starts clean each time.
97
+ data_file: Read coverage data for report generation from this file.
98
+ Defaults to `.coverage` [env: `COVERAGE_FILE`].
99
+ keep: Keep original coverage files, otherwise they are deleted.
100
+ quiet: Don't print messages about what is happening.
101
+ debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
102
+ """
103
+ cli_args = ["combine", *paths]
104
+
105
+ if append:
106
+ cli_args.append("--append")
107
+
108
+ if data_file:
109
+ cli_args.append("--data-file")
110
+ cli_args.append(data_file)
111
+
112
+ if keep:
113
+ cli_args.append("--keep")
114
+
115
+ if quiet:
116
+ cli_args.append("--quiet")
117
+
118
+ if debug_opts:
119
+ cli_args.append("--debug")
120
+ cli_args.append(",".join(debug_opts))
121
+
122
+ if rcfile:
123
+ cli_args.append("--rcfile")
124
+ cli_args.append(rcfile)
125
+
126
+ return cls(cli_args)
127
+
128
+ @classmethod
129
+ def debug(
130
+ cls,
131
+ topic: Literal["data", "sys", "config", "premain", "pybehave"],
132
+ *,
133
+ rcfile: str | None = None,
134
+ debug_opts: list[str] | None = None,
135
+ ) -> coverage:
136
+ """Display information about the internals of coverage.py.
137
+
138
+ Display information about the internals of coverage.py, for diagnosing
139
+ problems. Topics are: `data` to show a summary of the collected data; `sys` to
140
+ show installation information; `config` to show the configuration; `premain`
141
+ to show what is calling coverage; `pybehave` to show internal flags describing
142
+ Python behavior.
143
+
144
+ Parameters:
145
+ topic: Topic to display.
146
+ rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
147
+ and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
148
+ debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
149
+ """
150
+ cli_args: list[str] = ["debug", topic]
151
+
152
+ if debug_opts:
153
+ cli_args.append("--debug")
154
+ cli_args.append(",".join(debug_opts))
155
+
156
+ if rcfile:
157
+ cli_args.append("--rcfile")
158
+ cli_args.append(rcfile)
159
+
160
+ return cls(cli_args)
161
+
162
+ @classmethod
163
+ def erase(
164
+ cls,
165
+ *,
166
+ rcfile: str | None = None,
167
+ data_file: str | None = None,
168
+ debug_opts: list[str] | None = None,
169
+ ) -> coverage:
170
+ """Erase previously collected coverage data.
171
+
172
+ Parameters:
173
+ rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
174
+ and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
175
+ data_file: Read coverage data for report generation from this file.
176
+ Defaults to `.coverage` [env: `COVERAGE_FILE`].
177
+ debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
178
+ """
179
+ cli_args = ["erase"]
180
+
181
+ if data_file:
182
+ cli_args.append("--data-file")
183
+ cli_args.append(data_file)
184
+
185
+ if debug_opts:
186
+ cli_args.append("--debug")
187
+ cli_args.append(",".join(debug_opts))
188
+
189
+ if rcfile:
190
+ cli_args.append("--rcfile")
191
+ cli_args.append(rcfile)
192
+
193
+ return cls(cli_args)
194
+
195
+ @classmethod
196
+ def html(
197
+ cls,
198
+ *,
199
+ rcfile: str | None = None,
200
+ contexts: list[str] | None = None,
201
+ directory: str | None = None,
202
+ data_file: str | None = None,
203
+ fail_under: int | None = None,
204
+ ignore_errors: bool | None = None,
205
+ include: list[str] | None = None,
206
+ omit: list[str] | None = None,
207
+ precision: int | None = None,
208
+ quiet: bool | None = None,
209
+ show_contexts: bool | None = None,
210
+ skip_covered: bool | None = None,
211
+ skip_empty: bool | None = None,
212
+ title: str | None = None,
213
+ debug_opts: list[str] | None = None,
214
+ ) -> coverage:
215
+ """Create an HTML report.
216
+
217
+ Create an HTML report of the coverage of the files. Each file gets its own
218
+ page, with the source decorated to show executed, excluded, and missed lines.
219
+
220
+ Parameters:
221
+ rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
222
+ and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
223
+ contexts: Only display data from lines covered in the given contexts.
224
+ Accepts Python regexes, which must be quoted.
225
+ directory: Write the output files to this directory.
226
+ data_file: Read coverage data for report generation from this file.
227
+ Defaults to `.coverage` [env: `COVERAGE_FILE`].
228
+ fail_under: Exit with a status of 2 if the total coverage is less than the given number.
229
+ ignore_errors: Ignore errors while reading source files.
230
+ include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
231
+ omit: Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
232
+ precision: Number of digits after the decimal point to display for reported coverage percentages.
233
+ quiet: Don't print messages about what is happening.
234
+ show_contexts: Show contexts for covered lines.
235
+ skip_covered: Skip files with 100% coverage.
236
+ skip_empty: Skip files with no code.
237
+ title: A text string to use as the title on the HTML.
238
+ debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
239
+ """
240
+ cli_args = ["html"]
241
+
242
+ if contexts:
243
+ cli_args.append("--contexts")
244
+ cli_args.append(",".join(contexts))
245
+
246
+ if directory:
247
+ cli_args.append("--directory")
248
+ cli_args.append(directory)
249
+
250
+ if data_file:
251
+ cli_args.append("--data-file")
252
+ cli_args.append(data_file)
253
+
254
+ if fail_under is not None:
255
+ cli_args.append("--fail-under")
256
+ cli_args.append(str(fail_under))
257
+
258
+ if ignore_errors:
259
+ cli_args.append("--ignore-errors")
260
+
261
+ if include:
262
+ cli_args.append("--include")
263
+ cli_args.append(",".join(include))
264
+
265
+ if omit:
266
+ cli_args.append("--omit")
267
+ cli_args.append(",".join(omit))
268
+
269
+ if precision is not None:
270
+ cli_args.append("--precision")
271
+ cli_args.append(str(precision))
272
+
273
+ if quiet:
274
+ cli_args.append("--quiet")
275
+
276
+ if show_contexts:
277
+ cli_args.append("--show-contexts")
278
+
279
+ if skip_covered is True:
280
+ cli_args.append("--skip-covered")
281
+ elif skip_covered is False:
282
+ cli_args.append("--no-skip-covered")
283
+
284
+ if skip_empty:
285
+ cli_args.append("--skip-empty")
286
+
287
+ if title:
288
+ cli_args.append("--title")
289
+ cli_args.append(title)
290
+
291
+ if debug_opts:
292
+ cli_args.append("--debug")
293
+ cli_args.append(",".join(debug_opts))
294
+
295
+ if rcfile:
296
+ cli_args.append("--rcfile")
297
+ cli_args.append(rcfile)
298
+
299
+ return cls(cli_args)
300
+
301
+ @classmethod
302
+ def json(
303
+ cls,
304
+ *,
305
+ rcfile: str | None = None,
306
+ contexts: list[str] | None = None,
307
+ data_file: str | None = None,
308
+ fail_under: int | None = None,
309
+ ignore_errors: bool | None = None,
310
+ include: list[str] | None = None,
311
+ omit: list[str] | None = None,
312
+ output: str | None = None,
313
+ pretty_print: bool | None = None,
314
+ quiet: bool | None = None,
315
+ show_contexts: bool | None = None,
316
+ debug_opts: list[str] | None = None,
317
+ ) -> coverage:
318
+ """Create a JSON report of coverage results.
319
+
320
+ Parameters:
321
+ rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
322
+ and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
323
+ contexts: Only display data from lines covered in the given contexts.
324
+ Accepts Python regexes, which must be quoted.
325
+ data_file: Read coverage data for report generation from this file.
326
+ Defaults to `.coverage` [env: `COVERAGE_FILE`].
327
+ fail_under: Exit with a status of 2 if the total coverage is less than the given number.
328
+ ignore_errors: Ignore errors while reading source files.
329
+ include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
330
+ omit: Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
331
+ output: Write the JSON report to this file. Defaults to `coverage.json`.
332
+ pretty_print: Format the JSON for human readers.
333
+ quiet: Don't print messages about what is happening.
334
+ show_contexts: Show contexts for covered lines.
335
+ debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
336
+ """
337
+ cli_args = ["json"]
338
+
339
+ if contexts:
340
+ cli_args.append("--contexts")
341
+ cli_args.append(",".join(contexts))
342
+
343
+ if data_file:
344
+ cli_args.append("--data-file")
345
+ cli_args.append(data_file)
346
+
347
+ if fail_under is not None:
348
+ cli_args.append("--fail-under")
349
+ cli_args.append(str(fail_under))
350
+
351
+ if ignore_errors:
352
+ cli_args.append("--ignore-errors")
353
+
354
+ if include:
355
+ cli_args.append("--include")
356
+ cli_args.append(",".join(include))
357
+
358
+ if omit:
359
+ cli_args.append("--omit")
360
+ cli_args.append(",".join(omit))
361
+
362
+ if output:
363
+ cli_args.append("-o")
364
+ cli_args.append(output)
365
+
366
+ if pretty_print:
367
+ cli_args.append("--pretty-print")
368
+
369
+ if quiet:
370
+ cli_args.append("--quiet")
371
+
372
+ if show_contexts:
373
+ cli_args.append("--show-contexts")
374
+
375
+ if debug_opts:
376
+ cli_args.append("--debug")
377
+ cli_args.append(",".join(debug_opts))
378
+
379
+ if rcfile:
380
+ cli_args.append("--rcfile")
381
+ cli_args.append(rcfile)
382
+
383
+ return cls(cli_args)
384
+
385
+ @classmethod
386
+ def lcov(
387
+ cls,
388
+ *,
389
+ rcfile: str | None = None,
390
+ data_file: str | None = None,
391
+ fail_under: int | None = None,
392
+ ignore_errors: bool | None = None,
393
+ include: list[str] | None = None,
394
+ omit: list[str] | None = None,
395
+ output: str | None = None,
396
+ quiet: bool | None = None,
397
+ debug_opts: list[str] | None = None,
398
+ ) -> coverage:
399
+ """Create an LCOV report of coverage results.
400
+
401
+ Parameters:
402
+ rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
403
+ and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
404
+ data_file: Read coverage data for report generation from this file.
405
+ Defaults to `.coverage` [env: `COVERAGE_FILE`].
406
+ fail_under: Exit with a status of 2 if the total coverage is less than the given number.
407
+ ignore_errors: Ignore errors while reading source files.
408
+ include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
409
+ omit: Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
410
+ output: Write the JSON report to this file. Defaults to `coverage.json`.
411
+ quiet: Don't print messages about what is happening.
412
+ debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
413
+ """
414
+ cli_args = ["lcov"]
415
+
416
+ if data_file:
417
+ cli_args.append("--data-file")
418
+ cli_args.append(data_file)
419
+
420
+ if fail_under is not None:
421
+ cli_args.append("--fail-under")
422
+ cli_args.append(str(fail_under))
423
+
424
+ if ignore_errors:
425
+ cli_args.append("--ignore-errors")
426
+
427
+ if include:
428
+ cli_args.append("--include")
429
+ cli_args.append(",".join(include))
430
+
431
+ if omit:
432
+ cli_args.append("--omit")
433
+ cli_args.append(",".join(omit))
434
+
435
+ if output:
436
+ cli_args.append("-o")
437
+ cli_args.append(output)
438
+
439
+ if quiet:
440
+ cli_args.append("--quiet")
441
+
442
+ if debug_opts:
443
+ cli_args.append("--debug")
444
+ cli_args.append(",".join(debug_opts))
445
+
446
+ if rcfile:
447
+ cli_args.append("--rcfile")
448
+ cli_args.append(rcfile)
449
+
450
+ return cls(cli_args)
451
+
452
+ @classmethod
453
+ def report(
454
+ cls,
455
+ *,
456
+ rcfile: str | None = None,
457
+ contexts: list[str] | None = None,
458
+ data_file: str | None = None,
459
+ fail_under: int | None = None,
460
+ output_format: Literal["text", "markdown", "total"] | None = None,
461
+ ignore_errors: bool | None = None,
462
+ include: list[str] | None = None,
463
+ omit: list[str] | None = None,
464
+ precision: int | None = None,
465
+ sort: Literal["name", "stmts", "miss", "branch", "brpart", "cover"] | None = None,
466
+ show_missing: bool | None = None,
467
+ skip_covered: bool | None = None,
468
+ skip_empty: bool | None = None,
469
+ debug_opts: list[str] | None = None,
470
+ ) -> coverage:
471
+ """Report coverage statistics on modules.
472
+
473
+ Parameters:
474
+ rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
475
+ and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
476
+ contexts: Only display data from lines covered in the given contexts.
477
+ data_file: Read coverage data for report generation from this file.
478
+ Defaults to `.coverage` [env: `COVERAGE_FILE`].
479
+ fail_under: Exit with a status of 2 if the total coverage is less than the given number.
480
+ output_format: Output format, either text (default), markdown, or total.
481
+ ignore_errors: Ignore errors while reading source files.
482
+ include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
483
+ omit: Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
484
+ precision: Number of digits after the decimal point to display for reported coverage percentages.
485
+ sort: Sort the report by the named column: name, stmts, miss, branch, brpart, or cover. Default is name.
486
+ show_missing: Show line numbers of statements in each module that weren't executed.
487
+ skip_covered: Skip files with 100% coverage.
488
+ skip_empty: Skip files with no code.
489
+ debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
490
+ """
491
+ cli_args = ["report"]
492
+
493
+ if contexts:
494
+ cli_args.append("--contexts")
495
+ cli_args.append(",".join(contexts))
496
+
497
+ if data_file:
498
+ cli_args.append("--data-file")
499
+ cli_args.append(data_file)
500
+
501
+ if fail_under is not None:
502
+ cli_args.append("--fail-under")
503
+ cli_args.append(str(fail_under))
504
+
505
+ if output_format:
506
+ cli_args.append("--format")
507
+ cli_args.append(output_format)
508
+
509
+ if ignore_errors:
510
+ cli_args.append("--ignore-errors")
511
+
512
+ if include:
513
+ cli_args.append("--include")
514
+ cli_args.append(",".join(include))
515
+
516
+ if omit:
517
+ cli_args.append("--omit")
518
+ cli_args.append(",".join(omit))
519
+
520
+ if precision is not None:
521
+ cli_args.append("--precision")
522
+ cli_args.append(str(precision))
523
+
524
+ if sort:
525
+ cli_args.append("--sort")
526
+ cli_args.append(sort)
527
+
528
+ if show_missing:
529
+ cli_args.append("--show-missing")
530
+
531
+ if skip_covered is True:
532
+ cli_args.append("--skip-covered")
533
+ elif skip_covered is False:
534
+ cli_args.append("--no-skip-covered")
535
+
536
+ if skip_empty:
537
+ cli_args.append("--skip-empty")
538
+
539
+ if debug_opts:
540
+ cli_args.append("--debug")
541
+ cli_args.append(",".join(debug_opts))
542
+
543
+ if rcfile:
544
+ cli_args.append("--rcfile")
545
+ cli_args.append(rcfile)
546
+
547
+ return cls(cli_args)
548
+
549
+ @classmethod
550
+ def run(
551
+ cls,
552
+ pyfile: str,
553
+ *,
554
+ rcfile: str | None = None,
555
+ append: bool | None = None,
556
+ branch: bool | None = None,
557
+ concurrency: list[str] | None = None,
558
+ context: str | None = None,
559
+ data_file: str | None = None,
560
+ include: list[str] | None = None,
561
+ omit: list[str] | None = None,
562
+ module: bool | None = None,
563
+ pylib: bool | None = None,
564
+ parallel_mode: bool | None = None,
565
+ source: list[str] | None = None,
566
+ timid: bool | None = None,
567
+ debug_opts: list[str] | None = None,
568
+ ) -> coverage:
569
+ """Run a Python program and measure code execution.
570
+
571
+ Parameters:
572
+ pyfile: Python script or module to run.
573
+ rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
574
+ and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
575
+ append: Append coverage data to .coverage, otherwise it starts clean each time.
576
+ branch: Measure branch coverage in addition to statement coverage.
577
+ concurrency: Properly measure code using a concurrency library. Valid values are:
578
+ eventlet, gevent, greenlet, multiprocessing, thread, or a comma-list of them.
579
+ context: The context label to record for this coverage run.
580
+ data_file: Read coverage data for report generation from this file.
581
+ Defaults to `.coverage` [env: `COVERAGE_FILE`].
582
+ include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
583
+ omit: Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
584
+ module: The given file is an importable Python module, not a script path, to be run as `python -m` would run it.
585
+ pylib: Measure coverage even inside the Python installed library, which isn't done by default.
586
+ parallel_mode: Append the machine name, process id and random number to the data file name
587
+ to simplify collecting data from many processes.
588
+ source: A list of directories or importable names of code to measure.
589
+ timid: Use a simpler but slower trace method. Try this if you get seemingly impossible results!
590
+ debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
591
+ """
592
+ cli_args = ["run", pyfile]
593
+
594
+ if append:
595
+ cli_args.append("--append")
596
+
597
+ if branch:
598
+ cli_args.append("--branch")
599
+
600
+ if concurrency:
601
+ cli_args.append("--concurrency")
602
+ cli_args.append(",".join(concurrency))
603
+
604
+ if context:
605
+ cli_args.append("--context")
606
+ cli_args.append(context)
607
+
608
+ if data_file:
609
+ cli_args.append("--data-file")
610
+ cli_args.append(data_file)
611
+
612
+ if include:
613
+ cli_args.append("--include")
614
+ cli_args.append(",".join(include))
615
+
616
+ if omit:
617
+ cli_args.append("--omit")
618
+ cli_args.append(",".join(omit))
619
+
620
+ if module:
621
+ cli_args.append("--module")
622
+
623
+ if pylib:
624
+ cli_args.append("--pylib")
625
+
626
+ if parallel_mode:
627
+ cli_args.append("--parallel-mode")
628
+
629
+ if source:
630
+ cli_args.append("--source")
631
+ cli_args.append(",".join(source))
632
+
633
+ if timid:
634
+ cli_args.append("--timid")
635
+
636
+ if debug_opts:
637
+ cli_args.append("--debug")
638
+ cli_args.append(",".join(debug_opts))
639
+
640
+ if rcfile:
641
+ cli_args.append("--rcfile")
642
+ cli_args.append(rcfile)
643
+
644
+ return cls(cli_args)
645
+
646
+ @classmethod
647
+ def xml(
648
+ cls,
649
+ *,
650
+ rcfile: str | None = None,
651
+ data_file: str | None = None,
652
+ fail_under: int | None = None,
653
+ ignore_errors: bool | None = None,
654
+ include: list[str] | None = None,
655
+ omit: list[str] | None = None,
656
+ output: str | None = None,
657
+ quiet: bool | None = None,
658
+ skip_empty: bool | None = None,
659
+ debug_opts: list[str] | None = None,
660
+ ) -> coverage:
661
+ """Create an XML report of coverage results.
662
+
663
+ Parameters:
664
+ rcfile: Specify configuration file. By default `.coveragerc`, `setup.cfg`, `tox.ini`,
665
+ and `pyproject.toml` are tried [env: `COVERAGE_RCFILE`].
666
+ data_file: Read coverage data for report generation from this file.
667
+ Defaults to `.coverage` [env: `COVERAGE_FILE`].
668
+ fail_under: Exit with a status of 2 if the total coverage is less than the given number.
669
+ ignore_errors: Ignore errors while reading source files.
670
+ include: Include only files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
671
+ omit: Omit files whose paths match one of these patterns. Accepts shell-style wildcards, which must be quoted.
672
+ output: Write the JSON report to this file. Defaults to `coverage.json`.
673
+ quiet: Don't print messages about what is happening.
674
+ skip_empty: Skip files with no code.
675
+ debug_opts: Debug options, separated by commas [env: `COVERAGE_DEBUG`].
676
+ """
677
+ cli_args = ["xml"]
678
+
679
+ if data_file:
680
+ cli_args.append("--data-file")
681
+ cli_args.append(data_file)
682
+
683
+ if fail_under is not None:
684
+ cli_args.append("--fail-under")
685
+ cli_args.append(str(fail_under))
686
+
687
+ if ignore_errors:
688
+ cli_args.append("--ignore-errors")
689
+
690
+ if include:
691
+ cli_args.append("--include")
692
+ cli_args.append(",".join(include))
693
+
694
+ if omit:
695
+ cli_args.append("--omit")
696
+ cli_args.append(",".join(omit))
697
+
698
+ if output:
699
+ cli_args.append("-o")
700
+ cli_args.append(output)
701
+
702
+ if quiet:
703
+ cli_args.append("--quiet")
704
+
705
+ if skip_empty:
706
+ cli_args.append("--skip-empty")
707
+
708
+ if debug_opts:
709
+ cli_args.append("--debug")
710
+ cli_args.append(",".join(debug_opts))
711
+
712
+ if rcfile:
713
+ cli_args.append("--rcfile")
714
+ cli_args.append(rcfile)
715
+
716
+ return cls(cli_args)
717
+
718
+ def __call__(self) -> int | None:
719
+ from coverage.cmdline import main as run_coverage
720
+
721
+ return run_coverage(self.cli_args)