replace the toml library with tomli

This commit is contained in:
lilydjwg 2021-12-29 16:36:23 +08:00
parent 8d4982d440
commit 5e60a1dc86
10 changed files with 20 additions and 19 deletions

View file

@ -18,7 +18,7 @@ jobs:
${{ runner.os }}-${{ env.cache-name }}- ${{ runner.os }}-${{ env.cache-name }}-
${{ runner.os }}-cache-pip- ${{ runner.os }}-cache-pip-
- name: Install deps - name: Install deps
run: pip3 install -U tornado pytest pytest-asyncio pytest-httpbin flaky structlog toml aiohttp httpx mypy run: pip3 install -U tornado pytest pytest-asyncio pytest-httpbin flaky structlog tomli aiohttp httpx mypy
- name: Run mypy for --install-types - name: Run mypy for --install-types
run: PATH=$HOME/.local/bin:$PATH mypy nvchecker nvchecker_source tests run: PATH=$HOME/.local/bin:$PATH mypy nvchecker nvchecker_source tests
continue-on-error: true continue-on-error: true

View file

@ -44,7 +44,7 @@ jobs:
sudo apt update sudo apt update
sudo apt install -y libcurl4-openssl-dev sudo apt install -y libcurl4-openssl-dev
- name: Install Python deps - name: Install Python deps
run: pip install -U ${{ matrix.deps }} pytest pytest-asyncio pytest-httpbin flaky structlog toml appdirs lxml run: pip install -U ${{ matrix.deps }} pytest pytest-asyncio pytest-httpbin flaky structlog tomli appdirs lxml
- name: Decrypt keys - name: Decrypt keys
env: env:
KEY: ${{ secrets.KEY }} KEY: ${{ secrets.KEY }}

View file

@ -24,7 +24,7 @@ This is the version 2.0 branch. For the old version 1.x, please switch to the ``
Dependency Dependency
---------- ----------
- Python 3.7+ - Python 3.7+
- Python library: structlog, toml, appdirs - Python library: structlog, tomli, appdirs
- One of these Python library combinations (ordered by preference): - One of these Python library combinations (ordered by preference):
* tornado + pycurl * tornado + pycurl

View file

@ -1,4 +1,4 @@
toml tomli
structlog structlog
appdirs appdirs
tornado>=6 tornado>=6

View file

@ -18,7 +18,7 @@ This is the version 2.0 branch. For the old version 1.x, please switch to the ``
Dependency Dependency
---------- ----------
- Python 3.7+ - Python 3.7+
- Python library: structlog, toml, appdirs - Python library: structlog, tomli, appdirs
- One of these Python library combinations (ordered by preference): - One of these Python library combinations (ordered by preference):
* tornado + pycurl * tornado + pycurl
@ -907,5 +907,5 @@ Extending
It's possible to extend the supported sources by writing It's possible to extend the supported sources by writing
plugins. See :doc:`plugin` for documentation. plugins. See :doc:`plugin` for documentation.
.. _Pacman: https://wiki.archlinux.org/index.php/Pacman .. _Pacman: https://wiki.archlinux.org/title/Pacman
.. _toml: https://toml.io/ .. _toml: https://toml.io/

View file

@ -21,7 +21,7 @@ import contextvars
import json import json
import structlog import structlog
import toml import tomli
import appdirs import appdirs
from .lib import nicelogger from .lib import nicelogger
@ -156,8 +156,9 @@ def load_file(
use_keymanager: bool, use_keymanager: bool,
) -> Tuple[Entries, Options]: ) -> Tuple[Entries, Options]:
try: try:
config = toml.load(file) with open(file, 'rb') as f:
except (OSError, toml.TomlDecodeError) as e: config = tomli.load(f)
except (OSError, tomli.TOMLDecodeError) as e:
raise FileLoadError('version configuration file', file, e) raise FileLoadError('version configuration file', file, e)
ver_files: Optional[Tuple[Path, Path]] = None ver_files: Optional[Tuple[Path, Path]] = None

View file

@ -14,7 +14,7 @@ from pathlib import Path
import contextvars import contextvars
import abc import abc
import toml import tomli
import structlog import structlog
from .httpclient import session from .httpclient import session
@ -55,9 +55,9 @@ class KeyManager:
) -> None: ) -> None:
if file is not None: if file is not None:
try: try:
with file.open() as f: with file.open('rb') as f:
keys = toml.load(f)['keys'] keys = tomli.load(f)['keys']
except (OSError, toml.TomlDecodeError) as e: except (OSError, tomli.TOMLDecodeError) as e:
raise FileLoadError('keyfile', str(file), e) raise FileLoadError('keyfile', str(file), e)
else: else:
keys = {} keys = {}

View file

@ -21,7 +21,7 @@ setup(
zip_safe = True, zip_safe = True,
packages = find_namespace_packages(exclude=['tests', 'build*', 'docs*']), packages = find_namespace_packages(exclude=['tests', 'build*', 'docs*']),
install_requires = ['setuptools; python_version<"3.8"', 'toml', 'structlog', 'appdirs', 'tornado>=6', 'pycurl'], install_requires = ['setuptools; python_version<"3.8"', 'tomli', 'structlog', 'appdirs', 'tornado>=6', 'pycurl'],
extras_require = { extras_require = {
'vercmp': ['pyalpm'], 'vercmp': ['pyalpm'],
'pypi': ['packaging'], 'pypi': ['packaging'],

View file

@ -6,7 +6,7 @@ import structlog
import os import os
from pathlib import Path from pathlib import Path
import toml import tomli
import pytest import pytest
from nvchecker import core from nvchecker import core
@ -52,7 +52,7 @@ async def get_version():
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
async def run_str(): async def run_str():
async def __call__(str): async def __call__(str):
entries = toml.loads(str) entries = tomli.loads(str)
newvers = await run(entries) newvers = await run(entries)
return newvers.popitem()[1] return newvers.popitem()[1]
@ -61,19 +61,19 @@ async def run_str():
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
async def run_str_multi(): async def run_str_multi():
async def __call__(str): async def __call__(str):
entries = toml.loads(str) entries = tomli.loads(str)
newvers = await run(entries) newvers = await run(entries)
return newvers return newvers
return __call__ return __call__
loop = asyncio.new_event_loop()
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def event_loop(request): def event_loop(request):
"""Override pytest-asyncio's event_loop fixture, """Override pytest-asyncio's event_loop fixture,
Don't create an instance of the default event loop for each test case. Don't create an instance of the default event loop for each test case.
We need the same ioloop across tests for the aiohttp support. We need the same ioloop across tests for the aiohttp support.
""" """
loop = asyncio.get_event_loop()
yield loop yield loop
@pytest.fixture(scope="session", autouse=True) @pytest.fixture(scope="session", autouse=True)

View file

@ -31,5 +31,5 @@ async def test_archpkg_provided_strip(get_version):
"source": "archpkg", "source": "archpkg",
"provided": "libjsoncpp.so", "provided": "libjsoncpp.so",
"strip_release": True, "strip_release": True,
}) == "24" }) == "25"