Performs a round-trip serialization. If text is not None, it is treated as a previous serialization that should be modified in-place. - If "defaults" is False, only options with non-default values are serialized. Default values in text are preserved. - Unknown options i
(
opts: OptManager, file: TextIO, text: str, defaults: bool = False
)
| 582 | |
| 583 | |
| 584 | def serialize( |
| 585 | opts: OptManager, file: TextIO, text: str, defaults: bool = False |
| 586 | ) -> None: |
| 587 | """ |
| 588 | Performs a round-trip serialization. If text is not None, it is |
| 589 | treated as a previous serialization that should be modified |
| 590 | in-place. |
| 591 | |
| 592 | - If "defaults" is False, only options with non-default values are |
| 593 | serialized. Default values in text are preserved. |
| 594 | - Unknown options in text are removed. |
| 595 | - Raises OptionsError if text is invalid. |
| 596 | """ |
| 597 | data = parse(text) |
| 598 | for k in opts.keys(): |
| 599 | if defaults or opts.has_changed(k): |
| 600 | data[k] = getattr(opts, k) |
| 601 | for k in list(data.keys()): |
| 602 | if k not in opts._options: |
| 603 | del data[k] |
| 604 | |
| 605 | ruamel.yaml.YAML().dump(data, file) |
| 606 | |
| 607 | |
| 608 | def save(opts: OptManager, path: Path | str, defaults: bool = False) -> None: |
no test coverage detected
searching dependent graphs…