From 5e60a1dc86f9d1a7e54ac5e56f2b9c81558e0224 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Wed, 29 Dec 2021 16:36:23 +0800 Subject: [PATCH] replace the toml library with tomli --- .github/workflows/mypy.yaml | 2 +- .github/workflows/tests.yaml | 2 +- README.rst | 2 +- docs/requirements.txt | 2 +- docs/usage.rst | 4 ++-- nvchecker/core.py | 7 ++++--- nvchecker/util.py | 8 ++++---- setup.py | 2 +- tests/conftest.py | 8 ++++---- tests/test_archpkg.py | 2 +- 10 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.github/workflows/mypy.yaml b/.github/workflows/mypy.yaml index 048a65c..43ab1d4 100644 --- a/.github/workflows/mypy.yaml +++ b/.github/workflows/mypy.yaml @@ -18,7 +18,7 @@ jobs: ${{ runner.os }}-${{ env.cache-name }}- ${{ runner.os }}-cache-pip- - 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 run: PATH=$HOME/.local/bin:$PATH mypy nvchecker nvchecker_source tests continue-on-error: true diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 85e7d50..97304a1 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -44,7 +44,7 @@ jobs: sudo apt update sudo apt install -y libcurl4-openssl-dev - 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 env: KEY: ${{ secrets.KEY }} diff --git a/README.rst b/README.rst index 5d3ee10..4ce6ee3 100644 --- a/README.rst +++ b/README.rst @@ -24,7 +24,7 @@ This is the version 2.0 branch. For the old version 1.x, please switch to the `` Dependency ---------- - Python 3.7+ -- Python library: structlog, toml, appdirs +- Python library: structlog, tomli, appdirs - One of these Python library combinations (ordered by preference): * tornado + pycurl diff --git a/docs/requirements.txt b/docs/requirements.txt index a68922a..b1552e9 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,4 +1,4 @@ -toml +tomli structlog appdirs tornado>=6 diff --git a/docs/usage.rst b/docs/usage.rst index ef471c0..52f7536 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -18,7 +18,7 @@ This is the version 2.0 branch. For the old version 1.x, please switch to the `` Dependency ---------- - Python 3.7+ -- Python library: structlog, toml, appdirs +- Python library: structlog, tomli, appdirs - One of these Python library combinations (ordered by preference): * tornado + pycurl @@ -907,5 +907,5 @@ Extending It's possible to extend the supported sources by writing 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/ diff --git a/nvchecker/core.py b/nvchecker/core.py index 7fe9d5e..7ccd8fa 100644 --- a/nvchecker/core.py +++ b/nvchecker/core.py @@ -21,7 +21,7 @@ import contextvars import json import structlog -import toml +import tomli import appdirs from .lib import nicelogger @@ -156,8 +156,9 @@ def load_file( use_keymanager: bool, ) -> Tuple[Entries, Options]: try: - config = toml.load(file) - except (OSError, toml.TomlDecodeError) as e: + with open(file, 'rb') as f: + config = tomli.load(f) + except (OSError, tomli.TOMLDecodeError) as e: raise FileLoadError('version configuration file', file, e) ver_files: Optional[Tuple[Path, Path]] = None diff --git a/nvchecker/util.py b/nvchecker/util.py index 16d72c8..fb50750 100644 --- a/nvchecker/util.py +++ b/nvchecker/util.py @@ -14,7 +14,7 @@ from pathlib import Path import contextvars import abc -import toml +import tomli import structlog from .httpclient import session @@ -55,9 +55,9 @@ class KeyManager: ) -> None: if file is not None: try: - with file.open() as f: - keys = toml.load(f)['keys'] - except (OSError, toml.TomlDecodeError) as e: + with file.open('rb') as f: + keys = tomli.load(f)['keys'] + except (OSError, tomli.TOMLDecodeError) as e: raise FileLoadError('keyfile', str(file), e) else: keys = {} diff --git a/setup.py b/setup.py index 14c04a6..7848538 100755 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( zip_safe = True, 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 = { 'vercmp': ['pyalpm'], 'pypi': ['packaging'], diff --git a/tests/conftest.py b/tests/conftest.py index 1b0e2e0..d5031cc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,7 +6,7 @@ import structlog import os from pathlib import Path -import toml +import tomli import pytest from nvchecker import core @@ -52,7 +52,7 @@ async def get_version(): @pytest.fixture(scope="module") async def run_str(): async def __call__(str): - entries = toml.loads(str) + entries = tomli.loads(str) newvers = await run(entries) return newvers.popitem()[1] @@ -61,19 +61,19 @@ async def run_str(): @pytest.fixture(scope="module") async def run_str_multi(): async def __call__(str): - entries = toml.loads(str) + entries = tomli.loads(str) newvers = await run(entries) return newvers return __call__ +loop = asyncio.new_event_loop() @pytest.fixture(scope="session") def event_loop(request): """Override pytest-asyncio's event_loop fixture, 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. """ - loop = asyncio.get_event_loop() yield loop @pytest.fixture(scope="session", autouse=True) diff --git a/tests/test_archpkg.py b/tests/test_archpkg.py index 5f3d5ef..b15424e 100644 --- a/tests/test_archpkg.py +++ b/tests/test_archpkg.py @@ -31,5 +31,5 @@ async def test_archpkg_provided_strip(get_version): "source": "archpkg", "provided": "libjsoncpp.so", "strip_release": True, - }) == "24" + }) == "25"