From 4726d2a2f4b0cff1c000620f688bf52d9aec0585 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Mon, 28 Jul 2025 14:10:28 +0200 Subject: [PATCH] do not require old "tomli" on recent Python --- kalamine/layout.py | 8 ++++++-- pyproject.toml | 2 +- tests/util.py | 7 +++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/kalamine/layout.py b/kalamine/layout.py index 026bbe3..8064618 100644 --- a/kalamine/layout.py +++ b/kalamine/layout.py @@ -4,8 +4,12 @@ from pathlib import Path from typing import Dict, List, Optional, Set, Type, TypeVar +try: + import tomllib +except ImportError: + import tomli as tomllib + import click -import tomli import yaml from .utils import ( @@ -32,7 +36,7 @@ def load_descriptor(file_path: Path) -> Dict: return yaml.load(file, Loader=yaml.SafeLoader) with file_path.open(mode="rb") as dfile: - return tomli.load(dfile) + return tomllib.load(dfile) try: cfg = load_descriptor(layout_path) diff --git a/pyproject.toml b/pyproject.toml index 4bcbeff..ec14eee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ dependencies = [ "click>=8.0", "livereload", "pyyaml", - "tomli", + "tomli;python_version<'3.11'", "progress", ] diff --git a/tests/util.py b/tests/util.py index c4b35f2..4cf3fb7 100644 --- a/tests/util.py +++ b/tests/util.py @@ -3,7 +3,10 @@ from pathlib import Path from typing import Dict -import tomli +try: + import tomllib +except ImportError: + import tomli as tomllib def get_layout_dict(filename: str) -> Dict: @@ -11,4 +14,4 @@ def get_layout_dict(filename: str) -> Dict: file_path = Path(__file__).parent.parent / f"layouts/{filename}.toml" with file_path.open(mode="rb") as file: - return tomli.load(file) + return tomllib.load(file)