Skip to content

Commit d964d13

Browse files
committed
redo changes against current codebase, add tomli_w
1 parent 5a8e55d commit d964d13

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ classifiers = [
1818
dependencies = [
1919
"loguru>=0.7.3",
2020
"platformdirs>=4.3.8",
21-
"toml>=0.10.2",
21+
"tomli>=2.2.1 ; python_full_version < '3.11'",
22+
"tomli-w>=1.2.0",
2223
"typer>=0.15.4",
2324
"typing-extensions>=4.13.2",
2425
]

src/maison/parsers/pyproject.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"""A parser for pyproject.toml files."""
22

33
import pathlib
4+
import sys
45

5-
import toml
6+
if sys.version_info >= (3, 11):
7+
import tomllib
8+
else:
9+
import tomli as tomllib
610

711
from maison import typedefs
812

@@ -25,7 +29,8 @@ def __init__(self, package_name: str) -> None:
2529
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
2630
"""See the Parser.parse_config method."""
2731
try:
28-
pyproject_dict = dict(toml.load(file_path))
32+
with file_path.open(mode="rb") as fd:
33+
pyproject_dict = dict(tomllib.load(fd))
2934
except FileNotFoundError:
3035
return {}
3136
return dict(pyproject_dict.get("tool", {}).get(self._package_name, {}))

src/maison/parsers/toml.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"""A parser for .toml files."""
22

33
import pathlib
4+
import sys
45

5-
import toml
6+
if sys.version_info >= (3, 11):
7+
import tomllib
8+
else:
9+
import tomli as tomllib
610

711
from maison import typedefs
812

@@ -16,6 +20,7 @@ class TomlParser:
1620
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
1721
"""See the Parser.parse_config method."""
1822
try:
19-
return dict(toml.load(file_path))
23+
with file_path.open(mode="rb") as fd:
24+
return dict(tomllib.load(fd))
2025
except (FileNotFoundError, toml.TomlDecodeError):
2126
return {}

tests/unit_tests/conftest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from typing import Optional
77

88
import pytest
9-
import toml
10-
9+
import tomli_w
1110

1211
@pytest.fixture(name="create_tmp_file")
1312
def create_tmp_file_fixture(tmp_path: Path) -> Callable[..., Path]:
@@ -30,7 +29,7 @@ def _create_toml(
3029
content: Optional[dict[str, Any]] = None,
3130
) -> Path:
3231
content = content or {}
33-
config_toml = toml.dumps(content)
32+
config_toml = tomli_w.dumps(content)
3433
return create_tmp_file(content=config_toml, filename=filename)
3534

3635
return _create_toml

uv.lock

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)