Skip to content

Commit

Permalink
Use tomlkit for TOML read/write operations (#215)
Browse files Browse the repository at this point in the history
* small cleanups
* clean up argparse defaults

---------

Co-authored-by: Michael Howitz <[email protected]>
  • Loading branch information
dataflake and icemac authored Mar 22, 2024
1 parent 1351c95 commit f631b48
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 178 deletions.
17 changes: 7 additions & 10 deletions config/config-package.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,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 @@ -67,13 +66,13 @@ def handle_command_line_arguments():
'--no-flake8',
dest='use_flake8',
action='store_false',
default=None,
default=True,
help='Do not include flake8 and isort in the linting configuration.')
parser.add_argument(
'--with-appveyor',
dest='with_appveyor',
action='store_true',
default=None,
default=False,
help='Activate running tests on AppVeyor, too, '
'if not already configured in .meta.toml.')
parser.add_argument(
Expand Down Expand Up @@ -111,7 +110,7 @@ def handle_command_line_arguments():
'--with-sphinx',
dest='with_docs',
action='store_true',
default=None,
default=False,
help='Activate building docs if not already configured in .meta.toml.')
parser.add_argument(
'--with-sphinx-doctests',
Expand Down Expand Up @@ -178,7 +177,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 @@ -636,10 +636,7 @@ def configure(self):
with open('.meta.toml', 'w') as meta_f:
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
5 changes: 3 additions & 2 deletions config/drop-legacy-python.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import pathlib
import shutil
import sys
import toml
import tomlkit


parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -56,7 +56,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 Down
114 changes: 0 additions & 114 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.3
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
47 changes: 0 additions & 47 deletions config/shared/toml_encoder.py

This file was deleted.

0 comments on commit f631b48

Please sign in to comment.