File tree Expand file tree Collapse file tree 5 files changed +32
-5
lines changed Expand file tree Collapse file tree 5 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -322,10 +322,7 @@ def build_dictionary_list(args):
322322 if not isinstance (args .dict , list ):
323323 return dict_list
324324
325- for d in args .dict :
326- dpath = Path (d )
327- if dpath .exists ():
328- dict_list .append (dpath )
325+ dict_list .extend (args .dict )
329326
330327 return dict_list
331328
Original file line number Diff line number Diff line change 55import logging
66import importlib .resources
77import spellchecker
8+ import requests
9+ import pathlib
810
911
1012def create_checker (dict_list : list [str ] = None ) -> spellchecker .SpellChecker :
@@ -22,13 +24,26 @@ def create_checker(dict_list: list[str] = None) -> spellchecker.SpellChecker:
2224 english_dict = str (lib_path ) + "/resources/en.json.gz"
2325 logger .info ("Loading English dictionary from: %s" , english_dict )
2426 checker .word_frequency .load_dictionary (english_dict )
27+ logger .info ("number of words: %s" , checker .word_frequency .unique_words )
2528
2629 # load the additional dictionaries
2730 if not isinstance (dict_list , list ):
2831 return checker
2932 if len (dict_list ) > 0 :
3033 for d in dict_list :
3134 logger .info ("Loading additional dictionary from: %s" , d )
32- checker .word_frequency .load_text_file (d )
35+ if type (d ) == pathlib .PosixPath :
36+ # assume it's a local file path
37+ checker .word_frequency .load_text_file (d )
38+ else :
39+ # load dictionary from URL
40+ if d .startswith ("http://" ) or d .startswith ("https://" ):
41+ response = requests .get (d )
42+ response .raise_for_status ()
43+ checker .word_frequency .load_text (response .text )
44+ else :
45+ # assume it's a local file path
46+ checker .word_frequency .load_text_file (d )
47+ logger .info ("number of words: %s" , checker .word_frequency .unique_words )
3348
3449 return checker
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ def create_parser():
6161 help = "File that contains words that will be ignored."
6262 " Argument can be passed multiple times."
6363 " File must contain 1 word per line." ,
64+ " Argument can also be a URL to a text file with words." ,
6465 )
6566
6667 parser .add_argument (
Original file line number Diff line number Diff line change 11comment_parser
22pyspellchecker
33bibtexparser
4+ requests
Original file line number Diff line number Diff line change @@ -96,6 +96,19 @@ def test_bibtex(self):
9696 )
9797 self .assertEqual (runresult .returncode , 0 , runresult .stdout )
9898
99+ def test_url (self ):
100+ """URL test"""
101+ runresult = subprocess .run (
102+ [
103+ "comment_spell_check" ,
104+ "--dict" ,
105+ "https://raw.githubusercontent.com/SimpleITK/SimpleITK/refs/heads/master/.github/workflows/additional_dictionary.txt" ,
106+ "../tests/urltest.py" ,
107+
108+ ],
109+ cwd = "comment_spell_check" ,
110+ stdout = subprocess .PIPE ,
111+ )
99112
100113if __name__ == "__main__" :
101114 unittest .main ()
You can’t perform that action at this time.
0 commit comments