rb-textcheck 0.3.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rb_textcheck/__init__.py +36 -0
- rb_textcheck/_distribution.py +24 -0
- rb_textcheck/_pyproject.toml +172 -0
- rb_textcheck/cli.py +73 -0
- rb_textcheck/commands/__init__.py +1 -0
- rb_textcheck/commands/auth.py +66 -0
- rb_textcheck/commands/check.py +37 -0
- rb_textcheck/commands/config.py +87 -0
- rb_textcheck/commands/describe.py +34 -0
- rb_textcheck/commands/doctor.py +43 -0
- rb_textcheck/commands/fix.py +45 -0
- rb_textcheck/commands/init.py +48 -0
- rb_textcheck/commands/profile.py +35 -0
- rb_textcheck/commands/project.py +55 -0
- rb_textcheck/commands/rules.py +18 -0
- rb_textcheck/commands/skill.py +138 -0
- rb_textcheck/commands/status.py +35 -0
- rb_textcheck/core/__init__.py +1 -0
- rb_textcheck/core/checks.py +757 -0
- rb_textcheck/core/data_files.py +20 -0
- rb_textcheck/core/deps.py +165 -0
- rb_textcheck/core/errors.py +239 -0
- rb_textcheck/core/fix.py +234 -0
- rb_textcheck/core/humanizer_lint.py +335 -0
- rb_textcheck/core/models.py +25 -0
- rb_textcheck/core/normalize.py +52 -0
- rb_textcheck/core/opencli.py +286 -0
- rb_textcheck/core/profile.py +376 -0
- rb_textcheck/core/services.py +149 -0
- rb_textcheck/core/skills.py +64 -0
- rb_textcheck/core/text_blocks.py +104 -0
- rb_textcheck/core/version.py +89 -0
- rb_textcheck/data/LICENSE-humanizer-ru.txt +26 -0
- rb_textcheck/data/SKILL.md +63 -0
- rb_textcheck/data/__init__.py +1 -0
- rb_textcheck/data/quality-profile.schema.json +405 -0
- rb_textcheck/output/__init__.py +281 -0
- rb_textcheck/output/human.py +73 -0
- rb_textcheck/output/json.py +11 -0
- rb_textcheck-0.3.6.dist-info/METADATA +138 -0
- rb_textcheck-0.3.6.dist-info/RECORD +44 -0
- rb_textcheck-0.3.6.dist-info/WHEEL +4 -0
- rb_textcheck-0.3.6.dist-info/entry_points.txt +2 -0
- rb_textcheck-0.3.6.dist-info/licenses/LICENSE +21 -0
rb_textcheck/__init__.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""rb_textcheck - детерминированные проверки текста по профилю качества.
|
|
2
|
+
|
|
3
|
+
Библиотечно: ``rb_textcheck.check(text, profile, format)`` -> Result
|
|
4
|
+
(``.issues``, ``.humanizer``, ``.gate_failed``, ``.as_dict()``);
|
|
5
|
+
``rb_textcheck.fix(text, profile, format)`` -> FixResult (``.text``, ``.applied``, ``.unchanged``).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
__all__ = ["FixResult", "ProfileError", "QualityProfile", "Result", "check", "fix", "load_profile", "rules"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def rules() -> list[dict[str, Any]]:
|
|
16
|
+
"""Правила проверки: id, description, formats - в порядке выдачи."""
|
|
17
|
+
from .core.checks import RULES
|
|
18
|
+
|
|
19
|
+
return [dict(rule) for rule in RULES]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def __getattr__(name: str) -> Any:
|
|
23
|
+
# Ленивый импорт: CLI (--version, --help) не платит за bs4/html5lib
|
|
24
|
+
if name in ("check", "Result"):
|
|
25
|
+
from .core import checks
|
|
26
|
+
|
|
27
|
+
return getattr(checks, name)
|
|
28
|
+
if name in ("fix", "FixResult"):
|
|
29
|
+
from .core import fix
|
|
30
|
+
|
|
31
|
+
return getattr(fix, name)
|
|
32
|
+
if name in ("load_profile", "ProfileError", "QualityProfile"):
|
|
33
|
+
from .core import profile
|
|
34
|
+
|
|
35
|
+
return getattr(profile, name)
|
|
36
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""The distribution name and the tool namespace copier writes from its answers, because an editable install cannot map
|
|
2
|
+
this import package to its distribution at runtime.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# Rendered by copier from the `dist_name` answer: the [project] name in
|
|
6
|
+
# pyproject.toml (`rb-<slug>`, the Standard, Technology), which may differ from this
|
|
7
|
+
# import package's name. importlib.metadata finds this package's version,
|
|
8
|
+
# summary and console script by it; an editable install (`uv sync`) can't be
|
|
9
|
+
# mapped from package to distribution at runtime, so it is written down here.
|
|
10
|
+
# tests/test_cli.py fails if it drifts from pyproject.toml.
|
|
11
|
+
DIST_NAME = "rb-textcheck"
|
|
12
|
+
# The previous distribution name during a rename: an install made
|
|
13
|
+
# under it (not yet reinstalled) still finds its own version. Drop it once
|
|
14
|
+
# every machine has the new name.
|
|
15
|
+
DIST_NAME_LEGACY: str | None = None
|
|
16
|
+
# The command name (`cli_name`) as an identifier: the namespace of this tool's
|
|
17
|
+
# shared-database names (core/db.py) — table prefix `<TOOL>_`, env var
|
|
18
|
+
# `<TOOL>_DATABASE_URL`, Alembic table `alembic_version_<TOOL>`. Written down,
|
|
19
|
+
# not derived at runtime: a bare source run falls back to the package name,
|
|
20
|
+
# and a table name must never depend on how the tool was started.
|
|
21
|
+
TOOL = "textcheck"
|
|
22
|
+
# The cli-generator release this project was generated or last updated from
|
|
23
|
+
# (copier's `_commit`), for `describe --json`; None for a project not made by copier.
|
|
24
|
+
TEMPLATE_VERSION: str | None = "v1.27.3"
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "rb-textcheck"
|
|
3
|
+
# Version comes from the git tag vX.Y.Z (uv-dynamic-versioning) — never add `version =`.
|
|
4
|
+
dynamic = ["version"]
|
|
5
|
+
description = "Deterministic text quality checks by a quality profile, with no network and no LLM."
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "Roman Bolandau" }]
|
|
10
|
+
requires-python = ">=3.14"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"typer>=0.27,<0.29",
|
|
13
|
+
"rich>=13.7",
|
|
14
|
+
"pydantic>=2.6",
|
|
15
|
+
"tomli-w>=1.0",
|
|
16
|
+
"platformdirs>=4.2",
|
|
17
|
+
"packaging>=24.0",
|
|
18
|
+
"beautifulsoup4>=4.12",
|
|
19
|
+
"html5lib>=1.1",
|
|
20
|
+
"pymorphy3>=2.0",
|
|
21
|
+
"pymorphy3-dicts-ru>=2.4",
|
|
22
|
+
"pyyaml>=6.0",
|
|
23
|
+
"jsonschema>=4.23",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
textcheck = "rb_textcheck.cli:main"
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Repository = "https://github.com/bolandeu/rb-textcheck"
|
|
31
|
+
|
|
32
|
+
[build-system]
|
|
33
|
+
requires = ["hatchling", "uv-dynamic-versioning"]
|
|
34
|
+
build-backend = "hatchling.build"
|
|
35
|
+
|
|
36
|
+
[tool.hatch.version]
|
|
37
|
+
source = "uv-dynamic-versioning"
|
|
38
|
+
|
|
39
|
+
[tool.uv-dynamic-versioning]
|
|
40
|
+
vcs = "git"
|
|
41
|
+
style = "pep440"
|
|
42
|
+
fallback-version = "0.0.0"
|
|
43
|
+
|
|
44
|
+
[tool.uv]
|
|
45
|
+
# Rebuild the editable install when a commit or tag moves, so `--version` follows the tag.
|
|
46
|
+
cache-keys = [{ file = "pyproject.toml" }, { git = { commit = true, tags = true } }]
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.sdist]
|
|
49
|
+
# What a release must not carry: the agent's own files, the forge configs and the dev tooling. The wheel is
|
|
50
|
+
# narrow already (`packages = ["src/<pkg>"]`); this is about the sdist, which is otherwise a copy of the repo.
|
|
51
|
+
exclude = [
|
|
52
|
+
"/.agents",
|
|
53
|
+
"/.claude",
|
|
54
|
+
"/.claude-plugin",
|
|
55
|
+
"/.gitea",
|
|
56
|
+
"/.github",
|
|
57
|
+
"/docs",
|
|
58
|
+
"/scripts",
|
|
59
|
+
"/uv.lock",
|
|
60
|
+
"/AGENTS.md",
|
|
61
|
+
"/CLAUDE.md",
|
|
62
|
+
"/CODING_STANDARDS.md",
|
|
63
|
+
"/CONTEXT.md",
|
|
64
|
+
"/.copier-answers.yml",
|
|
65
|
+
"^\\.gitignore$",
|
|
66
|
+
"/.gitleaks.toml",
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
[tool.hatch.build.targets.wheel]
|
|
70
|
+
packages = ["src/rb_textcheck"]
|
|
71
|
+
|
|
72
|
+
[tool.hatch.build.targets.wheel.force-include]
|
|
73
|
+
# The installed CLI reads [[tool.rb.external]] from here (core/deps.py).
|
|
74
|
+
"pyproject.toml" = "rb_textcheck/_pyproject.toml"
|
|
75
|
+
|
|
76
|
+
[dependency-groups]
|
|
77
|
+
# Mutation testing, run now and then and before big releases — not in the gate:
|
|
78
|
+
# `uv run --group mutation mutmut run`, then `mutmut results` / `mutmut browse`.
|
|
79
|
+
# Needs fork(): macOS/Linux (WSL on Windows). Settings: [tool.mutmut] below.
|
|
80
|
+
mutation = ["mutmut>=3.3"]
|
|
81
|
+
dev = [
|
|
82
|
+
"jsonschema>=4.23",
|
|
83
|
+
"pytest>=8.0",
|
|
84
|
+
"pyyaml>=6.0", # .copier-answers.yml, the CI workflow, tests/contracts/*.yaml
|
|
85
|
+
"pytest-cov>=5.0",
|
|
86
|
+
"ruff>=0.6",
|
|
87
|
+
"syrupy>=4.8",
|
|
88
|
+
"ty>=0.0.80",
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
# External (non-Python) dependencies — every CLI this tool runs (require_cli,
|
|
92
|
+
# shutil.which, subprocess with a literal program, npx). The gate checks this
|
|
93
|
+
# list against the code both ways; doctor and require_cli read it at runtime;
|
|
94
|
+
# the tools catalog reads it (the Standard, Technology).
|
|
95
|
+
# [[tool.rb.external]]
|
|
96
|
+
# name = "ffmpeg"
|
|
97
|
+
# required = true # false: the tool works without it (doctor stays healthy)
|
|
98
|
+
# min_version = "6.0" # optional
|
|
99
|
+
# check = "ffmpeg -version" # prints the version; default "<name> --version"
|
|
100
|
+
# why = "transcodes the downloaded videos"
|
|
101
|
+
# detect = false # run via an injected runner / absolute path the gate can't see
|
|
102
|
+
# dist = "rb-serp" # for one of our CLIs: its distribution (default rb-<name>)
|
|
103
|
+
# url = "https://github.com/bolandeu/serp" # its repo: DEPENDENCY_TOO_OLD then prints a pinned install
|
|
104
|
+
|
|
105
|
+
# Where sysadmin's tool-updater installs this tool after its first tag. The
|
|
106
|
+
# installation is sysadmin's; this section only says where. homeserver: users
|
|
107
|
+
# to install for (empty = build and publish only); mac: install on the Mac.
|
|
108
|
+
# extras (optional): the extras to install with, e.g. extras = ["browser"].
|
|
109
|
+
[tool.rb.install]
|
|
110
|
+
homeserver = ["rbtools"]
|
|
111
|
+
mac = true
|
|
112
|
+
|
|
113
|
+
[tool.cli-generator]
|
|
114
|
+
# Where scripts/check_command_docstrings.py (called by the project's checks)
|
|
115
|
+
# looks for commands: a glob or a list of globs, relative to the repo root.
|
|
116
|
+
commands = ["src/rb_textcheck/commands/*.py"]
|
|
117
|
+
# gate check (the gate): extras to install before ruff/ty/pytest.
|
|
118
|
+
# gate_extras = ["browser"]
|
|
119
|
+
|
|
120
|
+
[tool.pytest.ini_options]
|
|
121
|
+
# Only tests/: mutmut leaves a copy of the tree in mutants/.
|
|
122
|
+
testpaths = ["tests"]
|
|
123
|
+
addopts = "--cov --cov-report=term-missing:skip-covered"
|
|
124
|
+
# tests/test_help.py keeps help snapshots at tests/snapshots/help/<command>.txt
|
|
125
|
+
# (the Standard, Commands), not in syrupy's own `__snapshots__/<test file>/` layout, so
|
|
126
|
+
# syrupy warns it "can not relate" each file to its test. It can — by name.
|
|
127
|
+
filterwarnings = ["ignore:(?s).*Can not relate snapshot:UserWarning"]
|
|
128
|
+
|
|
129
|
+
[tool.mutmut]
|
|
130
|
+
source_paths = ["src/rb_textcheck"]
|
|
131
|
+
also_copy = ["scripts/", "pyproject.toml"] # tests read them (test_scripts.py, the distribution checks)
|
|
132
|
+
pytest_add_cli_args = ["--no-cov"] # fail_under would kill every mutant
|
|
133
|
+
# only_mutate = ["*/core/normalize.py"] # one module at a time on a big tool
|
|
134
|
+
|
|
135
|
+
[tool.coverage.run]
|
|
136
|
+
source = ["src"]
|
|
137
|
+
# sysmon (default on 3.14) keeps a record per recompiled code object; Typer recompiles annotations on every invoke, so memory grows.
|
|
138
|
+
core = "ctrace"
|
|
139
|
+
|
|
140
|
+
[tool.coverage.report]
|
|
141
|
+
# The template ships at ~94%; keep the bar where it is instead of letting
|
|
142
|
+
# new commands land untested. Raise it, never lower it.
|
|
143
|
+
fail_under = 90
|
|
144
|
+
show_missing = true
|
|
145
|
+
|
|
146
|
+
[tool.ty.terminal]
|
|
147
|
+
# Only errors fail the gate; recent ty (>= 0.0.84) otherwise exits 1 on warnings too.
|
|
148
|
+
# Legacy code that can't be fixed yet: downgrade specific rules instead of
|
|
149
|
+
# ignoring them, e.g. [tool.ty.rules] possibly-unbound-attribute = "warn".
|
|
150
|
+
error-on-warning = false
|
|
151
|
+
|
|
152
|
+
[tool.ruff]
|
|
153
|
+
line-length = 120
|
|
154
|
+
|
|
155
|
+
[tool.ruff.lint]
|
|
156
|
+
select = ["E4", "E7", "E9", "F", "I", "UP", "B", "SIM", "RUF", "S", "T20", "TID251"]
|
|
157
|
+
# Russian messages, comments and docstrings: Cyrillic letters are not confusables here.
|
|
158
|
+
ignore = ["RUF001", "RUF002", "RUF003"]
|
|
159
|
+
|
|
160
|
+
[tool.ruff.lint.per-file-ignores]
|
|
161
|
+
"tests/*" = ["S101", "T201", "TID251"] # assert is the point of a test; print in code strings; httpx for mocks
|
|
162
|
+
"scripts/*" = ["S603", "S607", "T201"] # subprocess with fixed argv lists (git, uv), no shell; scripts print to the console
|
|
163
|
+
"src/*/providers/*" = ["TID251"] # external APIs live here
|
|
164
|
+
# Third-party copy (humanizer-ru lint.py, MIT): kept verbatim so diffs against upstream stay readable.
|
|
165
|
+
"src/rb_textcheck/core/humanizer_lint.py" = ["UP031", "B905", "RUF007", "T201"]
|
|
166
|
+
|
|
167
|
+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
|
|
168
|
+
"httpx".msg = "Call external APIs through providers/ (subclass providers.HttpProvider)."
|
|
169
|
+
|
|
170
|
+
[tool.ruff.lint.flake8-bugbear]
|
|
171
|
+
# Typer's `param: T = typer.Option(...)` style is a call in a default on purpose.
|
|
172
|
+
extend-immutable-calls = ["typer.Option", "typer.Argument"]
|
rb_textcheck/cli.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""The root Typer app: global options, the command groups and the optional commands a generated package has, wired
|
|
2
|
+
together, and the console-script entry point.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
from . import output
|
|
10
|
+
from .commands import auth, check, doctor, fix, profile, rules
|
|
11
|
+
from .core.version import DEV_VERSION, cli_name, installed_version, optional_module, package_summary
|
|
12
|
+
|
|
13
|
+
_PACKAGE_NAME = __name__.split(".")[0]
|
|
14
|
+
# Optional parts (copier questions, dropped by _exclude): each one ships a module that registers its
|
|
15
|
+
# commands and global options. Probed at runtime, so this file needs no template logic.
|
|
16
|
+
PARTS = ("project", "skill", "describe", "db")
|
|
17
|
+
|
|
18
|
+
# A bare `<cli>` is the discovery entry point for humans and agents alike:
|
|
19
|
+
# name + version + description, then every command with the first line of
|
|
20
|
+
# its docstring. No `no_args_is_help` (that exits 2) — main_options() below
|
|
21
|
+
# prints this and exits 0. Shell completion stays enabled.
|
|
22
|
+
app = typer.Typer(
|
|
23
|
+
cls=output.RootGroup, # a usage error under --json is the error envelope
|
|
24
|
+
help=f"{cli_name()} {installed_version() or DEV_VERSION} — {package_summary() or 'project-aware automation CLI'}",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
app.add_typer(auth.app, name="auth") # `auth status` in every CLI; login/logout only with credentials
|
|
28
|
+
app.add_typer(profile.app, name="profile")
|
|
29
|
+
|
|
30
|
+
app.command(name="doctor")(doctor.doctor)
|
|
31
|
+
app.command(name="check")(check.check)
|
|
32
|
+
app.command(name="fix")(fix.fix)
|
|
33
|
+
app.command(name="rules")(rules.rules)
|
|
34
|
+
for part in PARTS:
|
|
35
|
+
if module := optional_module(f"{_PACKAGE_NAME}.commands.{part}"):
|
|
36
|
+
module.register(app)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _version_callback(value: bool) -> None:
|
|
40
|
+
if not value:
|
|
41
|
+
return
|
|
42
|
+
typer.echo(installed_version() or DEV_VERSION)
|
|
43
|
+
raise typer.Exit()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@app.callback(invoke_without_command=True)
|
|
47
|
+
def main_options(
|
|
48
|
+
ctx: typer.Context,
|
|
49
|
+
json_output: bool = typer.Option(False, "--json", help="Emit machine-readable JSON output."),
|
|
50
|
+
quiet: bool = typer.Option(False, "--quiet", help="Suppress non-essential output."),
|
|
51
|
+
verbose: bool = typer.Option(False, "--verbose", help="Emit extra diagnostic output."),
|
|
52
|
+
non_interactive: bool = typer.Option(False, "--non-interactive", help="Never prompt; fail instead."),
|
|
53
|
+
dry_run: bool = typer.Option(False, "--dry-run", help="Show what would happen without making changes."),
|
|
54
|
+
version: bool = typer.Option(
|
|
55
|
+
False, "--version", callback=_version_callback, is_eager=True, help="Show the version and exit."
|
|
56
|
+
),
|
|
57
|
+
) -> None:
|
|
58
|
+
ctx.ensure_object(dict) # a part's global option (--project) may have put its value here already
|
|
59
|
+
ctx.obj["json"] = json_output
|
|
60
|
+
ctx.obj["quiet"] = quiet
|
|
61
|
+
ctx.obj["verbose"] = verbose
|
|
62
|
+
ctx.obj["non_interactive"] = non_interactive
|
|
63
|
+
ctx.obj["dry_run"] = dry_run
|
|
64
|
+
output.configure_logging(verbose)
|
|
65
|
+
output.help_if_no_command(ctx)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def main() -> None:
|
|
69
|
+
app()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if __name__ == "__main__":
|
|
73
|
+
main()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""The commands of the CLI, one module per command or command group."""
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""The `auth` command group: `status` reports the health of the credentials of every provider, or an empty report when
|
|
2
|
+
the package has none.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import importlib
|
|
8
|
+
from datetime import UTC, datetime
|
|
9
|
+
|
|
10
|
+
import typer
|
|
11
|
+
|
|
12
|
+
from .. import output
|
|
13
|
+
from ..core.errors import InvalidArguments
|
|
14
|
+
from ..core.version import DEV_VERSION, cli_name, installed_version, module_exists, optional_module
|
|
15
|
+
|
|
16
|
+
# `auth status` exists in every CLI (the Standard, Health); a CLI
|
|
17
|
+
# generated without credentials (no credentials/ package, no commands/login.py)
|
|
18
|
+
# reports an empty `credentials` list and exits 0. Detected at runtime so this
|
|
19
|
+
# file needs no template logic — same approach as doctor.py.
|
|
20
|
+
_PACKAGE_NAME = __name__.split(".")[0]
|
|
21
|
+
_HAS_CREDENTIALS = module_exists(f"{_PACKAGE_NAME}.credentials.manager")
|
|
22
|
+
|
|
23
|
+
app = output.group("Credentials: report their health (and store them, if this CLI has any).")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@app.command("status")
|
|
27
|
+
@output.guard
|
|
28
|
+
def auth_status(
|
|
29
|
+
ctx: typer.Context,
|
|
30
|
+
check: bool = typer.Option(
|
|
31
|
+
False, "--check", help="Also make one cheap read-only call per provider (10 s timeout) to prove each works."
|
|
32
|
+
),
|
|
33
|
+
provider: str | None = typer.Option(
|
|
34
|
+
None, "--provider", help="Report only this provider, or one target as <kind>:<target> (default: all)."
|
|
35
|
+
),
|
|
36
|
+
json_output: bool = output.JsonOption,
|
|
37
|
+
quiet: bool = output.QuietOption,
|
|
38
|
+
) -> None:
|
|
39
|
+
"""Report every provider's credential: where it comes from and whether it works. Never prints values.
|
|
40
|
+
|
|
41
|
+
Without --check only presence is reported (status `unchecked` or `missing`).
|
|
42
|
+
Exits 0 when every required provider is ok/unchecked (an optional one may be
|
|
43
|
+
missing), 3 when any required provider has a problem or any credential is
|
|
44
|
+
invalid/expired, 2 on a usage error. A per-target provider (one credential per
|
|
45
|
+
site/host/account) gets one entry per stored target, named `<kind>:<target>`. The --json shape is a cross-tool contract:
|
|
46
|
+
`tool`, `version`, `checked_at`, `credentials[]` with `provider`, `required`,
|
|
47
|
+
`fields`, `source`, `source_ref`, `status`, `expires_at`, `quota`, `message`.
|
|
48
|
+
|
|
49
|
+
Example: {cli} auth status --check --json
|
|
50
|
+
"""
|
|
51
|
+
tool, version = cli_name(), installed_version() or DEV_VERSION
|
|
52
|
+
if not _HAS_CREDENTIALS:
|
|
53
|
+
if provider is not None:
|
|
54
|
+
raise InvalidArguments(f"Unknown provider '{provider}' ({tool} stores no credentials).")
|
|
55
|
+
checked_at = datetime.now(UTC).replace(microsecond=0).isoformat().replace("+00:00", "Z")
|
|
56
|
+
payload = {"tool": tool, "version": version, "checked_at": checked_at, "credentials": []}
|
|
57
|
+
output.emit_report(ctx, payload, lambda _: output.human.echo(f"{tool} stores no credentials."), None)
|
|
58
|
+
return
|
|
59
|
+
health = importlib.import_module(f"{_PACKAGE_NAME}.credentials.health")
|
|
60
|
+
payload, problem = health.status(tool, version, check=check, only=provider)
|
|
61
|
+
output.emit_report(ctx, payload, health.render, problem)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if _login := optional_module(f"{_PACKAGE_NAME}.commands.login"):
|
|
65
|
+
app.command("login")(_login.login)
|
|
66
|
+
app.command("logout")(_login.logout)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
|
|
8
|
+
from .. import output
|
|
9
|
+
from ..core import services
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@output.guard
|
|
13
|
+
def check(
|
|
14
|
+
ctx: typer.Context,
|
|
15
|
+
source: str = typer.Argument(..., help="Text file to check, or '-' for stdin."),
|
|
16
|
+
profile: Path | None = typer.Option(
|
|
17
|
+
None, "--profile", help="Quality profile (quality.yml). Without it: built-in defaults only."
|
|
18
|
+
),
|
|
19
|
+
text_format: str | None = typer.Option(
|
|
20
|
+
None, "--format", help="html or md. Default: md for .md/.markdown files, html otherwise (and for stdin)."
|
|
21
|
+
),
|
|
22
|
+
json_output: bool = output.JsonOption,
|
|
23
|
+
quiet: bool = output.QuietOption,
|
|
24
|
+
) -> None:
|
|
25
|
+
"""Check a text against a quality profile: findings, humanizer verdict, gate.
|
|
26
|
+
|
|
27
|
+
Deterministic, no network and no LLM. Every finding has rule, message,
|
|
28
|
+
excerpt, gate, unit, address and action; `textcheck rules` lists the rules.
|
|
29
|
+
Exit 0: the gate passed (findings with gate=false are for information).
|
|
30
|
+
Exit 1: findings with gate=true — the report is still emitted (ok=false,
|
|
31
|
+
error QUALITY_GATE_FAILED). Exit 2: bad arguments or profile.
|
|
32
|
+
|
|
33
|
+
Example: {cli} check article.html --profile content-logistics.quality.yml --json
|
|
34
|
+
"""
|
|
35
|
+
text = sys.stdin.read() if source == "-" else services.read_text(Path(source))
|
|
36
|
+
result, problem = services.run_check(text, profile, services.text_format(source, text_format))
|
|
37
|
+
output.emit_report(ctx, result, render_human=output.human.render_check, problem=problem)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""The `config` command group: show and change the project's config file."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
from .. import output
|
|
10
|
+
from ..core import services
|
|
11
|
+
from ..core.errors import InvalidArguments
|
|
12
|
+
from ..core.models import ProjectConfig
|
|
13
|
+
|
|
14
|
+
app = output.group("Manage project configuration.")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@app.command("list")
|
|
18
|
+
@output.guard
|
|
19
|
+
def list_config(
|
|
20
|
+
ctx: typer.Context,
|
|
21
|
+
json_output: bool = output.JsonOption,
|
|
22
|
+
quiet: bool = output.QuietOption,
|
|
23
|
+
) -> None:
|
|
24
|
+
"""List all configuration values.
|
|
25
|
+
|
|
26
|
+
Example: {cli} config list --json
|
|
27
|
+
"""
|
|
28
|
+
start = Path(ctx.obj.get("project") or Path.cwd())
|
|
29
|
+
root = services.require_project_root(start)
|
|
30
|
+
config = services.load_config(root)
|
|
31
|
+
data = config.model_dump()
|
|
32
|
+
output.emit_success(ctx, data, render_human=lambda d: output.human.key_values("Config", d))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@app.command("get")
|
|
36
|
+
@output.guard
|
|
37
|
+
def get_config(
|
|
38
|
+
ctx: typer.Context,
|
|
39
|
+
key: str = typer.Argument(..., help="Dotted config key, e.g. cli.min_version (see `config list`)."),
|
|
40
|
+
json_output: bool = output.JsonOption,
|
|
41
|
+
quiet: bool = output.QuietOption,
|
|
42
|
+
) -> None:
|
|
43
|
+
"""Get a single configuration value.
|
|
44
|
+
|
|
45
|
+
Example: {cli} config get cli.min_version
|
|
46
|
+
"""
|
|
47
|
+
start = Path(ctx.obj.get("project") or Path.cwd())
|
|
48
|
+
root = services.require_project_root(start)
|
|
49
|
+
value: object = services.load_config(root).model_dump()
|
|
50
|
+
for part in key.split("."):
|
|
51
|
+
if not isinstance(value, dict) or part not in value:
|
|
52
|
+
raise InvalidArguments(f"Unknown config key '{key}'.")
|
|
53
|
+
value = value[part]
|
|
54
|
+
output.emit_success(
|
|
55
|
+
ctx, {"key": key, "value": value}, render_human=lambda d: output.human.echo(f"{d['key']} = {d['value']}")
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@app.command("set")
|
|
60
|
+
@output.guard
|
|
61
|
+
def set_config(
|
|
62
|
+
ctx: typer.Context,
|
|
63
|
+
key: str = typer.Argument(..., help="Dotted config key, e.g. cli.min_version (see `config list`)."),
|
|
64
|
+
value: str = typer.Argument(..., help="New value (stored as a string)."),
|
|
65
|
+
json_output: bool = output.JsonOption,
|
|
66
|
+
quiet: bool = output.QuietOption,
|
|
67
|
+
) -> None:
|
|
68
|
+
"""Set a single, non-secret configuration value.
|
|
69
|
+
|
|
70
|
+
Example: {cli} config set cli.min_version 0.2.0
|
|
71
|
+
"""
|
|
72
|
+
start = Path(ctx.obj.get("project") or Path.cwd())
|
|
73
|
+
root = services.require_project_root(start)
|
|
74
|
+
data = services.load_config(root).model_dump()
|
|
75
|
+
parts = key.split(".")
|
|
76
|
+
target = data
|
|
77
|
+
for part in parts[:-1]:
|
|
78
|
+
if not isinstance(target, dict) or part not in target:
|
|
79
|
+
raise InvalidArguments(f"Unknown config key '{key}'.")
|
|
80
|
+
target = target[part]
|
|
81
|
+
if not isinstance(target, dict) or parts[-1] not in target:
|
|
82
|
+
raise InvalidArguments(f"Unknown config key '{key}'.")
|
|
83
|
+
target[parts[-1]] = value
|
|
84
|
+
services.save_config(root, ProjectConfig.model_validate(data))
|
|
85
|
+
output.emit_success(
|
|
86
|
+
ctx, {"key": key, "value": value}, render_human=lambda d: output.human.echo(f"Set {d['key']} = {d['value']}")
|
|
87
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""The `describe` command: the machine-readable description (OpenCLI document) of this CLI for agents."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
from .. import output
|
|
10
|
+
from ..core import opencli
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@output.guard
|
|
14
|
+
def describe(
|
|
15
|
+
ctx: typer.Context,
|
|
16
|
+
json_output: bool = output.JsonOption,
|
|
17
|
+
quiet: bool = output.QuietOption,
|
|
18
|
+
verbose: bool = output.VerboseOption,
|
|
19
|
+
) -> None:
|
|
20
|
+
"""Print this CLI's machine-readable contract: an OpenCLI document (opencli.org).
|
|
21
|
+
|
|
22
|
+
Commands, options, arguments, exit codes, plus `x-rb-*` metadata: env vars,
|
|
23
|
+
tables, v1 views, data files, external programs. With --json it is the bare
|
|
24
|
+
document on one line (no {"ok": ...} envelope); without, the same indented.
|
|
25
|
+
|
|
26
|
+
Example: {cli} describe --json
|
|
27
|
+
"""
|
|
28
|
+
document = opencli.document(ctx.find_root().command)
|
|
29
|
+
typer.echo(json.dumps(document, ensure_ascii=False, indent=None if ctx.obj.get("json") else 2))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def register(root: typer.Typer) -> None:
|
|
33
|
+
"""Add `describe` to the CLI's root (the describe part, copier's include_describe)."""
|
|
34
|
+
root.command(name="describe")(describe)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""The `doctor` command: checks of this CLI's own setup, one line per check."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from .. import output
|
|
8
|
+
from ..core import deps
|
|
9
|
+
from ..core.version import DEV_VERSION, installed_version, optional_module
|
|
10
|
+
|
|
11
|
+
_PACKAGE_NAME = __name__.split(".")[0]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@output.guard
|
|
15
|
+
def doctor(
|
|
16
|
+
ctx: typer.Context,
|
|
17
|
+
json_output: bool = output.JsonOption,
|
|
18
|
+
quiet: bool = output.QuietOption,
|
|
19
|
+
verbose: bool = output.VerboseOption,
|
|
20
|
+
) -> None:
|
|
21
|
+
"""Run diagnostic checks and report readiness.
|
|
22
|
+
|
|
23
|
+
Always exits 0 — the report itself is the result; `healthy` says
|
|
24
|
+
whether every check passed.
|
|
25
|
+
|
|
26
|
+
Example: {cli} doctor --json
|
|
27
|
+
"""
|
|
28
|
+
checks: list[dict] = [{"name": "python", "ok": True}]
|
|
29
|
+
checks.append({"name": "cli_version", "ok": True, "detail": installed_version() or DEV_VERSION})
|
|
30
|
+
|
|
31
|
+
if project := optional_module(f"{_PACKAGE_NAME}.commands.project"): # include_project=false drops it
|
|
32
|
+
checks.extend(project.doctor_checks(ctx))
|
|
33
|
+
|
|
34
|
+
if credentials := optional_module(f"{_PACKAGE_NAME}.credentials.health"): # include_auth=false drops it
|
|
35
|
+
checks.extend(credentials.doctor_checks())
|
|
36
|
+
checks.extend(deps.doctor_checks()) # [[tool.rb.external]] in pyproject.toml
|
|
37
|
+
if db := optional_module(f"{_PACKAGE_NAME}.core.db"): # include_db=false drops it at generation time
|
|
38
|
+
checks.extend(db.doctor_checks())
|
|
39
|
+
|
|
40
|
+
all_ok = all(check["ok"] for check in checks)
|
|
41
|
+
output.emit_success(
|
|
42
|
+
ctx, {"healthy": all_ok, "checks": checks}, render_human=lambda data: output.human.render_doctor(data["checks"])
|
|
43
|
+
)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
|
|
8
|
+
from .. import output
|
|
9
|
+
from ..core import services
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@output.guard
|
|
13
|
+
def fix(
|
|
14
|
+
ctx: typer.Context,
|
|
15
|
+
source: str = typer.Argument(..., help="Text file to fix, or '-' for stdin."),
|
|
16
|
+
profile: Path | None = typer.Option(
|
|
17
|
+
None, "--profile", help="Quality profile (quality.yml) with a `fixes` section. Without fixes: text unchanged."
|
|
18
|
+
),
|
|
19
|
+
text_format: str | None = typer.Option(
|
|
20
|
+
None, "--format", help="html or md. Default: md for .md/.markdown files, html otherwise (and for stdin)."
|
|
21
|
+
),
|
|
22
|
+
then_check: bool = typer.Option(
|
|
23
|
+
False, "--check", help="Run check on the fixed text and exit with its code (0 gate passed, 1 failed)."
|
|
24
|
+
),
|
|
25
|
+
json_output: bool = output.JsonOption,
|
|
26
|
+
quiet: bool = output.QuietOption,
|
|
27
|
+
) -> None:
|
|
28
|
+
"""Apply the profile's mechanical replacements (fixes) and print the fixed text.
|
|
29
|
+
|
|
30
|
+
Deterministic, no LLM: what to replace with what is in the profile, in
|
|
31
|
+
its order. Only the text a reader sees changes — HTML text nodes (tags,
|
|
32
|
+
attributes and block order stay byte for byte), md outside code; code,
|
|
33
|
+
pre, script, style, md code, link targets and bare URLs are never touched.
|
|
34
|
+
Default output: the fixed text on stdout, a summary on stderr. --json:
|
|
35
|
+
{ok, text, applied[{name, count, addresses}], unchanged}; with --check
|
|
36
|
+
also check's {issues, humanizer, gate_failed} and its exit code.
|
|
37
|
+
Exit 2: bad arguments or profile (INVALID_PROFILE) — no text is printed.
|
|
38
|
+
|
|
39
|
+
Example: {cli} fix article.html --profile typography.quality.yml --check --json
|
|
40
|
+
"""
|
|
41
|
+
text = sys.stdin.read() if source == "-" else services.read_text(Path(source))
|
|
42
|
+
payload, problem = services.run_fix(text, profile, services.text_format(source, text_format), then_check=then_check)
|
|
43
|
+
if not ctx.obj.get("json"):
|
|
44
|
+
output.human.write_text(payload["text"]) # the text is the data: printed even with --quiet
|
|
45
|
+
output.emit_report(ctx, payload, render_human=output.human.render_fix, problem=problem)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""The `init` command: create the project folder with its config file in the target directory."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
from .. import output
|
|
10
|
+
from ..core import services
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@output.guard
|
|
14
|
+
def init(
|
|
15
|
+
ctx: typer.Context,
|
|
16
|
+
name: str | None = typer.Option(None, "--name", help="Project name (defaults to directory name)."),
|
|
17
|
+
force: bool = typer.Option(False, "--force", help="Overwrite an already-initialized project's config."),
|
|
18
|
+
json_output: bool = output.JsonOption,
|
|
19
|
+
quiet: bool = output.QuietOption,
|
|
20
|
+
verbose: bool = output.VerboseOption,
|
|
21
|
+
) -> None:
|
|
22
|
+
"""Initialize a project: creates .{package}/config.toml in the target directory.
|
|
23
|
+
|
|
24
|
+
Example: {cli} init --name demo
|
|
25
|
+
"""
|
|
26
|
+
target = Path(ctx.obj.get("project") or Path.cwd()).resolve()
|
|
27
|
+
|
|
28
|
+
if not force and services.find_project_root(target) == target:
|
|
29
|
+
output.vecho(ctx, f"Found existing config at {services.config_path(target)}")
|
|
30
|
+
config = services.load_config(target)
|
|
31
|
+
output.emit_success(
|
|
32
|
+
ctx,
|
|
33
|
+
{"project": config.name, "path": str(target), "already_initialized": True},
|
|
34
|
+
render_human=lambda data: output.human.echo(
|
|
35
|
+
f"Already initialized in {data['path']} (use --force to reset)."
|
|
36
|
+
),
|
|
37
|
+
)
|
|
38
|
+
return
|
|
39
|
+
|
|
40
|
+
project_name = name or target.name
|
|
41
|
+
config = services.init_project(target, project_name)
|
|
42
|
+
output.emit_success(
|
|
43
|
+
ctx,
|
|
44
|
+
{"project": config.name, "path": str(target), "already_initialized": False},
|
|
45
|
+
render_human=lambda data: output.human.key_values(
|
|
46
|
+
f"Initialized project in {data['path']}", {"name": data["project"]}
|
|
47
|
+
),
|
|
48
|
+
)
|