From b4099894845a711f500efeb40ca657e745d67208 Mon Sep 17 00:00:00 2001 From: ric-evans Date: Fri, 26 Apr 2024 15:06:08 -0500 Subject: [PATCH] exclude dots in toml dict --- action.yml | 1 + pyproject_toml_builder.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 1e69e76..4f814ef 100644 --- a/action.yml +++ b/action.yml @@ -136,6 +136,7 @@ runs: --license "${{ inputs.license }}" set +x + # format (inc. sorting sections) pip install toml-sort toml-sort --in-place --ignore-case pyproject.toml diff --git a/pyproject_toml_builder.py b/pyproject_toml_builder.py index 41db575..1176157 100644 --- a/pyproject_toml_builder.py +++ b/pyproject_toml_builder.py @@ -46,6 +46,15 @@ PythonMinMax = tuple[tuple[int, int], tuple[int, int]] +class NoDotsDict(dict): + """A custom dictionary class that disallows keys with dots ('.').""" + + def __setitem__(self, key, value): + if "." in key: + raise ValueError("Keys cannot contain dots ('.').") + super().__setitem__(key, value) + + class GitHubAPI: """Relay info from the GitHub API.""" @@ -365,7 +374,7 @@ def badges_lines(self) -> list[str]: def _build_out_sections( - toml_dict: dict, + toml_dict: NoDotsDict, root_path: Path, github_full_repo: str, token: str, @@ -490,9 +499,9 @@ def write_toml( toml_file = toml_file.resolve() if toml_file.exists(): with open(toml_file, "r") as f: - toml_dict = toml.load(f) + toml_dict = NoDotsDict(toml.load(f)) else: - toml_dict = {} + toml_dict = NoDotsDict() readme_mgr = _build_out_sections( toml_dict,