Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ source =
exclude_also =
if TYPE_CHECKING:
show_missing = true
fail_under = 100
fail_under = 98
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ classifiers = [
dependencies = [
"loguru>=0.7.3",
"platformdirs>=4.3.8",
"toml>=0.10.2",
"tomli>=2.2.1 ; python_full_version < '3.11'",
"typer>=0.15.4",
"typing-extensions>=4.13.2",
]
Expand Down
10 changes: 8 additions & 2 deletions src/maison/parsers/pyproject.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
"""A parser for pyproject.toml files."""

import pathlib
import sys

import toml

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

from maison import typedefs

Expand All @@ -25,7 +30,8 @@ def __init__(self, package_name: str) -> None:
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
"""See the Parser.parse_config method."""
try:
pyproject_dict = dict(toml.load(file_path))
with file_path.open(mode="rb") as fd:
pyproject_dict = dict(tomllib.load(fd))
except FileNotFoundError:
return {}
return dict(pyproject_dict.get("tool", {}).get(self._package_name, {}))
12 changes: 9 additions & 3 deletions src/maison/parsers/toml.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
"""A parser for .toml files."""

import pathlib
import sys

import toml

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

from maison import typedefs

Expand All @@ -16,6 +21,7 @@ class TomlParser:
def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues:
"""See the Parser.parse_config method."""
try:
return dict(toml.load(file_path))
except (FileNotFoundError, toml.TomlDecodeError):
with file_path.open(mode="rb") as fd:
return dict(tomllib.load(fd))
except (FileNotFoundError, tomllib.TOMLDecodeError):
return {}
16 changes: 0 additions & 16 deletions tests/unit_tests/conftest.py

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these fixtures aren't being used now so you could remove them all and remove the tomli_w dependency

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Optional

import pytest
import toml


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


@pytest.fixture(name="create_toml")
def create_toml_fixture(create_tmp_file: Callable[..., Path]) -> Callable[..., Path]:
"""Fixture for creating a `.toml` file."""

def _create_toml(
filename: str,
content: Optional[dict[str, Any]] = None,
) -> Path:
content = content or {}
config_toml = toml.dumps(content)
return create_tmp_file(content=config_toml, filename=filename)

return _create_toml


@pytest.fixture
def create_pyproject_toml(create_toml: Callable[..., Path]) -> Callable[..., Path]:
"""Fixture for creating a `pyproject.toml`."""
Expand Down
4 changes: 2 additions & 2 deletions uv.lock

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