Use tomllib from the standard library on Python 3.11+

This commit is contained in:
Miro Hrončok
2022-10-20 14:06:37 +02:00
committed by Karolina Surma
parent d7966cb29e
commit 737036a322
4 changed files with 16 additions and 8 deletions
+6 -2
View File
@@ -2,7 +2,11 @@ from importlib.resources import read_text
from textwrap import fill
import click
import tomli
try:
import tomllib
except ImportError:
import tomli as tomllib
from jinja2 import Template
@@ -22,7 +26,7 @@ class ConfigFile:
"""Return loaded TOML configuration file contents."""
with open(self.filename, "rb") as configuration_file:
loaded_contents = tomli.load(configuration_file)
loaded_contents = tomllib.load(configuration_file)
return loaded_contents
+1 -1
View File
@@ -1,6 +1,6 @@
click
jinja2
requests
tomli
tomli;python_version<"3.11"
tomli-w
packaging
+1 -1
View File
@@ -27,7 +27,7 @@ install_requires =
jinja2
packaging
requests
tomli
tomli;python_version<"3.11"
tomli-w
include_package_data = True
+8 -4
View File
@@ -5,7 +5,11 @@ to prevent loading from the internet on each request.
import betamax
import pytest
import tomli
try:
import tomllib
except ImportError:
import tomli as tomllib
from pyp2spec.pyp2conf import PypiPackage, create_config_contents
@@ -42,7 +46,7 @@ def test_automatically_generated_config_is_valid(betamax_parametrized_session, c
)
with open(f"tests/test_configs/default_python-{package}.conf", "rb") as config_file:
loaded_contents = tomli.load(config_file)
loaded_contents = tomllib.load(config_file)
assert config == loaded_contents
@@ -66,7 +70,7 @@ def test_config_with_customization_is_valid(betamax_session):
)
with open(f"tests/test_configs/customized_{package}.conf", "rb") as config_file:
loaded_contents = tomli.load(config_file)
loaded_contents = tomllib.load(config_file)
assert config == loaded_contents
@@ -85,7 +89,7 @@ def test_archful_package(betamax_session, changelog):
)
with open(f"tests/test_configs/customized_{package}.conf", "rb") as config_file:
loaded_contents = tomli.load(config_file)
loaded_contents = tomllib.load(config_file)
assert config["archful"] == loaded_contents["archful"]