| 524 | |
| 525 | |
| 526 | def parse(text): |
| 527 | if not text: |
| 528 | return {} |
| 529 | try: |
| 530 | yaml = ruamel.yaml.YAML(typ="safe", pure=True) |
| 531 | data = yaml.load(text) |
| 532 | except ruamel.yaml.error.YAMLError as v: |
| 533 | if hasattr(v, "problem_mark"): |
| 534 | snip = v.problem_mark.get_snippet() |
| 535 | raise exceptions.OptionsError( |
| 536 | "Config error at line %s:\n%s\n%s" |
| 537 | % (v.problem_mark.line + 1, snip, getattr(v, "problem", "")) |
| 538 | ) |
| 539 | else: |
| 540 | raise exceptions.OptionsError("Could not parse options.") |
| 541 | if isinstance(data, str): |
| 542 | raise exceptions.OptionsError("Config error - no keys found.") |
| 543 | elif data is None: |
| 544 | return {} |
| 545 | return data |
| 546 | |
| 547 | |
| 548 | def load(opts: OptManager, text: str, cwd: Path | str | None = None) -> None: |