Skip to content

Commit

Permalink
feat(toml): switch to tomlkit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Pajot authored and gpajot committed Apr 4, 2023
1 parent 0355c6a commit bc2da7f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 46 deletions.
66 changes: 33 additions & 33 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ python = ">=3.8"

PyYAML = { version = ">=6,<7", optional = true }

tomli = { version = ">=2,<3", optional = true }
tomli-w = { version = ">=1,<2", optional = true }
tomlkit = { version = ">=0,<1", optional = true }

pydantic = { version = ">=1,<2", optional = true }

attrs = { version = ">=22.2,<23", optional = true }

[tool.poetry.extras]
yaml = ["PyYAML"]
toml = ["tomli", "tomli-w"]
toml = ["tomlkit"]
pydantic = ["pydantic"]
attrs = ["attrs"]

Expand Down
14 changes: 4 additions & 10 deletions zenconfig/formats/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@
from pathlib import Path
from typing import Any, Dict

import tomli
import tomli_w
import tomlkit

from zenconfig.base import BaseConfig, Format


@dataclass
class TOMLFormat(Format):
multiline_strings: bool = True
sort_keys: bool = False

def load(self, path: Path) -> Dict[str, Any]:
return tomli.loads(path.read_text())
return tomlkit.loads(path.read_text())

def dump(
self,
path: Path,
config: Dict[str, Any],
) -> None:
path.write_text(
tomli_w.dumps(
config,
multiline_strings=self.multiline_strings,
)
)
path.write_text(tomlkit.dumps(config, sort_keys=self.sort_keys))


BaseConfig.register_format(TOMLFormat(), ".toml")

0 comments on commit bc2da7f

Please sign in to comment.