Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toml: move from toml to tomllib + tomli_w #395

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions dotdrop/cfg_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions dotdrop/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import itertools
import shutil
import json
import sys
import requests
from packaging import version

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/arch-dotdrop-git/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/arch-dotdrop/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'
6 changes: 3 additions & 3 deletions scripts/yaml_to_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down