|
8 | 8 | import re |
9 | 9 | import sys |
10 | 10 | import traceback |
| 11 | +import warnings |
11 | 12 | from importlib.metadata import PackageNotFoundError, version |
12 | 13 | from logging.config import dictConfig |
13 | 14 | from pathlib import Path |
@@ -374,55 +375,61 @@ def process_file( |
374 | 375 | print(filename, file=sys.stderr) |
375 | 376 |
|
376 | 377 | try: |
377 | | - with LanguageTool( |
378 | | - language=args.language, |
379 | | - mother_tongue=args.mother_tongue, |
380 | | - remote_server=remote_server, |
381 | | - ) as lang_tool: |
382 | | - try: |
383 | | - text = get_input_text(filename, args) |
384 | | - except (UnicodeError, FileNotFoundError) as exception: |
385 | | - print_exception(exception, args.verbose) |
386 | | - return 0 |
| 378 | + with warnings.catch_warnings(): |
| 379 | + warnings.filterwarnings( |
| 380 | + "ignore", |
| 381 | + message="No scheme was specified in the URL", |
| 382 | + category=RuntimeWarning, |
| 383 | + ) |
| 384 | + with LanguageTool( |
| 385 | + language=args.language, |
| 386 | + mother_tongue=args.mother_tongue, |
| 387 | + remote_server=remote_server, |
| 388 | + ) as lang_tool: |
| 389 | + try: |
| 390 | + text = get_input_text(filename, args) |
| 391 | + except (UnicodeError, FileNotFoundError) as exception: |
| 392 | + print_exception(exception, args.verbose) |
| 393 | + return 0 |
387 | 394 |
|
388 | | - if not args.spell_check: |
389 | | - lang_tool.disable_spellchecking() |
| 395 | + if not args.spell_check: |
| 396 | + lang_tool.disable_spellchecking() |
390 | 397 |
|
391 | | - lang_tool.disabled_rules.update(args.disable) |
392 | | - lang_tool.enabled_rules.update(args.enable) |
393 | | - lang_tool.disabled_categories.update(args.disable_categories) |
394 | | - lang_tool.enabled_categories.update(args.enable_categories) |
395 | | - lang_tool.enabled_rules_only = args.enabled_only |
| 398 | + lang_tool.disabled_rules.update(args.disable) |
| 399 | + lang_tool.enabled_rules.update(args.enable) |
| 400 | + lang_tool.disabled_categories.update(args.disable_categories) |
| 401 | + lang_tool.enabled_categories.update(args.enable_categories) |
| 402 | + lang_tool.enabled_rules_only = args.enabled_only |
396 | 403 |
|
397 | | - if args.picky: |
398 | | - lang_tool.picky = True |
| 404 | + if args.picky: |
| 405 | + lang_tool.picky = True |
399 | 406 |
|
400 | | - if args.apply: |
401 | | - print(lang_tool.correct(text)) |
402 | | - return 0 |
| 407 | + if args.apply: |
| 408 | + print(lang_tool.correct(text)) |
| 409 | + return 0 |
403 | 410 |
|
404 | | - status = 0 |
405 | | - for match in lang_tool.check(text): |
406 | | - rule_id = match.rule_id |
| 411 | + status = 0 |
| 412 | + for match in lang_tool.check(text): |
| 413 | + rule_id = match.rule_id |
407 | 414 |
|
408 | | - replacement_text = ", ".join( |
409 | | - f"'{word}'" for word in match.replacements |
410 | | - ).strip() |
| 415 | + replacement_text = ", ".join( |
| 416 | + f"'{word}'" for word in match.replacements |
| 417 | + ).strip() |
411 | 418 |
|
412 | | - message = match.message |
| 419 | + message = match.message |
413 | 420 |
|
414 | | - # Messages that end with punctuation already include the |
415 | | - # suggestion. |
416 | | - if replacement_text and not message.endswith("?"): |
417 | | - message += " Suggestions: " + replacement_text |
| 421 | + # Messages that end with punctuation already include the |
| 422 | + # suggestion. |
| 423 | + if replacement_text and not message.endswith("?"): |
| 424 | + message += " Suggestions: " + replacement_text |
418 | 425 |
|
419 | | - line, column = match.get_line_and_column(text) |
| 426 | + line, column = match.get_line_and_column(text) |
420 | 427 |
|
421 | | - print(f"{filename}:{line}:{column}: {rule_id}: {message}") |
| 428 | + print(f"{filename}:{line}:{column}: {rule_id}: {message}") |
422 | 429 |
|
423 | | - status = 2 |
| 430 | + status = 2 |
424 | 431 |
|
425 | | - return status |
| 432 | + return status |
426 | 433 | except LanguageToolError as exception: |
427 | 434 | print_exception(exception, args.verbose) |
428 | 435 | return 0 |
|
0 commit comments