Skip to content

Commit

Permalink
Don't print config files by default
Browse files Browse the repository at this point in the history
  • Loading branch information
skangas committed Dec 16, 2022
1 parent d219e43 commit 1dc2904
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
13 changes: 8 additions & 5 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class QuietLevels:
DISABLED_FIXES = 4
NON_AUTOMATIC_FIXES = 8
FIXES = 16
CONFIG_FILES = 32


class GlobMatch:
Expand Down Expand Up @@ -475,14 +476,15 @@ def parse_options(
"--quiet-level",
action="store",
type=int,
default=2,
default=34,
help="bitmask that allows suppressing messages:\n"
"- 0: print all messages.\n"
"- 1: disable warnings about wrong encoding.\n"
"- 2: disable warnings about binary files.\n"
"- 4: omit warnings about automatic fixes that were disabled in the dictionary.\n" # noqa: E501
"- 8: don't print anything for non-automatic fixes.\n" # noqa: E501
"- 16: don't print the list of fixed files.\n"
"- 32: don't print configuration files.\n"
"As usual with bitmasks, these levels can be "
"combined; e.g. use 3 for levels 1+2, 7 for "
"1+2+4, 23 for 1+2+4+16, etc. "
Expand Down Expand Up @@ -994,10 +996,11 @@ def main(*args: str) -> int:
options, parser, used_cfg_files = parse_options(args)

# Report used config files
if len(used_cfg_files) > 0:
print("Used config files:")
for ifile, cfg_file in enumerate(used_cfg_files, start=1):
print(" %i: %s" % (ifile, cfg_file))
if not options.quiet_level & QuietLevels.CONFIG_FILES:
if len(used_cfg_files) > 0:
print("Used config files:")
for ifile, cfg_file in enumerate(used_cfg_files, start=1):
print(" %i: %s" % (ifile, cfg_file))

if options.regex and options.write_changes:
print(
Expand Down
29 changes: 29 additions & 0 deletions codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,35 @@ def test_uri_regex_def() -> None:
assert not uri_regex.findall(boilerplate % uri), uri


def test_quiet_option_32(
tmp_path: Path,
tmpdir: pytest.TempPathFactory,
capsys: pytest.CaptureFixture[str],
) -> None:
d = tmp_path / "files"
d.mkdir()
conf = str(tmp_path / "setup.cfg")
with open(conf, "w") as f:
# It must contain a "codespell" section.
f.write("[codespell]\n")
args = ("--config", conf)

# Config files should NOT be in output.
result = cs.main(str(d), *args, "--quiet-level=32", std=True)
assert isinstance(result, tuple)
code, stdout, _ = result
assert code == 0
assert "Used config files:" not in stdout

# Config files SHOULD be in output.
result = cs.main(str(d), *args, "--quiet-level=2", std=True)
assert isinstance(result, tuple)
code, stdout, _ = result
assert code == 0
assert "Used config files:" in stdout
assert "setup.cfg" in stdout


@pytest.mark.parametrize("kind", ("toml", "cfg"))
def test_config_toml(
tmp_path: Path,
Expand Down

0 comments on commit 1dc2904

Please sign in to comment.