Skip to content

Commit

Permalink
Merge 953f72c into 586cc6c
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed May 22, 2021
2 parents 586cc6c + 953f72c commit d3abe92
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 75 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
# 0.15 (alpha)

- Removed `auto_load`/`auto_save` model options.
- Removed `INDENT_YAML_BLOCKS` setting.

# 0.14 (2021-05-21)

Expand Down
8 changes: 2 additions & 6 deletions datafiles/formats.py
Expand Up @@ -101,8 +101,7 @@ def serialize(cls, data):
yaml = YAML()
yaml.register_class(types.List)
yaml.register_class(types.Dict)
if settings.INDENT_YAML_BLOCKS:
yaml.indent(mapping=2, sequence=4, offset=2)
yaml.indent(mapping=2, sequence=4, offset=2)

stream = StringIO()
yaml.dump(data, stream)
Expand Down Expand Up @@ -138,10 +137,7 @@ def represent_none(self, _):

class Dumper(yaml.Dumper):
def increase_indent(self, flow=False, indentless=False):
return super().increase_indent(
flow=flow,
indentless=False if settings.INDENT_YAML_BLOCKS else indentless,
)
return super().increase_indent(flow=flow, indentless=False)

text = yaml.dump(data, Dumper=Dumper, sort_keys=False, default_flow_style=False)

Expand Down
2 changes: 0 additions & 2 deletions datafiles/settings.py
Expand Up @@ -4,8 +4,6 @@

HOOKS_ENABLED = True

INDENT_YAML_BLOCKS = True

MINIMIZE_LIST_DIFFS = True

YAML_LIBRARY = 'ruamel.yaml'
Expand Down
39 changes: 1 addition & 38 deletions datafiles/tests/test_formats.py
@@ -1,23 +1,12 @@
# pylint: disable=unused-variable

from pathlib import Path

import pytest

from datafiles import formats, settings
from datafiles import formats
from datafiles.utils import dedent


@pytest.fixture(autouse=True, scope='session')
def format_example():
path = Path.cwd() / 'docs' / 'settings.md'
example = path.read_text()
example = example.replace(" - 4", "- 4")
example = example.replace(" - 5", "- 5")
example = example.replace(" - 6", "- 6")
path.write_text(example)


def describe_serialize():
@pytest.fixture
def data():
Expand All @@ -36,19 +25,6 @@ def it_indents_blocks_by_default(expect, data):
"""
)

def it_can_render_lists_inline(expect, data, monkeypatch):
monkeypatch.setattr(settings, 'INDENT_YAML_BLOCKS', False)
text = formats.serialize(data, '.yaml')
expect(text) == dedent(
"""
key: value
items:
- 1
- a
-
"""
)

def describe_pyyaml():
def it_indents_blocks_by_default(expect, data):
text = formats.serialize(data, '.yaml', formatter=formats.PyYAML)
Expand All @@ -62,19 +38,6 @@ def it_indents_blocks_by_default(expect, data):
"""
)

def it_can_render_lists_inline(expect, data, monkeypatch):
monkeypatch.setattr(settings, 'INDENT_YAML_BLOCKS', False)
text = formats.serialize(data, '.yaml', formatter=formats.PyYAML)
expect(text) == dedent(
"""
key: value
items:
- 1
- a
-
"""
)


def describe_deserialize():
@pytest.fixture
Expand Down
28 changes: 0 additions & 28 deletions docs/settings.md
Expand Up @@ -25,34 +25,6 @@ def pytest_runtest_setup(item):
datafiles.settings.HOOKS_ENABLED = False
```

# `INDENT_YAML_BLOCKS`

In `datafiles >= 0.4`, YAML blocks are now indented by default, like so:

```yaml
items:
- 1
- 2
- 3
```

To make it easier to upgrade to this version, a client can disable this functionality:

```python
import datafiles

datafiles.settings.INDENT_YAML_BLOCKS = False
```

to produce YAML like:

```yaml
items:
- 4
- 5
- 6
```

# `MINIMIZE_LIST_DIFFS`

When serializing lists, `datafiles` intentionally deviates from the semantic representation of an empty list to optimize for the use case of storing YAML files in version control.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
@@ -1,7 +1,7 @@
[tool.poetry]

name = "datafiles"
version = "0.15a1"
version = "0.15a2"
description = "File-based ORM for dataclasses."

license = "MIT"
Expand Down

0 comments on commit d3abe92

Please sign in to comment.