Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC/ENH: Clarify usage or configuration files and log about it #2552

Merged
merged 4 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ These are both equivalent to running::

codespell --quiet-level 3 --count --skip "*.po,*.ts,./src/3rdParty,./src/Test"

If several config files are present, they are read in the following order:

#. ``pyproject.toml`` (only if the ``tomli`` library is available)
sappelhoff marked this conversation as resolved.
Show resolved Hide resolved
#. ``setup.cfg``
#. ``.codespellrc``
#. any additional file supplied via ``--config``

If a codespell configuration is supplied in several of these files,
the configuration from the most recently read file overwrites previously
specified configurations.
DimitriPapadopoulos marked this conversation as resolved.
Show resolved Hide resolved

Any options specified in the command line will *override* options from the
config files.

Expand Down
15 changes: 14 additions & 1 deletion codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,21 @@ def parse_options(args):
with open(toml_file, 'rb') as f:
data = tomli.load(f).get('tool', {})
config.read_dict(data)
config.read(cfg_files)

# Report which config files are going to be used
used_cfg_files = []
for cfg_file in cfg_files:
_cfg = configparser.ConfigParser()
_cfg.read(cfg_file)
if _cfg.has_section('codespell'):
used_cfg_files.append(cfg_file)
if len(used_cfg_files) > 0:
print('Used config files:\n')
for ifile, cfg_file in enumerate(used_cfg_files):
print(' %i : %s' % (ifile, cfg_file))

# Use config files
config.read(cfg_files)
DimitriPapadopoulos marked this conversation as resolved.
Show resolved Hide resolved
if config.has_section('codespell'):
# Build a "fake" argv list using option name and value.
cfg_args = []
Expand Down