Skip to content

Commit

Permalink
- use tomlkit for TOML read/write operations
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Oct 7, 2023
1 parent babc889 commit 0af837b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 153 deletions.
16 changes: 7 additions & 9 deletions config/config-package.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
from shared.git import get_commit_id
from shared.git import git_branch
from shared.path import change_dir
from shared.toml_encoder import TomlArraySeparatorEncoderWithNewline
import argparse
import collections
import jinja2
import pathlib
import shutil
import toml
import tomlkit


META_HINT = """\
Expand Down Expand Up @@ -166,7 +165,8 @@ def _read_meta_configuration(self):
"""Read and update meta configuration"""
meta_toml_path = self.path / '.meta.toml'
if meta_toml_path.exists():
meta_cfg = toml.load(meta_toml_path)
with open(meta_toml_path, 'rb') as meta_f:
meta_cfg = tomlkit.load(meta_f)
meta_cfg = collections.defaultdict(dict, **meta_cfg)
else:
meta_cfg = collections.defaultdict(dict)
Expand Down Expand Up @@ -274,7 +274,7 @@ def _set_python_config_value(self, name, default=False):
existing_value = self.meta_cfg['python'].get(key, default)
arg_value = getattr(self.args, key.replace('-', '_'))
new_value = existing_value or arg_value
self.meta_cfg['python'][key] = new_value
self.meta_cfg['python'][key] = new_value or default
return new_value

def _clean_up_old_settings(self):
Expand Down Expand Up @@ -622,12 +622,10 @@ def configure(self):
# Remove empty sections:
meta_cfg = {k: v for k, v in self.meta_cfg.items() if v}
with open('.meta.toml', 'w') as meta_f:
meta_f.write(META_HINT.format(config_type=self.config_type))
meta_f.write(
META_HINT.format(config_type=self.config_type))
meta_f.write('\n')
toml.dump(
meta_cfg, meta_f,
TomlArraySeparatorEncoderWithNewline(
separator=',\n ', indent_first_line=True))
tomlkit.dump(meta_cfg, meta_f)

tox_path = shutil.which('tox') or (
pathlib.Path(cwd) / 'bin' / 'tox')
Expand Down
6 changes: 4 additions & 2 deletions config/drop-legacy-python.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pathlib
import shutil
import sys
import toml
import tomlkit


parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -44,7 +44,8 @@
with change_dir(path) as cwd_str:
cwd = pathlib.Path(cwd_str)
bin_dir = cwd / 'bin'
meta_cfg = collections.defaultdict(dict, **toml.load('.meta.toml'))
with open('.meta.toml', 'rb') as meta_f:
meta_cfg = collections.defaultdict(dict, **tomlkit.load(meta_f))
config_type = meta_cfg['meta']['template']
branch_name = get_branch_name(args.branch_name, config_type)
updating = git_branch(branch_name)
Expand All @@ -70,6 +71,7 @@
'--no-push',
]
if args.interactive:
config_package_args.remove('--no-push')
config_package_args.append('--no-commit')
call(*config_package_args, cwd=cwd_str)
print('Remove `six` from the list of dependencies and other Py 2 things.')
Expand Down
102 changes: 0 additions & 102 deletions config/meta-cfg-to-toml.py

This file was deleted.

10 changes: 5 additions & 5 deletions config/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
check-python-versions==0.20.0
check-python-versions==0.21.3
Jinja2==3.1.2
pyupgrade==3.3.1
toml==0.10.2
tox==4.0.14
zest.releaser==7.2.0
pyupgrade==3.3.2
tomlkit==0.12.1
tox==4.8.0
zest.releaser==8.0.0
35 changes: 0 additions & 35 deletions config/shared/toml_encoder.py

This file was deleted.

0 comments on commit 0af837b

Please sign in to comment.