Skip to content

Commit 9c34d92

Browse files
committed
only collect in parse, report in main
1 parent 2381c2b commit 9c34d92

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

codespell_lib/_codespell.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,13 @@ def parse_options(args):
424424
data = tomli.load(f).get('tool', {})
425425
config.read_dict(data)
426426

427-
# Report which config files are going to be used
427+
# Collect which config files are going to be used
428428
used_cfg_files = []
429429
for cfg_file in cfg_files:
430430
_cfg = configparser.ConfigParser()
431431
_cfg.read(cfg_file)
432432
if _cfg.has_section('codespell'):
433433
used_cfg_files.append(cfg_file)
434-
if len(used_cfg_files) > 0:
435-
print('Used config files:\n')
436-
for ifile, cfg_file in enumerate(used_cfg_files):
437-
print(' %i : %s' % (ifile, cfg_file))
438434

439435
# Use config files
440436
config.read(cfg_files)
@@ -458,7 +454,7 @@ def parse_options(args):
458454
if not options.files:
459455
options.files.append('.')
460456

461-
return options, parser
457+
return options, parser, used_cfg_files
462458

463459

464460
def parse_ignore_words_option(ignore_words_option):
@@ -789,7 +785,13 @@ def _script_main():
789785

790786
def main(*args):
791787
"""Contains flow control"""
792-
options, parser = parse_options(args)
788+
options, parser, used_cfg_files = parse_options(args)
789+
790+
# Report used config files
791+
if len(used_cfg_files) > 0:
792+
print('Used config files:')
793+
for ifile, cfg_file in enumerate(used_cfg_files, start=1):
794+
print(' %i: %s' % (ifile, cfg_file))
793795

794796
if options.regex and options.write_changes:
795797
print("ERROR: --write-changes cannot be used together with "

0 commit comments

Comments
 (0)