diff --git a/dotdrop/cfg_yaml.py b/dotdrop/cfg_yaml.py index 984d32b87..27d821c31 100644 --- a/dotdrop/cfg_yaml.py +++ b/dotdrop/cfg_yaml.py @@ -26,7 +26,11 @@ 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 @@ def __toml_load(cls, path): """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 @@ def __yaml_dump(cls, content, file): @classmethod def __toml_dump(cls, content, file): """dump to toml""" - toml.dump(content, file) + file.write(tomli_w.dumps(content)) ######################################################## # templating diff --git a/dotdrop/utils.py b/dotdrop/utils.py index dc7998758..cee6422c8 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -16,6 +16,7 @@ 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 diff --git a/packages/arch-dotdrop-git/PKGBUILD b/packages/arch-dotdrop-git/PKGBUILD index 3a6c344a5..9d2eeaa82 100644 --- a/packages/arch-dotdrop-git/PKGBUILD +++ b/packages/arch-dotdrop-git/PKGBUILD @@ -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) diff --git a/packages/arch-dotdrop/PKGBUILD b/packages/arch-dotdrop/PKGBUILD index 4dfb4d104..eaa36b823 100644 --- a/packages/arch-dotdrop/PKGBUILD +++ b/packages/arch-dotdrop/PKGBUILD @@ -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') diff --git a/requirements.txt b/requirements.txt index ff4efcd3d..e7499555a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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' diff --git a/scripts/yaml_to_toml.py b/scripts/yaml_to_toml.py index fd351acd0..e9c112742 100755 --- a/scripts/yaml_to_toml.py +++ b/scripts/yaml_to_toml.py @@ -9,8 +9,8 @@ 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 diff --git a/setup.py b/setup.py index 3d272ad70..280a79b85 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,8 @@ def read_readme(readme_path): 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'],