Skip to content

Commit

Permalink
Replace tomli with tomlkit for TOML parsing
Browse files Browse the repository at this point in the history
Remove tomli from dependencies as it is no longer needed, while
tomlkit was already used in other parts of the codebase.

Signed-off-by: Michal Šoltis <[email protected]>
  • Loading branch information
slimreaper35 committed Feb 4, 2025
1 parent 07ba171 commit aadba5b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 47 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gating.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
apt-get update && apt-get install --no-install-recommends --no-install-suggests -y git
python3 -m pip install --upgrade pip
pip install nox
pip install tomli
pip install tomlkit
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
apt-get update && apt-get install --no-install-recommends --no-install-suggests -y git
python3 -m pip install --upgrade pip
pip install nox
pip install tomli
pip install tomlkit
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
python3 -m venv /var/tmp/venv
/var/tmp/venv/bin/pip3 install --upgrade pip
/var/tmp/venv/bin/pip3 install nox
/var/tmp/venv/bin/pip3 install tomli
/var/tmp/venv/bin/pip3 install tomlkit
- name: add checkout action...
uses: actions/checkout@v4
Expand Down
12 changes: 6 additions & 6 deletions cachi2/core/package_managers/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
cast,
)

import tomli
import tomlkit
from packageurl import PackageURL

from cachi2.core.rooted_path import RootedPath
Expand Down Expand Up @@ -462,11 +462,11 @@ def get_version(self) -> Optional[str]:
@functools.cached_property
def _parsed_toml(self) -> dict[str, Any]:
try:
with open(self._setup_file, "rb") as f:
log.debug("Parsing pyproject.toml at %r", str(self._setup_file))
data = tomli.load(f)
return data
except tomli.TOMLDecodeError as e:
log.debug("Parsing pyproject.toml at %r", str(self._setup_file))
return tomlkit.parse(self._setup_file.path.read_text())
# no exceptions are exposed in the public API reference for tomlkit
# https://github.com/python-poetry/tomlkit/issues/399
except Exception as e:
log.error("Failed to parse pyproject.toml: %s", e)
return {}

Expand Down
5 changes: 3 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

import os
from pathlib import Path
from typing import Any

import nox
import tomli
import tomlkit
from nox.sessions import Session

# default sessions to run (sorted alphabetically)
Expand All @@ -39,7 +40,7 @@ def install_requirements(session: Session) -> None:
def parse_supported_python_versions() -> list[str]:
"""Parse supported Python versions from pyproject.toml."""
pyproject_path = Path("pyproject.toml")
pyproject = tomli.loads(pyproject_path.read_text())
pyproject: dict[str, Any] = tomlkit.parse(pyproject_path.read_text())
classifiers: list[str] = pyproject["project"]["classifiers"]

