1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 14:31:46 +00:00

toml: move from toml to tomllib + tomli_w

* toml is getting removed from distributions due to being generally
  unmaintained and not support the lastest TOML standard.
* For parsing use tomllib which is included in python3.11 and tomli for
  earlier interpeter versions.
* For writing use tomli-w. tomli-w.dump() expects bytes-like objects so
  work around it to keep compatability and minimize changes elsewhere.

Signed-off-by: Alfred Wingate <parona@protonmail.com>
This commit is contained in:
Alfred Wingate
2023-08-03 17:43:09 +03:00
committed by deadc0de
parent af5bcf4514
commit 56d5a86eb2
7 changed files with 31 additions and 14 deletions

View File

@@ -26,7 +26,11 @@ import io
from copy import deepcopy
from itertools import chain
from ruamel.yaml import YAML as yaml
import toml
try:
import tomllib
except ImportError:
import tomli as tomllib
import tomli_w
# local imports
from dotdrop.version import __version__ as VERSION
@@ -1345,7 +1349,7 @@ class CfgYaml:
"""load from toml"""
with open(path, 'r', encoding='utf8') as file:
data = file.read()
content = toml.loads(data)
content = tomllib.loads(data)
# handle inexistent dotfiles/profiles
# since toml doesn't have a nul/nil/null/none
if cls.key_dotfiles not in content:
@@ -1375,7 +1379,7 @@ class CfgYaml:
@classmethod
def __toml_dump(cls, content, file):
"""dump to toml"""
toml.dump(content, file)
file.write(tomli_w.dumps(content))
########################################################
# templating

View File

@@ -16,6 +16,7 @@ import filecmp
import itertools
import shutil
import json
import sys
import requests
from packaging import version
@@ -393,12 +394,22 @@ def dependencies_met():
except ImportError as exc:
raise UnmetDependency(err) from exc
# toml
name = 'toml'
# tomli
if sys.version_info < (3, 11):
name = 'tomli'
err = f'missing python module \"{name}\"'
try:
import tomli
assert tomli
except ImportError as exc:
raise UnmetDependency(err) from exc
# tomli_w
name = 'tomli_w'
err = f'missing python module \"{name}\"'
try:
import toml
assert toml
import tomli_w
assert tomli_w
except ImportError as exc:
raise UnmetDependency(err) from exc

View File

@@ -9,7 +9,7 @@ arch=('any')
url="https://github.com/deadc0de6/dotdrop"
license=('GPL')
groups=()
depends=('python' 'python-setuptools' 'python-jinja' 'python-docopt' 'python-ruamel-yaml' 'python-magic' 'python-requests' 'python-packaging' 'python-toml' 'python-distro')
depends=('python' 'python-setuptools' 'python-jinja' 'python-docopt' 'python-ruamel-yaml' 'python-magic' 'python-requests' 'python-packaging' 'python-tomli-w' 'python-distro')
makedepends=('git')
provides=(dotdrop)
conflicts=(dotdrop)

View File

@@ -8,7 +8,7 @@ arch=('any')
url="https://github.com/deadc0de6/dotdrop"
license=('GPL')
groups=()
depends=('python' 'python-setuptools' 'python-jinja' 'python-docopt' 'python-ruamel-yaml' 'python-magic' 'python-requests' 'python-packaging' 'python-toml' 'python-distro')
depends=('python' 'python-setuptools' 'python-jinja' 'python-docopt' 'python-ruamel-yaml' 'python-magic' 'python-requests' 'python-packaging' 'python-tomli-w' 'python-distro')
makedepends=('git')
source=("git+https://github.com/deadc0de6/dotdrop.git#tag=v${pkgver}")
md5sums=('SKIP')

3
requirements.txt vendored
View File

@@ -4,5 +4,6 @@ ruamel.yaml; python_version > '3.5'
python-magic; python_version > '3.5'
packaging; python_version > '3.5'
requests; python_version > '3.5'
toml; python_version > '3.5'
tomli; python_version > '3.5' and python_version < '3.11'
tomli_w; python_version > '3.5'
distro; python_version > '3.5'

View File

@@ -9,8 +9,8 @@ convert yaml config file to toml
import sys
# pip3 install ruamel.yaml
from ruamel.yaml import YAML as yaml
# pip3 install toml
import toml
# pip3 install tomli_w
import tomli_w
def yaml_load(path):
@@ -42,7 +42,7 @@ def replace_none(content):
def toml_dump(content):
"""dump toml to stdout"""
return toml.dumps(content)
return tomli_w.dumps(content)
# pylint: disable=C0103

View File

@@ -50,7 +50,8 @@ setup(
install_requires=[
'docopt', 'Jinja2', 'ruamel.yaml',
'python-magic', 'packaging', 'requests',
'toml', 'distro'],
'tomli; python_version < "3.11"',
'tomli_w', 'distro'],
extras_require={
'dev': ['check-manifest'],