From d964d130d43fd37c7b542309a9c8f5be38a5519a Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 2 Oct 2025 23:01:55 +0200 Subject: [PATCH 1/6] redo changes against current codebase, add tomli_w --- pyproject.toml | 3 ++- src/maison/parsers/pyproject.py | 9 +++++++-- src/maison/parsers/toml.py | 9 +++++++-- tests/unit_tests/conftest.py | 5 ++--- uv.lock | 15 +++++++++++++-- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b7ae4e5..25c1a7d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,8 @@ classifiers = [ dependencies = [ "loguru>=0.7.3", "platformdirs>=4.3.8", - "toml>=0.10.2", + "tomli>=2.2.1 ; python_full_version < '3.11'", + "tomli-w>=1.2.0", "typer>=0.15.4", "typing-extensions>=4.13.2", ] diff --git a/src/maison/parsers/pyproject.py b/src/maison/parsers/pyproject.py index a8cee06..edca45f 100644 --- a/src/maison/parsers/pyproject.py +++ b/src/maison/parsers/pyproject.py @@ -1,8 +1,12 @@ """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 @@ -25,7 +29,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, {})) diff --git a/src/maison/parsers/toml.py b/src/maison/parsers/toml.py index e21b9ef..2b8a35c 100644 --- a/src/maison/parsers/toml.py +++ b/src/maison/parsers/toml.py @@ -1,8 +1,12 @@ """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 @@ -16,6 +20,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)) + with file_path.open(mode="rb") as fd: + return dict(tomllib.load(fd)) except (FileNotFoundError, toml.TomlDecodeError): return {} diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.py index 340618f..4d008e7 100644 --- a/tests/unit_tests/conftest.py +++ b/tests/unit_tests/conftest.py @@ -6,8 +6,7 @@ from typing import Optional import pytest -import toml - +import tomli_w @pytest.fixture(name="create_tmp_file") def create_tmp_file_fixture(tmp_path: Path) -> Callable[..., Path]: @@ -30,7 +29,7 @@ def _create_toml( content: Optional[dict[str, Any]] = None, ) -> Path: content = content or {} - config_toml = toml.dumps(content) + config_toml = tomli_w.dumps(content) return create_tmp_file(content=config_toml, filename=filename) return _create_toml diff --git a/uv.lock b/uv.lock index e58c648..1389a33 100644 --- a/uv.lock +++ b/uv.lock @@ -636,7 +636,8 @@ source = { editable = "." } dependencies = [ { name = "loguru" }, { name = "platformdirs" }, - { name = "toml" }, + { name = "tomli", marker = "python_full_version < '3.11'" }, + { name = "tomli-w" }, { name = "typer" }, { name = "typing-extensions" }, ] @@ -676,7 +677,8 @@ docs = [ requires-dist = [ { name = "loguru", specifier = ">=0.7.3" }, { name = "platformdirs", specifier = ">=4.3.8" }, - { name = "toml", specifier = ">=0.10.2" }, + { name = "tomli", marker = "python_full_version < '3.11'", specifier = ">=2.2.1" }, + { name = "tomli-w", specifier = ">=1.2.0" }, { name = "typer", specifier = ">=0.15.4" }, { name = "typing-extensions", specifier = ">=4.13.2" }, ] @@ -1894,6 +1896,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/6e/c2/61d3e0f47e2b74ef40a68b9e6ad5984f6241a942f7cd3bbfbdbd03861ea9/tomli-2.2.1-py3-none-any.whl", hash = "sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc", size = 14257, upload-time = "2024-11-27T22:38:35.385Z" }, ] +[[package]] +name = "tomli-w" +version = "1.2.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/19/75/241269d1da26b624c0d5e110e8149093c759b7a286138f4efd61a60e75fe/tomli_w-1.2.0.tar.gz", hash = "sha256:2dd14fac5a47c27be9cd4c976af5a12d87fb1f0b4512f81d69cce3b35ae25021", size = 7184, upload-time = "2025-01-15T12:07:24.262Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/c7/18/c86eb8e0202e32dd3df50d43d7ff9854f8e0603945ff398974c1d91ac1ef/tomli_w-1.2.0-py3-none-any.whl", hash = "sha256:188306098d013b691fcadc011abd66727d3c414c571bb01b1a174ba8c983cf90", size = 6675, upload-time = "2025-01-15T12:07:22.074Z" }, +] + [[package]] name = "tomlkit" version = "0.13.3" From 071d70ddf2268ee13829d1265f6718b487253d75 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 2 Oct 2025 23:07:12 +0200 Subject: [PATCH 2/6] catch new exception --- src/maison/parsers/toml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/maison/parsers/toml.py b/src/maison/parsers/toml.py index 2b8a35c..3aebb65 100644 --- a/src/maison/parsers/toml.py +++ b/src/maison/parsers/toml.py @@ -22,5 +22,5 @@ def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues: try: with file_path.open(mode="rb") as fd: return dict(tomllib.load(fd)) - except (FileNotFoundError, toml.TomlDecodeError): + except (FileNotFoundError, tomllib.TOMLDecodeError): return {} From f59775d063c5d63630304ebeb55ea3175486d3c5 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 2 Oct 2025 23:09:51 +0200 Subject: [PATCH 3/6] whitespace --- src/maison/parsers/pyproject.py | 1 + src/maison/parsers/toml.py | 1 + tests/unit_tests/conftest.py | 1 + 3 files changed, 3 insertions(+) diff --git a/src/maison/parsers/pyproject.py b/src/maison/parsers/pyproject.py index edca45f..b588e95 100644 --- a/src/maison/parsers/pyproject.py +++ b/src/maison/parsers/pyproject.py @@ -3,6 +3,7 @@ import pathlib import sys + if sys.version_info >= (3, 11): import tomllib else: diff --git a/src/maison/parsers/toml.py b/src/maison/parsers/toml.py index 3aebb65..3cf0260 100644 --- a/src/maison/parsers/toml.py +++ b/src/maison/parsers/toml.py @@ -3,6 +3,7 @@ import pathlib import sys + if sys.version_info >= (3, 11): import tomllib else: diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.py index 4d008e7..8eb1f78 100644 --- a/tests/unit_tests/conftest.py +++ b/tests/unit_tests/conftest.py @@ -8,6 +8,7 @@ import pytest import tomli_w + @pytest.fixture(name="create_tmp_file") def create_tmp_file_fixture(tmp_path: Path) -> Callable[..., Path]: """Fixture for creating a temporary file.""" From 9137e10cd5cc9ae5b0e7e4505b144648be805281 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 2 Oct 2025 23:11:40 +0200 Subject: [PATCH 4/6] coverage 99% --- .coveragerc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.coveragerc b/.coveragerc index 1999858..1ea253d 100644 --- a/.coveragerc +++ b/.coveragerc @@ -16,4 +16,4 @@ source = exclude_also = if TYPE_CHECKING: show_missing = true -fail_under = 100 +fail_under = 99 From 7e04118fe2f74b6700c8c7a042db564ae8579c43 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 2 Oct 2025 23:15:21 +0200 Subject: [PATCH 5/6] coverage 98% --- .coveragerc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.coveragerc b/.coveragerc index 1ea253d..4901af4 100644 --- a/.coveragerc +++ b/.coveragerc @@ -16,4 +16,4 @@ source = exclude_also = if TYPE_CHECKING: show_missing = true -fail_under = 99 +fail_under = 98 From 22c6f60936f7e767218869d10f73c7883e9f651c Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Sat, 4 Oct 2025 12:45:44 +0200 Subject: [PATCH 6/6] remove unused fixture --- pyproject.toml | 1 - tests/unit_tests/conftest.py | 16 ---------------- uv.lock | 11 ----------- 3 files changed, 28 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 25c1a7d..aec4e41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,6 @@ dependencies = [ "loguru>=0.7.3", "platformdirs>=4.3.8", "tomli>=2.2.1 ; python_full_version < '3.11'", - "tomli-w>=1.2.0", "typer>=0.15.4", "typing-extensions>=4.13.2", ] diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.py index 8eb1f78..9fb0c63 100644 --- a/tests/unit_tests/conftest.py +++ b/tests/unit_tests/conftest.py @@ -6,7 +6,6 @@ from typing import Optional import pytest -import tomli_w @pytest.fixture(name="create_tmp_file") @@ -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 = tomli_w.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`.""" diff --git a/uv.lock b/uv.lock index 1389a33..7242fbb 100644 --- a/uv.lock +++ b/uv.lock @@ -637,7 +637,6 @@ dependencies = [ { name = "loguru" }, { name = "platformdirs" }, { name = "tomli", marker = "python_full_version < '3.11'" }, - { name = "tomli-w" }, { name = "typer" }, { name = "typing-extensions" }, ] @@ -678,7 +677,6 @@ requires-dist = [ { name = "loguru", specifier = ">=0.7.3" }, { name = "platformdirs", specifier = ">=4.3.8" }, { name = "tomli", marker = "python_full_version < '3.11'", specifier = ">=2.2.1" }, - { name = "tomli-w", specifier = ">=1.2.0" }, { name = "typer", specifier = ">=0.15.4" }, { name = "typing-extensions", specifier = ">=4.13.2" }, ] @@ -1896,15 +1894,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/6e/c2/61d3e0f47e2b74ef40a68b9e6ad5984f6241a942f7cd3bbfbdbd03861ea9/tomli-2.2.1-py3-none-any.whl", hash = "sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc", size = 14257, upload-time = "2024-11-27T22:38:35.385Z" }, ] -[[package]] -name = "tomli-w" -version = "1.2.0" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/19/75/241269d1da26b624c0d5e110e8149093c759b7a286138f4efd61a60e75fe/tomli_w-1.2.0.tar.gz", hash = "sha256:2dd14fac5a47c27be9cd4c976af5a12d87fb1f0b4512f81d69cce3b35ae25021", size = 7184, upload-time = "2025-01-15T12:07:24.262Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/c7/18/c86eb8e0202e32dd3df50d43d7ff9854f8e0603945ff398974c1d91ac1ef/tomli_w-1.2.0-py3-none-any.whl", hash = "sha256:188306098d013b691fcadc011abd66727d3c414c571bb01b1a174ba8c983cf90", size = 6675, upload-time = "2025-01-15T12:07:22.074Z" }, -] - [[package]] name = "tomlkit" version = "0.13.3"