Skip to content

Commit

Permalink
Use dom_toml for the toml encoding and decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Mar 26, 2021
1 parent bf7e9ca commit e0e4e81
Show file tree
Hide file tree
Showing 26 changed files with 123 additions and 39 deletions.
15 changes: 4 additions & 11 deletions repo_helper/files/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
from typing import Any, Dict, List, Tuple, TypeVar

# 3rd party
import dom_toml
import jinja2
import toml
from domdf_python_tools.compat import importlib_resources
from domdf_python_tools.paths import PathPlus
from natsort import natsorted
Expand All @@ -44,14 +44,7 @@
from repo_helper.configupdater2 import ConfigUpdater
from repo_helper.configuration.utils import get_version_classifiers
from repo_helper.files import management
from repo_helper.utils import (
CustomTomlEncoder,
IniConfigurator,
indent_join,
indent_with_tab,
license_lookup,
reformat_file
)
from repo_helper.utils import IniConfigurator, indent_join, indent_with_tab, license_lookup, reformat_file

__all__ = [
"make_manifest",
Expand Down Expand Up @@ -140,7 +133,7 @@ def make_pyproject(repo_path: pathlib.Path, templates: jinja2.Environment) -> Li
data: DefaultDict[str, Any]

if pyproject_file.is_file():
data = DefaultDict(toml.loads(pyproject_file.read_text()))
data = DefaultDict(dom_toml.load(pyproject_file))
else:
data = DefaultDict()

Expand Down Expand Up @@ -274,7 +267,7 @@ def make_pyproject(repo_path: pathlib.Path, templates: jinja2.Environment) -> Li
data["tool"]["importcheck"] = data["tool"].get("importcheck", {})

# TODO: managed message
pyproject_file.write_clean(toml.dumps(data, encoder=CustomTomlEncoder(dict)))
dom_toml.dump(data, pyproject_file, encoder=dom_toml.TomlEncoder)

return [pyproject_file.name]

Expand Down
8 changes: 4 additions & 4 deletions repo_helper/files/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
from typing import Any, Dict, List, Tuple

# 3rd party
import dom_toml
import jinja2
import toml
from domdf_python_tools.paths import PathPlus
from domdf_python_tools.stringlist import DelimitedList
from domdf_python_tools.typing import PathLike
Expand All @@ -51,7 +51,7 @@
from repo_helper.configupdater2 import ConfigUpdater
from repo_helper.files import management
from repo_helper.files.linting import code_only_warning, lint_warn_list
from repo_helper.utils import CustomTomlEncoder, IniConfigurator, indent_join
from repo_helper.utils import IniConfigurator, indent_join

__all__ = [
"make_tox",
Expand Down Expand Up @@ -704,7 +704,7 @@ def make_formate_toml(repo_path: pathlib.Path, templates: jinja2.Environment) ->
known_third_party.update(isort_config["known_third_party"])

if formate_file.is_file():
formate_config = toml.loads(formate_file.read_text())
formate_config = dom_toml.load(formate_file)
else:
formate_config = {}

Expand Down Expand Up @@ -748,7 +748,7 @@ def normalise_underscore(name: str) -> str:
formate_config["config"] = config

formate_file = PathPlus(repo_path / "formate.toml")
formate_file.write_clean(toml.dumps(formate_config, encoder=CustomTomlEncoder(dict)))
dom_toml.dump(formate_config, formate_file, encoder=dom_toml.TomlEncoder)

return [formate_file.name, isort_file.name]

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ click==7.1.2
configconfig>=0.5.0
consolekit>=1.0.0
dict2css>=0.2.0
dom-toml>=0.2.2
domdf-python-tools>=2.7.0
dulwich>=0.19.16
email-validator==1.1.2
Expand All @@ -18,6 +19,5 @@ ruamel-yaml>=0.16.12
shippinglabel>=0.8.2
southwark>=0.7.1
tabulate>=0.8.8
toml>=0.10.2
typing-extensions>=3.7.4.3
yapf-isort>=0.5.2
9 changes: 7 additions & 2 deletions tests/test_cli/test_show_/test_requirements_3_10__.tree
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ repo_helper==2020.12.18
│ ├── natsort>=7.1.0
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── dom-toml>=0.2.2
│ ├── domdf-python-tools>=2.7.0
│ │ ├── natsort>=7.1.0
│ │ ├── pydash>=4.7.4
│ │ └── typing-extensions>=3.7.4.3
│ └── toml>=0.10.2
├── domdf-python-tools>=2.7.0
│ ├── natsort>=7.1.0
│ ├── pydash>=4.7.4
Expand Down Expand Up @@ -194,7 +200,6 @@ repo_helper==2020.12.18
│ ├── filelock>=3.0.12
│ └── typing-extensions>=3.7.4.3
├── tabulate>=0.8.8
├── toml>=0.10.2
├── typing-extensions>=3.7.4.3
└── yapf-isort>=0.5.2
├── asttokens>=2.0.4
Expand All @@ -219,4 +224,4 @@ repo_helper==2020.12.18
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── isort<=5.6.4,>=5.5.2
└── yapf==0.30.0
└── yapf==0.30.0
12 changes: 11 additions & 1 deletion tests/test_cli/test_show_/test_requirements_3_6_.tree
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ repo_helper==2020.12.18
│ ├── natsort>=7.1.0
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── dom-toml>=0.2.2
│ ├── domdf-python-tools>=2.7.0
│ │ ├── importlib-metadata<3.5.0,>=1.5.0; python_version < "3.9"
│ │ │ ├── typing-extensions>=3.6.4; python_version < "3.8"
│ │ │ └── zipp>=0.5
│ │ ├── importlib-resources>=3.0.0; python_version < "3.7"
│ │ │ └── zipp>=0.4; python_version < "3.8"
│ │ ├── natsort>=7.1.0
│ │ ├── pydash>=4.7.4
│ │ └── typing-extensions>=3.7.4.3
│ └── toml>=0.10.2
├── domdf-python-tools>=2.7.0
│ ├── importlib-metadata<3.5.0,>=1.5.0; python_version < "3.9"
│ │ ├── typing-extensions>=3.6.4; python_version < "3.8"
Expand Down Expand Up @@ -267,7 +278,6 @@ repo_helper==2020.12.18
│ ├── filelock>=3.0.12
│ └── typing-extensions>=3.7.4.3
├── tabulate>=0.8.8
├── toml>=0.10.2
├── typing-extensions>=3.7.4.3
└── yapf-isort>=0.5.2
├── asttokens>=2.0.4
Expand Down
12 changes: 10 additions & 2 deletions tests/test_cli/test_show_/test_requirements_3_7_.tree
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ repo_helper==2020.12.18
│ ├── natsort>=7.1.0
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── dom-toml>=0.2.2
│ ├── domdf-python-tools>=2.7.0
│ │ ├── importlib-metadata<3.5.0,>=1.5.0; python_version < "3.9"
│ │ │ ├── typing-extensions>=3.6.4; python_version < "3.8"
│ │ │ └── zipp>=0.5
│ │ ├── natsort>=7.1.0
│ │ ├── pydash>=4.7.4
│ │ └── typing-extensions>=3.7.4.3
│ └── toml>=0.10.2
├── domdf-python-tools>=2.7.0
│ ├── importlib-metadata<3.5.0,>=1.5.0; python_version < "3.9"
│ │ ├── typing-extensions>=3.6.4; python_version < "3.8"
Expand Down Expand Up @@ -241,7 +250,6 @@ repo_helper==2020.12.18
│ ├── filelock>=3.0.12
│ └── typing-extensions>=3.7.4.3
├── tabulate>=0.8.8
├── toml>=0.10.2
├── typing-extensions>=3.7.4.3
└── yapf-isort>=0.5.2
├── asttokens>=2.0.4
Expand Down Expand Up @@ -273,4 +281,4 @@ repo_helper==2020.12.18
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── isort<=5.6.4,>=5.5.2
└── yapf==0.30.0
└── yapf==0.30.0
11 changes: 9 additions & 2 deletions tests/test_cli/test_show_/test_requirements_3_8_.tree
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ repo_helper==2020.12.18
│ ├── natsort>=7.1.0
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── dom-toml>=0.2.2
│ ├── domdf-python-tools>=2.7.0
│ │ ├── importlib-metadata<3.5.0,>=1.5.0; python_version < "3.9"
│ │ │ └── zipp>=0.5
│ │ ├── natsort>=7.1.0
│ │ ├── pydash>=4.7.4
│ │ └── typing-extensions>=3.7.4.3
│ └── toml>=0.10.2
├── domdf-python-tools>=2.7.0
│ ├── importlib-metadata<3.5.0,>=1.5.0; python_version < "3.9"
│ │ └── zipp>=0.5
Expand Down Expand Up @@ -221,7 +229,6 @@ repo_helper==2020.12.18
│ ├── filelock>=3.0.12
│ └── typing-extensions>=3.7.4.3
├── tabulate>=0.8.8
├── toml>=0.10.2
├── typing-extensions>=3.7.4.3
└── yapf-isort>=0.5.2
├── asttokens>=2.0.4
Expand Down Expand Up @@ -251,4 +258,4 @@ repo_helper==2020.12.18
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── isort<=5.6.4,>=5.5.2
└── yapf==0.30.0
└── yapf==0.30.0
9 changes: 7 additions & 2 deletions tests/test_cli/test_show_/test_requirements_3_9_.tree
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ repo_helper==2020.12.18
│ ├── natsort>=7.1.0
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── dom-toml>=0.2.2
│ ├── domdf-python-tools>=2.7.0
│ │ ├── natsort>=7.1.0
│ │ ├── pydash>=4.7.4
│ │ └── typing-extensions>=3.7.4.3
│ └── toml>=0.10.2
├── domdf-python-tools>=2.7.0
│ ├── natsort>=7.1.0
│ ├── pydash>=4.7.4
Expand Down Expand Up @@ -199,7 +205,6 @@ repo_helper==2020.12.18
│ ├── filelock>=3.0.12
│ └── typing-extensions>=3.7.4.3
├── tabulate>=0.8.8
├── toml>=0.10.2
├── typing-extensions>=3.7.4.3
└── yapf-isort>=0.5.2
├── asttokens>=2.0.4
Expand All @@ -225,4 +230,4 @@ repo_helper==2020.12.18
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── isort<=5.6.4,>=5.5.2
└── yapf==0.30.0
└── yapf==0.30.0
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ repo_helper==2020.12.18
├── dict2css>=0.2.0
├── distlib<1,>=0.3.1
├── dnspython>=1.15.0
├── dom-toml>=0.2.2
├── domdf-python-tools>=2.7.0
├── dulwich!=0.20.7,!=0.20.8,!=0.20.9,>=0.20.5
├── email-validator==1.1.2
Expand Down Expand Up @@ -57,4 +58,4 @@ repo_helper==2020.12.18
├── virtualenv>=20.0.8
├── wheel-filename>=1.2.0
├── yapf==0.30.0
└── yapf-isort>=0.5.2
└── yapf-isort>=0.5.2
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ repo_helper==2020.12.18
├── dict2css>=0.2.0
├── distlib<1,>=0.3.1
├── dnspython>=1.15.0
├── dom-toml>=0.2.2
├── domdf-python-tools>=2.7.0
├── dulwich!=0.20.7,!=0.20.8,!=0.20.9,>=0.20.5
├── email-validator==1.1.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ repo_helper==2020.12.18
├── dict2css>=0.2.0
├── distlib<1,>=0.3.1
├── dnspython>=1.15.0
├── dom-toml>=0.2.2
├── domdf-python-tools>=2.7.0
├── dulwich!=0.20.7,!=0.20.8,!=0.20.9,>=0.20.5
├── email-validator==1.1.2
Expand Down Expand Up @@ -65,4 +66,4 @@ repo_helper==2020.12.18
├── wheel-filename>=1.2.0
├── yapf==0.30.0
├── yapf-isort>=0.5.2
└── zipp>=0.5
└── zipp>=0.5
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ repo_helper==2020.12.18
├── dict2css>=0.2.0
├── distlib<1,>=0.3.1
├── dnspython>=1.15.0
├── dom-toml>=0.2.2
├── domdf-python-tools>=2.7.0
├── dulwich!=0.20.7,!=0.20.8,!=0.20.9,>=0.20.5
├── email-validator==1.1.2
Expand Down Expand Up @@ -61,4 +62,4 @@ repo_helper==2020.12.18
├── wheel-filename>=1.2.0
├── yapf==0.30.0
├── yapf-isort>=0.5.2
└── zipp>=0.5
└── zipp>=0.5
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ repo_helper==2020.12.18
├── dict2css>=0.2.0
├── distlib<1,>=0.3.1
├── dnspython>=1.15.0
├── dom-toml>=0.2.2
├── domdf-python-tools>=2.7.0
├── dulwich!=0.20.7,!=0.20.8,!=0.20.9,>=0.20.5
├── email-validator==1.1.2
Expand Down Expand Up @@ -59,4 +60,4 @@ repo_helper==2020.12.18
├── virtualenv>=20.0.8
├── wheel-filename>=1.2.0
├── yapf==0.30.0
└── yapf-isort>=0.5.2
└── yapf-isort>=0.5.2
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ repo_helper==2020.12.18
│ ├── natsort>=7.1.0
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── dom-toml>=0.2.2
│ ├── domdf-python-tools>=2.7.0
│ │ ├── natsort>=7.1.0
│ │ ├── pydash>=4.7.4
│ │ └── typing-extensions>=3.7.4.3
│ └── toml>=0.10.2
├── domdf-python-tools>=2.7.0
│ ├── natsort>=7.1.0
│ ├── pydash>=4.7.4
Expand Down Expand Up @@ -194,7 +200,6 @@ repo_helper==2020.12.18
│ ├── filelock>=3.0.12
│ └── typing-extensions>=3.7.4.3
├── tabulate>=0.8.8
├── toml>=0.10.2
├── typing-extensions>=3.7.4.3
└── yapf-isort>=0.5.2
├── asttokens>=2.0.4
Expand All @@ -219,4 +224,4 @@ repo_helper==2020.12.18
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── isort<=5.6.4,>=5.5.2
└── yapf==0.30.0
└── yapf==0.30.0
14 changes: 12 additions & 2 deletions tests/test_cli/test_show_/test_requirements_no_pager_3_6_.tree
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ repo_helper==2020.12.18
│ ├── natsort>=7.1.0
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── dom-toml>=0.2.2
│ ├── domdf-python-tools>=2.7.0
│ │ ├── importlib-metadata<3.5.0,>=1.5.0; python_version < "3.9"
│ │ │ ├── typing-extensions>=3.6.4; python_version < "3.8"
│ │ │ └── zipp>=0.5
│ │ ├── importlib-resources>=3.0.0; python_version < "3.7"
│ │ │ └── zipp>=0.4; python_version < "3.8"
│ │ ├── natsort>=7.1.0
│ │ ├── pydash>=4.7.4
│ │ └── typing-extensions>=3.7.4.3
│ └── toml>=0.10.2
├── domdf-python-tools>=2.7.0
│ ├── importlib-metadata<3.5.0,>=1.5.0; python_version < "3.9"
│ │ ├── typing-extensions>=3.6.4; python_version < "3.8"
Expand Down Expand Up @@ -267,7 +278,6 @@ repo_helper==2020.12.18
│ ├── filelock>=3.0.12
│ └── typing-extensions>=3.7.4.3
├── tabulate>=0.8.8
├── toml>=0.10.2
├── typing-extensions>=3.7.4.3
└── yapf-isort>=0.5.2
├── asttokens>=2.0.4
Expand Down Expand Up @@ -303,4 +313,4 @@ repo_helper==2020.12.18
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── isort<=5.6.4,>=5.5.2
└── yapf==0.30.0
└── yapf==0.30.0
12 changes: 10 additions & 2 deletions tests/test_cli/test_show_/test_requirements_no_pager_3_7_.tree
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ repo_helper==2020.12.18
│ ├── natsort>=7.1.0
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── dom-toml>=0.2.2
│ ├── domdf-python-tools>=2.7.0
│ │ ├── importlib-metadata<3.5.0,>=1.5.0; python_version < "3.9"
│ │ │ ├── typing-extensions>=3.6.4; python_version < "3.8"
│ │ │ └── zipp>=0.5
│ │ ├── natsort>=7.1.0
│ │ ├── pydash>=4.7.4
│ │ └── typing-extensions>=3.7.4.3
│ └── toml>=0.10.2
├── domdf-python-tools>=2.7.0
│ ├── importlib-metadata<3.5.0,>=1.5.0; python_version < "3.9"
│ │ ├── typing-extensions>=3.6.4; python_version < "3.8"
Expand Down Expand Up @@ -241,7 +250,6 @@ repo_helper==2020.12.18
│ ├── filelock>=3.0.12
│ └── typing-extensions>=3.7.4.3
├── tabulate>=0.8.8
├── toml>=0.10.2
├── typing-extensions>=3.7.4.3
└── yapf-isort>=0.5.2
├── asttokens>=2.0.4
Expand Down Expand Up @@ -273,4 +281,4 @@ repo_helper==2020.12.18
│ ├── pydash>=4.7.4
│ └── typing-extensions>=3.7.4.3
├── isort<=5.6.4,>=5.5.2
└── yapf==0.30.0
└── yapf==0.30.0
Loading

0 comments on commit e0e4e81

Please sign in to comment.