|
24 | 24 | import os |
25 | 25 | import fnmatch |
26 | 26 | import glob |
27 | | -import argparse |
28 | 27 | import re |
29 | 28 | import unicodedata |
30 | 29 | import logging |
|
35 | 34 |
|
36 | 35 | from spellchecker import SpellChecker |
37 | 36 |
|
38 | | -try: |
39 | | - # This loads the modules from the installed package |
40 | | - from comment_spell_check.utils import bibtex_loader |
41 | | - from comment_spell_check.utils import create_checker |
42 | | - from comment_spell_check.utils import url_remove |
43 | | -except ImportError: |
44 | | - # This loads the modules from the source directory |
45 | | - from utils import bibtex_loader |
46 | | - from utils import create_checker |
47 | | - from utils import url_remove |
| 37 | + |
| 38 | +# Insert the root directory of the project to the system path |
| 39 | +current_script_path = os.path.abspath(__file__) |
| 40 | +parent_directory = os.path.dirname(current_script_path) |
| 41 | +sys.path.insert(0, parent_directory + "/../") |
| 42 | + |
| 43 | +from comment_spell_check.utils import parseargs |
| 44 | +from comment_spell_check.utils import bibtex_loader |
| 45 | +from comment_spell_check.utils import create_checker |
| 46 | +from comment_spell_check.utils import url_remove |
48 | 47 |
|
49 | 48 | __version__ = "unknown" |
50 | 49 |
|
@@ -313,129 +312,6 @@ def skip_check(name: str, skip_list: list[str] = None): |
313 | 312 | return False |
314 | 313 |
|
315 | 314 |
|
316 | | -def parse_args(): |
317 | | - """parse the command-line arguments.""" |
318 | | - parser = argparse.ArgumentParser() |
319 | | - |
320 | | - parser.add_argument("filenames", nargs="*") |
321 | | - |
322 | | - parser.add_argument( |
323 | | - "--brief", |
324 | | - "-b", |
325 | | - action="store_true", |
326 | | - default=False, |
327 | | - dest="brief", |
328 | | - help="Make output brief", |
329 | | - ) |
330 | | - |
331 | | - parser.add_argument( |
332 | | - "--verbose", |
333 | | - "-v", |
334 | | - action="store_true", |
335 | | - default=False, |
336 | | - dest="verbose", |
337 | | - help="Make output verbose", |
338 | | - ) |
339 | | - |
340 | | - parser.add_argument( |
341 | | - "--first", |
342 | | - "-f", |
343 | | - action="store_true", |
344 | | - default=False, |
345 | | - dest="first", |
346 | | - help="Show only first occurrence of a mispelling", |
347 | | - ) |
348 | | - |
349 | | - parser.add_argument( |
350 | | - "--vim", |
351 | | - "-V", |
352 | | - action="store_true", |
353 | | - default=False, |
354 | | - dest="vim", |
355 | | - help="Output results in vim command format", |
356 | | - ) |
357 | | - |
358 | | - parser.add_argument( |
359 | | - "--dict", |
360 | | - "-d", |
361 | | - "--ignore-words", |
362 | | - "-I", |
363 | | - action="append", |
364 | | - dest="dict", |
365 | | - help="File that contains words that will be ignored." |
366 | | - " Argument can be passed multiple times." |
367 | | - " File must contain 1 word per line.", |
368 | | - ) |
369 | | - |
370 | | - parser.add_argument( |
371 | | - "--exclude", |
372 | | - "-e", |
373 | | - action="append", |
374 | | - dest="exclude", |
375 | | - help="Specify regex for excluding files." |
376 | | - " Argument can be passed multiple times.", |
377 | | - ) |
378 | | - |
379 | | - parser.add_argument( |
380 | | - "--skip", |
381 | | - "-S", |
382 | | - action="append", |
383 | | - help="Comma-separated list of files to skip. It " |
384 | | - "accepts globs as well. E.g.: if you want " |
385 | | - "coment_spell_check.py to skip .eps and .txt files, " |
386 | | - 'you\'d give "*.eps,*.txt" to this option.' |
387 | | - " Argument can be passed multiple times.", |
388 | | - ) |
389 | | - |
390 | | - parser.add_argument( |
391 | | - "--prefix", |
392 | | - "-p", |
393 | | - action="append", |
394 | | - default=[], |
395 | | - dest="prefixes", |
396 | | - help="Add word prefix. Argument can be passed multiple times.", |
397 | | - ) |
398 | | - |
399 | | - parser.add_argument( |
400 | | - "--miss", |
401 | | - "-m", |
402 | | - action="store_true", |
403 | | - default=False, |
404 | | - dest="miss", |
405 | | - help="Only output the misspelt words", |
406 | | - ) |
407 | | - |
408 | | - parser.add_argument( |
409 | | - "--suffix", |
410 | | - "-s", |
411 | | - action="append", |
412 | | - default=[".h"], |
413 | | - dest="suffix", |
414 | | - help="File name suffix. Argument can be passed multiple times.", |
415 | | - ) |
416 | | - |
417 | | - parser.add_argument( |
418 | | - "--type", |
419 | | - "-t", |
420 | | - action="store", |
421 | | - default="", |
422 | | - dest="mime_type", |
423 | | - help="Set file mime type. File name suffix will be ignored.", |
424 | | - ) |
425 | | - |
426 | | - parser.add_argument( |
427 | | - "--bibtex", |
428 | | - action="append", |
429 | | - dest="bibtex", |
430 | | - help="Bibtex file to load for additional dictionary words.", |
431 | | - ) |
432 | | - |
433 | | - parser.add_argument("--version", action="version", version=f"{__version__}") |
434 | | - |
435 | | - args = parser.parse_args() |
436 | | - return args |
437 | | - |
438 | | - |
439 | 315 | def build_dictionary_list(args): |
440 | 316 | """build a list of dictionaries to use for spell checking.""" |
441 | 317 | dict_list = [] |
@@ -535,9 +411,8 @@ def setup_logger(args): |
535 | 411 | return logger |
536 | 412 |
|
537 | 413 |
|
538 | | -def main(): |
| 414 | +def comment_spell_check(args): |
539 | 415 | """comment_spell_check main function.""" |
540 | | - args = parse_args() |
541 | 416 | logger = setup_logger(args) |
542 | 417 |
|
543 | 418 | dict_list = build_dictionary_list(args) |
@@ -618,5 +493,10 @@ def main(): |
618 | 493 | sys.exit(len(bad_words)) |
619 | 494 |
|
620 | 495 |
|
| 496 | +def main(): |
| 497 | + parser = parseargs.create_parser() |
| 498 | + args = parseargs.parse_args() |
| 499 | + comment_spell_check(args) |
| 500 | + |
621 | 501 | if __name__ == "__main__": |
622 | 502 | main() |
0 commit comments