Skip to content

Commit

Permalink
exclude dots in toml dict
Browse files Browse the repository at this point in the history
  • Loading branch information
ric-evans committed Apr 26, 2024
1 parent 8445ec0 commit b409989
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions pyproject_toml_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

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

0 comments on commit b409989

Please sign in to comment.