MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / _migrate_map

Function _migrate_map

pre_commit/commands/migrate_config.py:25–46  ·  view source on GitHub ↗
(contents: str)

Source from the content-addressed store, hash-verified

23
24
25def _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
49def _preserve_style(n: ScalarNode, *, s: str) -> str:

Callers 1

migrate_configFunction · 0.85

Calls 1

_is_header_lineFunction · 0.85

Tested by

no test coverage detected