Skip to content

Commit 5ff5555

Browse files
committed
Use pydantic instead deserializer
1 parent bb899c5 commit 5ff5555

File tree

4 files changed

+89
-17
lines changed

4 files changed

+89
-17
lines changed

pdm.lock

+80-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies = [
77
"aiohttp<4.0.0,>=3.9.3",
88
"defusedxml>=0.7.1",
99
"watchfiles>=0.24.0",
10-
"deserializer @ git+https://github.com/arenekosreal/deserializer.git",
10+
"pydantic>=2.9.2",
1111
]
1212
name = "crx-repo"
1313
description = "Download Chrom(e|ium) extensions from Chrome Web Store and serve a update manifest."

src/crx_repo/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from crx_repo.config.parser import parse_config_async as _parse_config_async
2222

2323

24-
__version__ = "0.2.0"
24+
__version__ = "0.2.1"
2525

2626

2727
_logger = logging.getLogger(__name__)

src/crx_repo/config/parser/toml.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""ConfigParser implementation to parse toml config."""
22

33
import tomllib
4+
from typing import Any
45
from typing import override
56
from pathlib import Path
6-
from deserializer import deserialize
7+
from pydantic import TypeAdapter
78
from crx_repo.config.config import Config
89
from crx_repo.config.parser.parser import PathOrStr
910
from crx_repo.config.parser.parser import ConfigParser
@@ -18,10 +19,11 @@ async def parse_async(self, path: PathOrStr) -> Config:
1819
if path not in self._cache:
1920
content = path.read_text()
2021
config_raw = tomllib.loads(content)
21-
self._cache[path] = deserialize(
22-
Config, config_raw,
23-
lambda x: x.replace("-", "_").lower(), # Kebab case to snake case
24-
)
22+
t = TypeAdapter(Config)
23+
converted_config: dict[str, Any] = {}
24+
for key in config_raw:
25+
converted_config[key.replace("-", "_").lower()] = config_raw[key]
26+
self._cache[path] = t.validate_python(converted_config)
2527
return self._cache[path]
2628

2729
@override

0 commit comments

Comments
 (0)