Skip to content

Commit 8c7b842

Browse files
authored
Replace unmaintained toml library with tomli (#366)
1 parent 5a8e55d commit 8c7b842

File tree

6 files changed

+21
-25
lines changed

6 files changed

+21
-25
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ source =
1616
exclude_also =
1717
if TYPE_CHECKING:
1818
show_missing = true
19-
fail_under = 100
19+
fail_under = 98

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ 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'",
2222
"typer>=0.15.4",
2323
"typing-extensions>=4.13.2",
2424
]

src/maison/parsers/pyproject.py

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

33
import pathlib
4+
import sys
45

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

712
from maison import typedefs
813

@@ -25,7 +30,8 @@ def __init__(self, package_name: str) -> None:
2530
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
2631
"""See the Parser.parse_config method."""
2732
try:
28-
pyproject_dict = dict(toml.load(file_path))
33+
with file_path.open(mode="rb") as fd:
34+
pyproject_dict = dict(tomllib.load(fd))
2935
except FileNotFoundError:
3036
return {}
3137
return dict(pyproject_dict.get("tool", {}).get(self._package_name, {}))

src/maison/parsers/toml.py

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

33
import pathlib
4+
import sys
45

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

712
from maison import typedefs
813

@@ -16,6 +21,7 @@ class TomlParser:
1621
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
1722
"""See the Parser.parse_config method."""
1823
try:
19-
return dict(toml.load(file_path))
20-
except (FileNotFoundError, toml.TomlDecodeError):
24+
with file_path.open(mode="rb") as fd:
25+
return dict(tomllib.load(fd))
26+
except (FileNotFoundError, tomllib.TOMLDecodeError):
2127
return {}

tests/unit_tests/conftest.py

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

88
import pytest
9-
import toml
109

1110

1211
@pytest.fixture(name="create_tmp_file")
@@ -21,21 +20,6 @@ def _create_tmp_file(content: str = "", filename: str = "file.txt") -> Path:
2120
return _create_tmp_file
2221

2322

24-
@pytest.fixture(name="create_toml")
25-
def create_toml_fixture(create_tmp_file: Callable[..., Path]) -> Callable[..., Path]:
26-
"""Fixture for creating a `.toml` file."""
27-
28-
def _create_toml(
29-
filename: str,
30-
content: Optional[dict[str, Any]] = None,
31-
) -> Path:
32-
content = content or {}
33-
config_toml = toml.dumps(content)
34-
return create_tmp_file(content=config_toml, filename=filename)
35-
36-
return _create_toml
37-
38-
3923
@pytest.fixture
4024
def create_pyproject_toml(create_toml: Callable[..., Path]) -> Callable[..., Path]:
4125
"""Fixture for creating a `pyproject.toml`."""

uv.lock

Lines changed: 2 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)