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

MAINT: remove redundant Taplo config exclusions #201

Merged
merged 1 commit into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
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)
else:
del expected["exclude"]
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)
if existing_str != expected_str:
with open(CONFIG_PATH.taplo, "w") as stream:
stream.write(expected_content)
stream.write(expected_str)
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