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

[Backport maintenance/3.3.x] fix "skipped files" count calculation #10175

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/10073.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixes "skipped files" count calculation; the previous method was displaying an arbitrary number.

Closes #10073
18 changes: 18 additions & 0 deletions pylint/lint/expand_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ def expand_modules(
if _is_ignored_file(
something, ignore_list, ignore_list_re, ignore_list_paths_re
):
result[something] = {
"path": something,
"name": "",
"isarg": False,
"basepath": something,
"basename": "",
"isignored": True,
}
continue
module_package_path = discover_package_path(something, source_roots)
additional_search_path = [".", module_package_path, *path]
Expand Down Expand Up @@ -138,6 +146,7 @@ def expand_modules(
"isarg": True,
"basepath": filepath,
"basename": modname,
"isignored": False,
}
has_init = (
not (modname.endswith(".__init__") or modname == "__init__")
Expand All @@ -153,6 +162,14 @@ def expand_modules(
if _is_in_ignore_list_re(
os.path.basename(subfilepath), ignore_list_re
) or _is_in_ignore_list_re(subfilepath, ignore_list_paths_re):
result[subfilepath] = {
"path": subfilepath,
"name": "",
"isarg": False,
"basepath": subfilepath,
"basename": "",
"isignored": True,
}
continue

modpath = _modpath_from_file(
Expand All @@ -167,5 +184,6 @@ def expand_modules(
"isarg": isarg,
"basepath": filepath,
"basename": modname,
"isignored": False,
}
return result, errors
9 changes: 6 additions & 3 deletions pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ def _get_file_descr_from_stdin(self, filepath: str) -> Iterator[FileItem]:
self.config.ignore_patterns,
self.config.ignore_paths,
):
self.stats.skipped += 1
return

try:
Expand All @@ -873,7 +874,9 @@ def _iterate_file_descrs(
"""
for descr in self._expand_files(files_or_modules).values():
name, filepath, is_arg = descr["name"], descr["path"], descr["isarg"]
if self.should_analyze_file(name, filepath, is_argument=is_arg):
if descr["isignored"]:
self.stats.skipped += 1
elif self.should_analyze_file(name, filepath, is_argument=is_arg):
yield FileItem(name, filepath, descr["basename"])

def _expand_files(
Expand Down Expand Up @@ -1100,6 +1103,7 @@ def generate_reports(self, verbose: bool = False) -> int | None:

if self.config.reports:
self.reporter.display_reports(sect)

score_value = self._report_evaluation(verbose)
# save results if persistent run
if self.config.persistent:
Expand Down Expand Up @@ -1143,8 +1147,7 @@ def _report_evaluation(self, verbose: bool = False) -> int | None:

if verbose:
checked_files_count = self.stats.node_count["module"]
unchecked_files_count = self.stats.undocumented["module"]
msg += f"\nChecked {checked_files_count} files, skipped {unchecked_files_count} files"
msg += f"\nChecked {checked_files_count} files, skipped {self.stats.skipped} files/modules"

if self.config.score:
sect = report_nodes.EvaluationSection(msg)
Expand Down
1 change: 1 addition & 0 deletions pylint/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ModuleDescriptionDict(TypedDict):
isarg: bool
basepath: str
basename: str
isignored: bool


class ErrorDescriptionDict(TypedDict):
Expand Down
3 changes: 3 additions & 0 deletions pylint/utils/linterstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def __init__(
self.refactor = 0
self.statement = 0
self.warning = 0
self.skipped = 0

self.global_note = 0
self.nb_duplicated_lines = 0
Expand All @@ -151,6 +152,7 @@ def __str__(self) -> str:
{self.refactor}
{self.statement}
{self.warning}
{self.skipped}
{self.global_note}
{self.nb_duplicated_lines}
{self.percent_duplicated_lines}"""
Expand Down Expand Up @@ -385,6 +387,7 @@ def merge_stats(stats: list[LinterStats]) -> LinterStats:
merged.refactor += stat.refactor
merged.statement += stat.statement
merged.warning += stat.warning
merged.skipped += stat.skipped

merged.global_note += stat.global_note
return merged
14 changes: 13 additions & 1 deletion tests/lint/unittest_expand_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test__is_in_ignore_list_re_match() -> None:
"isarg": True,
"name": "lint.unittest_expand_modules",
"path": EXPAND_MODULES,
"isignored": False,
}

this_file_relative_to_parent = {
Expand All @@ -48,6 +49,7 @@ def test__is_in_ignore_list_re_match() -> None:
"isarg": True,
"name": "lint.unittest_expand_modules",
"path": EXPAND_MODULES_BASE,
"isignored": False,
}

this_file_from_init = {
Expand All @@ -56,6 +58,7 @@ def test__is_in_ignore_list_re_match() -> None:
"isarg": False,
"name": "lint.unittest_expand_modules",
"path": EXPAND_MODULES,
"isignored": False,
}

this_file_from_init_deduplicated = {
Expand All @@ -64,6 +67,7 @@ def test__is_in_ignore_list_re_match() -> None:
"isarg": True,
"name": "lint.unittest_expand_modules",
"path": EXPAND_MODULES,
"isignored": False,
}

unittest_lint = {
Expand All @@ -72,6 +76,7 @@ def test__is_in_ignore_list_re_match() -> None:
"isarg": False,
"name": "lint.unittest_lint",
"path": str(TEST_DIRECTORY / "lint/unittest_lint.py"),
"isignored": False,
}

test_utils = {
Expand All @@ -80,6 +85,7 @@ def test__is_in_ignore_list_re_match() -> None:
"isarg": False,
"name": "lint.test_utils",
"path": str(TEST_DIRECTORY / "lint/test_utils.py"),
"isignored": False,
}

test_run_pylint = {
Expand All @@ -88,6 +94,7 @@ def test__is_in_ignore_list_re_match() -> None:
"isarg": False,
"name": "lint.test_run_pylint",
"path": str(TEST_DIRECTORY / "lint/test_run_pylint.py"),
"isignored": False,
}

test_pylinter = {
Expand All @@ -96,6 +103,7 @@ def test__is_in_ignore_list_re_match() -> None:
"isarg": False,
"name": "lint.test_pylinter",
"path": str(TEST_DIRECTORY / "lint/test_pylinter.py"),
"isignored": False,
}

test_caching = {
Expand All @@ -104,6 +112,7 @@ def test__is_in_ignore_list_re_match() -> None:
"isarg": False,
"name": "lint.test_caching",
"path": str(TEST_DIRECTORY / "lint/test_caching.py"),
"isignored": False,
}

init_of_package = {
Expand All @@ -112,6 +121,7 @@ def test__is_in_ignore_list_re_match() -> None:
"isarg": True,
"name": "lint",
"path": INIT_PATH,
"isignored": False,
}

# A directory that is not a python package.
Expand All @@ -123,13 +133,15 @@ def test__is_in_ignore_list_re_match() -> None:
"isarg": False,
"basepath": str(REPORTERS_PATH / "__init__.py"),
"basename": "reporters",
"isignored": False,
},
str(REPORTERS_PATH / "unittest_reporting.py"): {
"path": str(REPORTERS_PATH / "unittest_reporting.py"),
"name": "reporters.unittest_reporting",
"isarg": False,
"basepath": str(REPORTERS_PATH / "__init__.py"),
"basename": "reporters",
"isignored": False,
},
}

Expand Down Expand Up @@ -304,5 +316,5 @@ def test_expand_modules_with_ignore(
ignore_list_re,
self.linter.config.ignore_paths,
)
assert modules == expected
assert {k: v for k, v in modules.items() if not v["isignored"]} == expected
assert not errors
26 changes: 22 additions & 4 deletions tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,23 @@ def test_disable_all_enable_invalid(self) -> None:

def test_output_with_verbose(self) -> None:
out = StringIO()
self._runtest([UNNECESSARY_LAMBDA, "--verbose"], out=out, code=4)
assert "Checked 1 files, skipped 0 files" in out.getvalue().strip()
self._runtest(
[
UNNECESSARY_LAMBDA,
join(
HERE,
"regrtest_data",
"directory",
"ignored_subdirectory",
"failing.py",
),
"--ignore-paths=.*failing.*",
"--verbose",
],
out=out,
code=4,
)
assert "Checked 1 files, skipped 1 files/modules" in out.getvalue().strip()

def test_no_out_encoding(self) -> None:
"""Test redirection of stdout with non ascii characters."""
Expand Down Expand Up @@ -1104,7 +1119,7 @@ def test_fail_on_info_only_exit_code(self, args: list[str], expected: int) -> No
(
"colorized",
(
"{path}:4:4: W0612: \x1B[35mUnused variable 'variable'\x1B[0m (\x1B[35munused-variable\x1B[0m)"
"{path}:4:4: W0612: \x1b[35mUnused variable 'variable'\x1b[0m (\x1b[35munused-variable\x1b[0m)"
),
),
("json", '"message": "Unused variable \'variable\'",'),
Expand Down Expand Up @@ -1212,7 +1227,10 @@ def test_ignore_recursive(self, ignore_value: str) -> None:
test would fail due these errors.
"""
directory = join(HERE, "regrtest_data", "directory")
self._runtest([directory, "--recursive=y", f"--ignore={ignore_value}"], code=0)
self._runtest(
[directory, "--verbose", "--recursive=y", f"--ignore={ignore_value}"],
code=0,
)

@pytest.mark.parametrize("ignore_pattern_value", ["ignored_.*", "failing.*"])
def test_ignore_pattern_recursive(self, ignore_pattern_value: str) -> None:
Expand Down
Loading