mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-09 00:14:16 +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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user