result = []
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ dependencies = [
"pyyaml",
"requests",
"semver",
"tomli",
"tomlkit",
"typer",
"createrepo-c",
Expand Down
1 change: 0 additions & 1 deletion requirements-extras.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,6 @@ tomli==2.2.1 \
--hash=sha256:f4039b9cbc3048b2416cc57ab3bda989a6fcf9b36cf8937f01a6e731b64f80d7
# via
# black
# cachi2 (pyproject.toml)
# coverage
# flake8-pyproject
# mypy
Expand Down
34 changes: 0 additions & 34 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -752,40 +752,6 @@ soupsieve==2.6 \
--hash=sha256:e2e68417777af359ec65daac1057404a3c8a5455bb8abc36f1a9866ab1a51abb \
--hash=sha256:e72c4ff06e4fb6e4b5a9f0f55fe6e81514581fca1515028625d0f299c602ccc9
# via beautifulsoup4
tomli==2.2.1 \
--hash=sha256:023aa114dd824ade0100497eb2318602af309e5a55595f76b626d6d9f3b7b0a6 \
--hash=sha256:02abe224de6ae62c19f090f68da4e27b10af2b93213d36cf44e6e1c5abd19fdd \
--hash=sha256:286f0ca2ffeeb5b9bd4fcc8d6c330534323ec51b2f52da063b11c502da16f30c \
--hash=sha256:2d0f2fdd22b02c6d81637a3c95f8cd77f995846af7414c5c4b8d0545afa1bc4b \
--hash=sha256:33580bccab0338d00994d7f16f4c4ec25b776af3ffaac1ed74e0b3fc95e885a8 \
--hash=sha256:400e720fe168c0f8521520190686ef8ef033fb19fc493da09779e592861b78c6 \
--hash=sha256:40741994320b232529c802f8bc86da4e1aa9f413db394617b9a256ae0f9a7f77 \
--hash=sha256:465af0e0875402f1d226519c9904f37254b3045fc5084697cefb9bdde1ff99ff \
--hash=sha256:4a8f6e44de52d5e6c657c9fe83b562f5f4256d8ebbfe4ff922c495620a7f6cea \
--hash=sha256:4e340144ad7ae1533cb897d406382b4b6fede8890a03738ff1683af800d54192 \
--hash=sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249 \
--hash=sha256:6972ca9c9cc9f0acaa56a8ca1ff51e7af152a9f87fb64623e31d5c83700080ee \
--hash=sha256:7fc04e92e1d624a4a63c76474610238576942d6b8950a2d7f908a340494e67e4 \
--hash=sha256:889f80ef92701b9dbb224e49ec87c645ce5df3fa2cc548664eb8a25e03127a98 \
--hash=sha256:8d57ca8095a641b8237d5b079147646153d22552f1c637fd3ba7f4b0b29167a8 \
--hash=sha256:8dd28b3e155b80f4d54beb40a441d366adcfe740969820caf156c019fb5c7ec4 \
--hash=sha256:9316dc65bed1684c9a98ee68759ceaed29d229e985297003e494aa825ebb0281 \
--hash=sha256:a198f10c4d1b1375d7687bc25294306e551bf1abfa4eace6650070a5c1ae2744 \
--hash=sha256:a38aa0308e754b0e3c67e344754dff64999ff9b513e691d0e786265c93583c69 \
--hash=sha256:a92ef1a44547e894e2a17d24e7557a5e85a9e1d0048b0b5e7541f76c5032cb13 \
--hash=sha256:ac065718db92ca818f8d6141b5f66369833d4a80a9d74435a268c52bdfa73140 \
--hash=sha256:b82ebccc8c8a36f2094e969560a1b836758481f3dc360ce9a3277c65f374285e \
--hash=sha256:c954d2250168d28797dd4e3ac5cf812a406cd5a92674ee4c8f123c889786aa8e \
--hash=sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc \
--hash=sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff \
--hash=sha256:d3f5614314d758649ab2ab3a62d4f2004c825922f9e370b29416484086b264ec \
--hash=sha256:d920f33822747519673ee656a4b6ac33e382eca9d331c87770faa3eef562aeb2 \
--hash=sha256:db2b95f9de79181805df90bedc5a5ab4c165e6ec3fe99f970d0e302f384ad222 \
--hash=sha256:e59e304978767a54663af13c07b3d1af22ddee3bb2fb0618ca1593e4f593a106 \
--hash=sha256:e85e99945e688e32d5a35c1ff38ed0b3f41f43fad8df0bdf79f72b2ba7bc5272 \
--hash=sha256:ece47d672db52ac607a3d9599a9d48dcb2f2f735c6c2d1f34130085bb12b112a \
--hash=sha256:f4039b9cbc3048b2416cc57ab3bda989a6fcf9b36cf8937f01a6e731b64f80d7
# via cachi2 (pyproject.toml)
tomlkit==0.13.2 \
--hash=sha256:7a974427f6e119197f670fbbbeae7bef749a6c14e793db934baefc1b5f03efde \
--hash=sha256:fff5fe59a87295b278abd31bec92c15d9bc4a06885ab12bcea52c71119392e79
Expand Down

0 comments on commit aadba5b

Please sign in to comment.