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

Use the toml implementation from standard lib. #209

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 2 additions & 1 deletion config/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ Usage
Preparation
+++++++++++

The script needs a ``venv`` with some packages installed::
The script needs a ``venv`` with at Python > 3.11 with some packages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The script needs a ``venv`` with at Python > 3.11 with some packages
The script needs a ``venv`` with at least Python 3.11 and some dependencies

installed::

$ python3.11 -m venv .
$ bin/pip install -r requirements.txt
Expand Down
32 changes: 21 additions & 11 deletions config/config-package.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
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 tomli_w
import tomllib


META_HINT = """\
Expand Down Expand Up @@ -143,6 +143,17 @@ def prepend_space(text):
return text


def remove_empty_dict_entries(data):
"""Remove None/{} entries in data recursively."""
# The tomli-w writer cannot handle it.
if not isinstance(data, dict):
return data

return {k: remove_empty_dict_entries(v)
for k, v in data.items()
if v not in (None, {})}


class PackageConfiguration:
add_coveragerc = False
rm_coveragerc = False
Expand All @@ -166,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 = tomllib.load(meta_f)
meta_cfg = collections.defaultdict(dict, **meta_cfg)
else:
meta_cfg = collections.defaultdict(dict)
Expand Down Expand Up @@ -620,14 +632,12 @@ def configure(self):
if self.add_manylinux and self.args.commit:
call('git', 'add', '.manylinux.sh', '.manylinux-install.sh')
# 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('\n')
toml.dump(
meta_cfg, meta_f,
TomlArraySeparatorEncoderWithNewline(
separator=',\n ', indent_first_line=True))
meta_cfg = remove_empty_dict_entries(self.meta_cfg)
with open('.meta.toml', 'wb') as meta_f:
meta_f.write(
META_HINT.format(config_type=self.config_type).encode())
meta_f.write(b'\n')
tomli_w.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 @@ -10,7 +10,7 @@
import pathlib
import shutil
import sys
import toml
import tomllib


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, **tomllib.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
102 changes: 0 additions & 102 deletions config/meta-cfg-to-toml.py

This file was deleted.

2 changes: 1 addition & 1 deletion config/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
check-python-versions==0.20.0
Jinja2==3.1.2
pyupgrade==3.3.1
toml==0.10.2
tomli-w==1.0.0
tox==4.0.14
zest.releaser==7.2.0
35 changes: 0 additions & 35 deletions config/shared/toml_encoder.py

This file was deleted.