Merge pull request #66 from JulienPalard/mdk-no-default-personal-dict
Don't force everyone to use French dictionary.
This commit is contained in:
commit
5f3e154a36
|
@ -26,6 +26,12 @@ class Checker(ABC):
|
||||||
"""Check an item in a `*.po` file."""
|
"""Check an item in a `*.po` file."""
|
||||||
return NotImplementedError
|
return NotImplementedError
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
"""Let any checker register argparse arguments."""
|
||||||
|
|
||||||
|
def configure(self, args):
|
||||||
|
"""Store the result of parse_args, to get back arguments from self.add_arguments."""
|
||||||
|
|
||||||
|
|
||||||
def replace_quotes(match):
|
def replace_quotes(match):
|
||||||
"""Replace match with « xxxxxxx »."""
|
"""Replace match with « xxxxxxx »."""
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
"""Checker for grammar errors."""
|
"""Checker for grammar errors."""
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from typing import Set
|
from pathlib import Path
|
||||||
|
from typing import Set, Optional
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import simplelogging
|
import simplelogging
|
||||||
|
@ -28,7 +29,6 @@ class GrammalecteChecker(Checker):
|
||||||
"""Initialiser."""
|
"""Initialiser."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.personal_dict: Set[str] = set()
|
self.personal_dict: Set[str] = set()
|
||||||
self.get_personal_dict()
|
|
||||||
|
|
||||||
def check_file(self, pofile: PoFile):
|
def check_file(self, pofile: PoFile):
|
||||||
"""Check a `*.po` file."""
|
"""Check a `*.po` file."""
|
||||||
|
@ -100,18 +100,28 @@ class GrammalecteChecker(Checker):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_personal_dict(self):
|
def _get_personal_dict(self, dict_path: str) -> None:
|
||||||
"""
|
if "://" in dict_path:
|
||||||
Add spelling white list.
|
download_request = requests.get(dict_path)
|
||||||
|
download_request.raise_for_status()
|
||||||
Based on
|
lines = download_request.text
|
||||||
https://raw.githubusercontent.com/python/python-docs-fr/3.9/dict
|
else:
|
||||||
"""
|
lines = Path(dict_path).read_text(encoding="UTF-8")
|
||||||
download_request = requests.get(
|
for line in lines.splitlines():
|
||||||
"https://raw.githubusercontent.com/python/python-docs-fr/3.9/dict"
|
|
||||||
)
|
|
||||||
download_request.raise_for_status()
|
|
||||||
for line in download_request.text.splitlines():
|
|
||||||
word = line.strip()
|
word = line.strip()
|
||||||
self.personal_dict.add(word)
|
self.personal_dict.add(word)
|
||||||
self.personal_dict.add(word.title())
|
self.personal_dict.add(word.title())
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument(
|
||||||
|
"--dict",
|
||||||
|
nargs="*",
|
||||||
|
dest="dicts",
|
||||||
|
help="Personal dict files or URLs. Should contain onw word per line.",
|
||||||
|
)
|
||||||
|
|
||||||
|
def configure(self, args):
|
||||||
|
"""Store the result of parse_args, to get back arguments from self.add_arguments."""
|
||||||
|
if args.dicts:
|
||||||
|
for dict_path in args.dicts:
|
||||||
|
self._get_personal_dict(dict_path)
|
||||||
|
|
|
@ -93,6 +93,10 @@ def main():
|
||||||
)
|
)
|
||||||
files.add_argument("--version", action="store_true", help="Return version")
|
files.add_argument("--version", action="store_true", help="Return version")
|
||||||
parser.add_argument("-c", "--color", action="store_true", help="color output")
|
parser.add_argument("-c", "--color", action="store_true", help="color output")
|
||||||
|
|
||||||
|
for checker in checkers:
|
||||||
|
checker.add_arguments(parser)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.version:
|
if args.version:
|
||||||
|
@ -128,6 +132,9 @@ def main():
|
||||||
path = args.input_path
|
path = args.input_path
|
||||||
pull_request_info = None
|
pull_request_info = None
|
||||||
|
|
||||||
|
for checker in checkers:
|
||||||
|
checker.configure(args)
|
||||||
|
|
||||||
errors, warnings = check_paths(path, pull_request_info=pull_request_info)
|
errors, warnings = check_paths(path, pull_request_info=pull_request_info)
|
||||||
if errors:
|
if errors:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
Loading…
Reference in New Issue