Skip to content
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
1 change: 0 additions & 1 deletion docs/cli/t4sanity.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ $ t4sanity -h
│ --output -o TEXT Path to output JSON file. [default: None] │
│ --revision -rv TEXT Specify if you want to check the specific version. [default: None] │
│ --exclude -e TEXT Exclude specific rules or rule groups. [default: None] │
│ --include-warning -iw Indicates whether to report any warnings. │
│ --strict -s Indicates whether warnings are treated as failures. │
│ --install-completion Install completion for the current shell. │
│ --show-completion Show completion for the current shell, to copy it or customize the installation. │
Expand Down
15 changes: 5 additions & 10 deletions t4_devkit/cli/sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,14 @@ def main(
excludes: list[str] | None = typer.Option(
None, "-e", "--exclude", help="Exclude specific rules or rule groups."
),
include_warning: bool = typer.Option(
False, "-iw", "--include-warning", help="Indicates whether to report any warnings."
),
strict: bool = typer.Option(
False, "-s", "--strict", help="Indicates whether warnings are treated as failures."
False,
"-s",
"--strict",
help="By default, warnings do not cause failure. If set, warnings are treated as failures.",
),
) -> None:
result = sanity_check(
data_root=data_root,
revision=revision,
excludes=excludes,
include_warning=include_warning,
)
result = sanity_check(data_root=data_root, revision=revision, excludes=excludes)

print_sanity_result(result, strict=strict)

Expand Down
17 changes: 4 additions & 13 deletions t4_devkit/sanity/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import warnings
from typing import Sequence

from .context import SanityContext
Expand All @@ -14,29 +13,21 @@ def sanity_check(
data_root: str,
revision: str | None = None,
*,
include_warning: bool = False,
excludes: Sequence[str] | None = None,
) -> SanityResult:
"""Run sanity checks on the given data root.

Args:
data_root (str): The root directory of the data.
revision (str | None, optional): The revision to check. If None, the latest revision is used.
include_warning (bool, optional): Whether to include warning checks.
excludes (Sequence[str] | None, optional): A list of rule names or groups to exclude.

Returns:
A SanityResult object.
"""
with warnings.catch_warnings():
if include_warning:
warnings.simplefilter("error")
else:
warnings.simplefilter("ignore")
context = SanityContext.from_path(data_root, revision=revision)

context = SanityContext.from_path(data_root, revision=revision)
checkers = CHECKERS.build(excludes=excludes)
reports = [checker(context) for checker in checkers]

checkers = CHECKERS.build(excludes=excludes)
reports = [checker(context) for checker in checkers]

return SanityResult.from_context(context, reports)
return SanityResult.from_context(context, reports)