From 92d35d3a210ac169eff10bc1a53ff015b4aaf743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 6 Apr 2022 13:58:25 +0200 Subject: [PATCH] gidocgen: Use tomli instead of the deprecated toml package Use the modern `tomli` library to read TOML files, rather than the unmaintained `toml` package. The former package is used by a growing number of packages in the Python ecosystem and has been selected as the base for Python 3.11's `tomllib` module, while the latter has not seen a release since Nov 2020 and does not adhere to the TOML 1.0 standard. --- .gitlab-ci.yml | 4 ++-- gidocgen/config.py | 12 +++++++----- meson.build | 2 +- pyproject.toml | 2 +- setup.cfg | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dc1159c..5cd7a69 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,7 @@ stages: # stage: build # needs: [] # script: -# - dnf install -y meson ninja-build pytest python3-flake8 python3-mypy python3-markdown python3-jinja2 python3-toml python3-typogrify +# - dnf install -y meson ninja-build pytest python3-flake8 python3-mypy python3-markdown python3-jinja2 python3-tomli python3-typogrify # - meson _build . # - meson test -C _build # @@ -31,7 +31,7 @@ pytest: stage: check needs: [] script: - - dnf install -y pytest python3-markdown python3-jinja2 python3-pygments python3-toml python3-typogrify + - dnf install -y pytest python3-markdown python3-jinja2 python3-pygments python3-tomli python3-typogrify - pytest --verbose flake8: diff --git a/gidocgen/config.py b/gidocgen/config.py index 1e00316..82f8211 100644 --- a/gidocgen/config.py +++ b/gidocgen/config.py @@ -3,7 +3,7 @@ import os import re -import toml +import tomli from urllib.parse import urljoin @@ -19,8 +19,9 @@ class GIDocConfig: if self._config_file is not None: try: log.debug(f"Reading configuration file: {self._config_file}") - self._config = toml.load(self._config_file) - except toml.TomlDecodeError as err: + with open(self._config_file, "rb") as f: + self._config = tomli.load(f) + except tomli.TOMLDecodeError as err: log.error(f"Invalid configuration file: {self._config_file}: {err}") @property @@ -219,8 +220,9 @@ class GITemplateConfig: self._config = {} try: log.debug(f"Reading template configuration file: {self._config_file}") - self._config = toml.load(self._config_file) - except toml.TomlDecodeError as err: + with open(self._config_file, "rb") as f: + self._config = tomli.load(f) + except tomli.TOMLDecodeError as err: log.error(f"Invalid template configuration file: {self._config_file}: {err}") @property diff --git a/meson.build b/meson.build index 7df5536..7584259 100644 --- a/meson.build +++ b/meson.build @@ -13,7 +13,7 @@ py = import('python').find_installation('python3', 'markdown', 'markupsafe', 'pygments', - 'toml', + 'tomli', 'typogrify', ], ) diff --git a/pyproject.toml b/pyproject.toml index e3dedbf..d2a6baf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ Markdown = "^3" MarkupSafe = "^1" Pygments = "^2" Jinja2 = "^2" -toml = "^0" +tomli = ">=1,<3" typogrify = "^2" [tool.poetry.dev-dependencies] diff --git a/setup.cfg b/setup.cfg index 7b1955e..e9563a4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -52,7 +52,7 @@ install_requires = MarkupSafe Pygments jinja2 - toml + tomli typogrify [options.entry_points] -- GitLab