Skip to content

Commit

Permalink
MAINT: remove redundant Taplo config exclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Oct 8, 2023
1 parent 1ae3de7 commit 44cb8d2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
4 changes: 0 additions & 4 deletions .taplo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
exclude = [
"**/Cargo.toml",
"**/Manifest.toml",
"**/Project.toml",
"labels*.toml",
"labels/*.toml",
]

Expand Down
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
".constraints/*.txt": true,
".github/workflows/cd.yml": true,
".github/workflows/ci.yml": true,
".taplo.toml": true,
"src/repoma/.github/workflows/clean-caches.yml": true,
"src/repoma/.github/workflows/pr-linting.yml": true,
"src/repoma/.github/workflows/release-drafter.yml": true,
"src/repoma/.template/.cspell.json": true,
"src/repoma/.template/.gitpod.yml": true,
"src/repoma/.template/.prettierrc": true,
"src/repoma/.template/.taplo.toml": true
"src/repoma/.template/.prettierrc": true
},
"yaml.schemas": {
"https://citation-file-format.github.io/1.2.0/schema.json": "CITATION.cff",
Expand Down
1 change: 0 additions & 1 deletion src/repoma/.template/.taplo.toml

This file was deleted.

20 changes: 20 additions & 0 deletions src/repoma/.template/.taplo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
exclude = [
"**/Cargo.toml",
"**/Manifest.toml",
"**/Project.toml",
"labels*.toml",
"labels/*.toml",
]

[formatting]
align_comments = false
align_entries = false
allowed_blank_lines = 1
array_auto_collapse = false
array_auto_expand = true
array_trailing_comma = true
column_width = 88
compact_inline_tables = true
indent_string = " "
reorder_arrays = true
reorder_keys = true
17 changes: 13 additions & 4 deletions src/repoma/check_dev_files/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
from typing import List, Union

import tomlkit
from ruamel.yaml.comments import CommentedMap

from repoma.errors import PrecommitError
Expand Down Expand Up @@ -94,12 +95,20 @@ def _update_taplo_config() -> None:
msg = f"Added {CONFIG_PATH.taplo} config for TOML formatting"
raise PrecommitError(msg)
with open(template_path) as f:
expected_content = f.read()
expected = tomlkit.load(f)

Check warning on line 98 in src/repoma/check_dev_files/toml.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/toml.py#L98

Added line #L98 was not covered by tests
excludes: List[str] = [p for p in expected["exclude"] if glob(p, recursive=True)] # type: ignore[union-attr]
if excludes:
excludes = sorted(excludes, key=str.lower)
expected["exclude"] = to_toml_array(excludes, enforce_multiline=True)

Check warning on line 102 in src/repoma/check_dev_files/toml.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/toml.py#L101-L102

Added lines #L101 - L102 were not covered by tests
else:
del expected["exclude"]

Check warning on line 104 in src/repoma/check_dev_files/toml.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/toml.py#L104

Added line #L104 was not covered by tests
with open(CONFIG_PATH.taplo) as f:
existing_content = f.read()
if existing_content != expected_content:
existing = tomlkit.load(f)
expected_str = tomlkit.dumps(expected)
existing_str = tomlkit.dumps(existing)

Check warning on line 108 in src/repoma/check_dev_files/toml.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/toml.py#L106-L108

Added lines #L106 - L108 were not covered by tests
if existing_str != expected_str:
with open(CONFIG_PATH.taplo, "w") as stream:
stream.write(expected_content)
stream.write(expected_str)

Check warning on line 111 in src/repoma/check_dev_files/toml.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/toml.py#L111

Added line #L111 was not covered by tests
msg = f"Updated {CONFIG_PATH.taplo} config file"
raise PrecommitError(msg)

Expand Down
4 changes: 2 additions & 2 deletions src/repoma/utilities/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def write_pyproject(config: TOMLDocument) -> None:
stream.write(src)


def to_toml_array(items: Iterable[Any]) -> Array:
def to_toml_array(items: Iterable[Any], enforce_multiline: bool = False) -> Array:
array = tomlkit.array()
array.extend(items)
if len(array) > 1:
if enforce_multiline or len(array) > 1:
array.multiline(True)
else:
array.multiline(False)
Expand Down

0 comments on commit 44cb8d2

Please sign in to comment.