Skip to content

Commit 772d7d4

Browse files
authored
Merge pull request #3324 from pre-commit/migrate-config-purelib
fix migrate-config for purelib yaml
2 parents 3d5548b + 222c62b commit 772d7d4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pre_commit/commands/migrate_config.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def _migrate_map(contents: str) -> str:
4747

4848

4949
def _preserve_style(n: ScalarNode, *, s: str) -> str:
50-
return f'{n.style}{s}{n.style}'
50+
style = n.style or ''
51+
return f'{style}{s}{style}'
5152

5253

5354
def _fix_stage(n: ScalarNode) -> str:

tests/commands/migrate_config_test.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
from __future__ import annotations
22

3+
from unittest import mock
4+
35
import pytest
6+
import yaml
47

58
import pre_commit.constants as C
69
from pre_commit.clientlib import InvalidConfigError
710
from pre_commit.commands.migrate_config import migrate_config
11+
from pre_commit.yaml import yaml_compose
12+
13+
14+
@pytest.fixture(autouse=True, params=['c', 'pure'])
15+
def switch_pyyaml_impl(request):
16+
if request.param == 'c':
17+
yield
18+
else:
19+
with mock.patch.dict(
20+
yaml_compose.keywords,
21+
{'Loader': yaml.SafeLoader},
22+
):
23+
yield
824

925

1026
def test_migrate_config_normal_format(tmpdir, capsys):

0 commit comments

Comments
 (0)