MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / main

Function main

scripts/developer-guide/run_languagetool.py:542–607  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

540
541
542def main():
543 parser = argparse.ArgumentParser(description=__doc__)
544 parser.add_argument("--html", required=True, help="Rendered HTML input")
545 parser.add_argument("--output", required=True, help="JSON output path")
546 parser.add_argument("--language", default="en-US")
547 parser.add_argument(
548 "--accept-list",
549 default=os.path.join(
550 os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))),
551 "docs",
552 "developer-guide",
553 "languagetool-accept.txt",
554 ),
555 help="Path to the LanguageTool accept-list file (one regex per line).",
556 )
557 args = parser.parse_args()
558
559 text = extract_text(args.html)
560 accept_re = load_accept_patterns(args.accept_list)
561
562 report = {"status": "unknown", "matches": [], "total": 0}
563 try:
564 try:
565 matches = run_languagetool(text, language=args.language, accept_re=accept_re)
566 except Exception as exc: # noqa: BLE001 — advisory check must not crash CI
567 print(f"LanguageTool failed to start: {exc}", file=sys.stderr)
568 report = {"status": "error", "reason": str(exc), "matches": [], "total": 0}
569 else:
570 if matches is None:
571 report = {
572 "status": "skipped",
573 "reason": "language_tool_python not installed",
574 "matches": [],
575 "total": 0,
576 }
577 else:
578 try:
579 serialized = matches_to_json(matches, text)
580 except Exception as exc: # noqa: BLE001
581 print(
582 f"LanguageTool: failed to serialize {len(matches)} match(es): {exc}",
583 file=sys.stderr,
584 )
585 report = {
586 "status": "error",
587 "reason": f"serialization failed: {exc}",
588 "matches": [],
589 "total": len(matches),
590 }
591 else:
592 report = {"status": "ok", "matches": serialized, "total": len(serialized)}
593 finally:
594 os.makedirs(os.path.dirname(args.output) or ".", exist_ok=True)
595 with open(args.output, "w", encoding="utf-8") as fh:
596 json.dump(report, fh, indent=2)
597 print(
598 f"LanguageTool report written to {args.output} "
599 f"({report.get('total', 0)} match(es), status={report.get('status')})."

Callers 1

Calls 7

extract_textFunction · 0.85
load_accept_patternsFunction · 0.85
run_languagetoolFunction · 0.85
matches_to_jsonFunction · 0.85
joinMethod · 0.65
dumpMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected