dev-python/pylama: Port to tomllib/tomli

Signed-off-by: Michał Górny <mgorny@gentoo.org>
This commit is contained in:
Michał Górny
2023-01-26 15:32:54 +01:00
parent ba35113118
commit aa8da0c8d8
2 changed files with 84 additions and 3 deletions

View File

@@ -0,0 +1,69 @@
From 8b7908fec960a05af0a0a9b10d24ed458fcf97c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
Date: Tue, 8 Nov 2022 14:33:59 +0100
Subject: [PATCH] Use tomli/tomllib instead of the unmaintained toml package
Replace the use of the unmaintained `toml` package with the modern
alternatives: the built-in `tomllib` in Python 3.11+, and its equivalent
`tomli` in older Python versions. `tomli` installs type stubs, so there
is no need for an additional `types-*` package for it.
---
pylama/config_toml.py | 9 +++++++--
requirements/requirements-tests.txt | 3 +--
setup.py | 2 +-
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/pylama/config_toml.py b/pylama/config_toml.py
index 2af02a5..ea6e17a 100644
--- a/pylama/config_toml.py
+++ b/pylama/config_toml.py
@@ -1,16 +1,21 @@
"""Pylama TOML configuration."""
-import toml
+import sys
from pylama.libs.inirama import Namespace as _Namespace
+if sys.version_info >= (3, 11):
+ import tomllib
+else:
+ import tomli as tomllib
+
class Namespace(_Namespace):
"""Inirama-style wrapper for TOML config."""
def parse(self, source: str, update: bool = True, **params):
"""Parse TOML source as string."""
- content = toml.loads(source)
+ content = tomllib.loads(source)
tool = content.get("tool", {})
pylama = tool.get("pylama", {})
linters = pylama.pop("linter", {})
diff --git a/requirements/requirements-tests.txt b/requirements/requirements-tests.txt
index d786f1f..e62ccae 100644
--- a/requirements/requirements-tests.txt
+++ b/requirements/requirements-tests.txt
@@ -5,8 +5,7 @@ radon >= 5.1.0
mypy
pylint >= 2.11.1
pylama-quotes
-toml
+tomli >= 1.2.3 ; python_version < "3.11"
vulture
types-setuptools
-types-toml
diff --git a/setup.py b/setup.py
index 911aea6..6d0222b 100644
--- a/setup.py
+++ b/setup.py
@@ -21,6 +21,6 @@ def parse_requirements(path: str) -> "list[str]":
extras_require=dict(
tests=parse_requirements("requirements/requirements-tests.txt"),
all=OPTIONAL_LINTERS, **{linter: [linter] for linter in OPTIONAL_LINTERS},
- toml="toml>=0.10.2",
+ toml="tomli>=1.2.3; python_version < '3.11'",
),
)

View File

@@ -9,8 +9,14 @@ PYTHON_COMPAT=( python3_{9..11} )
inherit distutils-r1
DESCRIPTION="Code audit tool for python"
HOMEPAGE="https://github.com/klen/pylama"
SRC_URI="https://github.com/klen/pylama/archive/${PV}.tar.gz -> ${P}.gh.tar.gz"
HOMEPAGE="
https://github.com/klen/pylama/
https://pypi.org/project/pylama/
"
SRC_URI="
https://github.com/klen/pylama/archive/${PV}.tar.gz
-> ${P}.gh.tar.gz
"
LICENSE="MIT"
SLOT="0"
@@ -28,13 +34,19 @@ BDEPEND="
dev-python/mypy[${PYTHON_USEDEP}]
dev-python/pylint[${PYTHON_USEDEP}]
dev-python/radon[${PYTHON_USEDEP}]
dev-python/toml[${PYTHON_USEDEP}]
dev-vcs/git
$(python_gen_cond_dep '
dev-python/tomli[${PYTHON_USEDEP}]
' 3.{8..10})
)
"
distutils_enable_tests pytest
PATCHES=(
"${FILESDIR}"/${P}-tomli.patch
)
EPYTEST_DESELECT=(
# not packaged
tests/test_linters.py::test_quotes