Skip to content

Commit

Permalink
Use modern tomllib/tomli modules for reading TOML files
Browse files Browse the repository at this point in the history
Replace the unmaintained `toml`/`pytoml` dependencies with the modern
alternatives: the built-in `tomllib` module in Python 3.11, and `tomli`
in older Python versions.  Preserving backwards compatibility does not
seem necessary, as podman-py no longer supports Python versions older
than 3.6.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
  • Loading branch information
mgorny committed Nov 3, 2022
1 parent 5420ae5 commit c5a356f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
16 changes: 10 additions & 6 deletions podman/domain/config.py
@@ -1,17 +1,21 @@
"""Read containers.conf file."""
import sys
import urllib
from pathlib import Path
from typing import Dict, Optional

import xdg.BaseDirectory

try:
import toml
except ImportError:
import pytoml as toml

from podman.api import cached_property

if sys.version_info >= (3, 11):
from tomllib import loads as toml_loads
else:
try:
from tomli import loads as toml_loads
except ImportError:
from toml import loads as toml_loads


class ServiceConnection:
"""ServiceConnection defines a connection to the Podman service."""
Expand Down Expand Up @@ -64,7 +68,7 @@ def __init__(self, path: Optional[str] = None):
if self.path.exists():
with self.path.open(encoding='utf-8') as file:
buffer = file.read()
self.attrs = toml.loads(buffer)
self.attrs = toml_loads(buffer)

def __hash__(self) -> int:
return hash(tuple(self.path.name))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -25,7 +25,7 @@ requires = [
"requests>=2.24",
"setuptools>=46.4",
"sphinx",
"toml>=0.10.2",
"tomli>=1.2.3; python_version<'3.11'",
"urllib3>=1.26.5",
"wheel",
]
Expand Down
8 changes: 4 additions & 4 deletions python-podman.spec.rpkg
Expand Up @@ -49,19 +49,19 @@ Source: {{{ git_dir_pack }}}
BuildRequires: git-core
BuildRequires: python%{python3_pkgversion}-devel
%if %{?old_rhel}
BuildRequires: python%{python3_pkgversion}-pytoml
BuildRequires: python%{python3_pkgversion}-pyxdg
BuildRequires: python%{python3_pkgversion}-requests
BuildRequires: python%{python3_pkgversion}-setuptools
Requires: python%{python3_pkgversion}-pytoml
BuildRequires: python%{python3_pkgversion}-toml
Requires: python%{python3_pkgversion}-pyxdg
Requires: python%{python3_pkgversion}-requests
Requires: python%{python3_pkgversion}-toml
%else
BuildRequires: pyproject-rpm-macros
%endif
%if 0%{?fedora} <= 35 && ! 0%{?rhel}
BuildRequires: python%{python3_pkgversion}-toml
Requires: python%{python3_pkgversion}-toml
BuildRequires: python%{python3_pkgversion}-tomli
Requires: python%{python3_pkgversion}-tomli
%endif
Provides: %{pypi_name}-py = %{version}-%{release}
Summary: %{summary}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -3,6 +3,6 @@ pyxdg>=0.26
requests>=2.24
setuptools
sphinx
toml>=0.10.2
tomli>=1.2.3; python_version<'3.11'
urllib3>=1.26.5
wheel
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -36,7 +36,7 @@ test_suite =
install_requires =
pyxdg >=0.26
requests >=2.24
toml >=0.10.2
tomli>=1.2.3; python_version<'3.11'
urllib3 >=1.26.5

# typing_extensions are included for RHEL 8.5
Expand Down

0 comments on commit c5a356f

Please sign in to comment.