Skip to content

Commit

Permalink
Don't force everyone to use French dictionary.
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienPalard committed Oct 13, 2021
1 parent 429ef81 commit 74a7c58
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
6 changes: 6 additions & 0 deletions padpo/checkers/baseclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def check_item(self, item: PoItem):
"""Check an item in a `*.po` file."""
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):
"""Replace match with « xxxxxxx »."""
Expand Down
38 changes: 24 additions & 14 deletions padpo/checkers/grammalecte.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Checker for grammar errors."""

import re
from typing import Set
from pathlib import Path
from typing import Set, Optional

import requests
import simplelogging
Expand All @@ -28,7 +29,6 @@ def __init__(self):
"""Initialiser."""
super().__init__()
self.personal_dict: Set[str] = set()
self.get_personal_dict()

def check_file(self, pofile: PoFile):
"""Check a `*.po` file."""
Expand Down Expand Up @@ -100,18 +100,28 @@ def filter_out_spelling_error(self, warning: GrammalecteMessage) -> bool:
return True
return False

def get_personal_dict(self):
"""
Add spelling white list.
Based on
https://raw.githubusercontent.com/python/python-docs-fr/3.9/dict
"""
download_request = requests.get(
"https://raw.githubusercontent.com/python/python-docs-fr/3.9/dict"
)
download_request.raise_for_status()
for line in download_request.text.splitlines():
def _get_personal_dict(self, dict_path: str) -> None:
if ":https://" in dict_path:
download_request = requests.get(dict_path)
download_request.raise_for_status()
lines = download_request.text
else:
lines = Path(dict_path).read_text(encoding="UTF-8")
for line in lines.splitlines():
word = line.strip()
self.personal_dict.add(word)
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)
7 changes: 7 additions & 0 deletions padpo/padpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def main():
)
files.add_argument("--version", action="store_true", help="Return version")
parser.add_argument("-c", "--color", action="store_true", help="color output")

for checker in checkers:
checker.add_arguments(parser)

args = parser.parse_args()

if args.version:
Expand Down Expand Up @@ -128,6 +132,9 @@ def main():
path = args.input_path
pull_request_info = None

for checker in checkers:
checker.configure(args)

errors, warnings = check_paths(path, pull_request_info=pull_request_info)
if errors:
sys.exit(1)

0 comments on commit 74a7c58

Please sign in to comment.