From 0cba3d61d0c7e1b0adc6eecbe0ce3ed4775d4d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Sun, 21 May 2023 14:13:14 +0500 Subject: [PATCH] Switch from deprecated "toml" library Fixes #451 --- setup.py | 2 +- src/nanoemoji/config.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 66984bbf..5ac3067d 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ "picosvg>=0.20.4", "pillow>=7.2.0", "regex>=2020.4.4", - "toml>=0.10.1", + "tomlkit", "ufo2ft[cffsubr]>=2.24.0", "ufoLib2>=0.6.2", "resvg-cli>=0.22.0.post3", diff --git a/src/nanoemoji/config.py b/src/nanoemoji/config.py index 0d18c0d5..4f2d2f97 100644 --- a/src/nanoemoji/config.py +++ b/src/nanoemoji/config.py @@ -20,9 +20,9 @@ import importlib_resources as resources # pytype: disable=import-error import itertools +import tomlkit from pathlib import Path from picosvg.svg_transform import Affine2D -import toml from typing import Any, Iterable, MutableMapping, NamedTuple, Optional, Tuple, Sequence from nanoemoji import util @@ -288,7 +288,8 @@ def write(dest: Path, config: FontConfig): for m in config.masters }, } - dest.write_text(toml.dumps(toml_cfg)) + toml_cfg = {key: val for key, val in toml_cfg.items() if val is not None} + dest.write_text(tomlkit.dumps(toml_cfg)) def _resolve_config( @@ -297,8 +298,8 @@ def _resolve_config( if config_file is None: with resources.path("nanoemoji.data", _DEFAULT_CONFIG_FILE) as config_file: # no config_dir in this context; bad input if we need it - return None, toml.load(config_file) - return config_file.parent, toml.load(config_file) + return None, tomlkit.load(open(config_file)) + return config_file.parent, tomlkit.load(open(config_file)) def _resolve_src(relative_base: Optional[Path], src: str) -> Iterable[Path]: