(contents: str)
| 23 | |
| 24 | |
| 25 | def _migrate_map(contents: str) -> str: |
| 26 | if isinstance(yaml_load(contents), list): |
| 27 | # Find the first non-header line |
| 28 | lines = contents.splitlines(True) |
| 29 | i = 0 |
| 30 | # Only loop on non empty configuration file |
| 31 | while i < len(lines) and _is_header_line(lines[i]): |
| 32 | i += 1 |
| 33 | |
| 34 | header = ''.join(lines[:i]) |
| 35 | rest = ''.join(lines[i:]) |
| 36 | |
| 37 | # If they are using the "default" flow style of yaml, this operation |
| 38 | # will yield a valid configuration |
| 39 | try: |
| 40 | trial_contents = f'{header}repos:\n{rest}' |
| 41 | yaml_load(trial_contents) |
| 42 | contents = trial_contents |
| 43 | except yaml.YAMLError: |
| 44 | contents = f'{header}repos:\n{textwrap.indent(rest, " " * 4)}' |
| 45 | |
| 46 | return contents |
| 47 | |
| 48 | |
| 49 | def _preserve_style(n: ScalarNode, *, s: str) -> str: |
no test coverage detected