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

Allow TOML 1.0.0 syntax in check-toml #608

Closed
wants to merge 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions pre_commit_hooks/check_toml.py
Expand Up @@ -2,7 +2,7 @@
from typing import Optional
from typing import Sequence

import toml
import tomli


def main(argv: Optional[Sequence[str]] = None) -> int:
Expand All @@ -12,11 +12,12 @@ def main(argv: Optional[Sequence[str]] = None) -> int:

retval = 0
for filename in args.filenames:
try:
toml.load(filename)
except toml.TomlDecodeError as exc:
print(f'{filename}: {exc}')
retval = 1
with open(filename, encoding='utf-8') as f:
try:
tomli.load(f)
except tomli.TOMLDecodeError as exc:
print(f'{filename}: {exc}')
retval = 1
return retval


Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -24,7 +24,7 @@ classifiers =
packages = find:
install_requires =
ruamel.yaml>=0.15
toml
tomli
python_requires = >=3.6.1

[options.packages.find]
Expand Down
3 changes: 3 additions & 0 deletions tests/check_toml_test.py
Expand Up @@ -23,6 +23,9 @@ def test_toml_good(tmpdir):
[owner]
name = "John"
dob = 1979-05-27T07:32:00-08:00 # First class dates

["toml-1.0.0-compat"]
heterogeneous-array = [1, "2"]
""",
)
ret = main((str(filename),))
Expand Down