Skip to content

Commit b29b3b6

Browse files
committed
fix skipped count calculation
1 parent cb12577 commit b29b3b6

File tree

4 files changed

+66
-13
lines changed

4 files changed

+66
-13
lines changed

pylint/lint/expand_modules.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ def expand_modules(
8787
if _is_ignored_file(
8888
something, ignore_list, ignore_list_re, ignore_list_paths_re
8989
):
90+
result[something] = {
91+
"path": something,
92+
"name": "",
93+
"isarg": False,
94+
"basepath": something,
95+
"basename": "",
96+
"isignored": True,
97+
}
9098
continue
9199
module_package_path = discover_package_path(something, source_roots)
92100
additional_search_path = [".", module_package_path, *path]
@@ -138,6 +146,7 @@ def expand_modules(
138146
"isarg": True,
139147
"basepath": filepath,
140148
"basename": modname,
149+
"isignored": False,
141150
}
142151
has_init = (
143152
not (modname.endswith(".__init__") or modname == "__init__")
@@ -153,6 +162,14 @@ def expand_modules(
153162
if _is_in_ignore_list_re(
154163
os.path.basename(subfilepath), ignore_list_re
155164
) or _is_in_ignore_list_re(subfilepath, ignore_list_paths_re):
165+
result[subfilepath] = {
166+
"path": subfilepath,
167+
"name": "",
168+
"isarg": False,
169+
"basepath": subfilepath,
170+
"basename": "",
171+
"isignored": True,
172+
}
156173
continue
157174

158175
modpath = _modpath_from_file(
@@ -167,5 +184,6 @@ def expand_modules(
167184
"isarg": isarg,
168185
"basepath": filepath,
169186
"basename": modname,
187+
"isignored": False,
170188
}
171189
return result, errors

pylint/lint/pylinter.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ def __init__(
316316

317317
# Attributes related to stats
318318
self.stats = LinterStats()
319+
self.skipped_paths: set[str] = set()
319320

320321
# Attributes related to (command-line) options and their parsing
321322
self.options: Options = options + _make_linter_options(self)
@@ -614,31 +615,39 @@ def initialize(self) -> None:
614615
if not msg.may_be_emitted(self.config.py_version):
615616
self._msgs_state[msg.msgid] = False
616617

617-
def _discover_files(self, files_or_modules: Sequence[str]) -> Iterator[str]:
618+
def _discover_files(
619+
self, files_or_modules: Sequence[str], all_files: bool = False
620+
) -> Iterator[str]:
618621
"""Discover python modules and packages in sub-directory.
619622
623+
:param Sequence[str] files_or_modules: list of directories to explore
624+
:param str all_files: whether to return _all_ files, entering modules
625+
and not considering ignored paths
620626
Returns iterator of paths to discovered modules and packages.
621627
"""
622628
for something in files_or_modules:
623-
if os.path.isdir(something) and not os.path.isfile(
624-
os.path.join(something, "__init__.py")
625-
):
629+
if os.path.isdir(something):
630+
if not all_files and not os.path.isfile(
631+
os.path.join(something, "__init__.py")
632+
):
633+
continue
626634
skip_subtrees: list[str] = []
627635
for root, _, files in os.walk(something):
628636
if any(root.startswith(s) for s in skip_subtrees):
629637
# Skip subtree of already discovered package.
630638
continue
631639

632-
if _is_ignored_file(
640+
if not all_files and _is_ignored_file(
633641
root,
634642
self.config.ignore,
635643
self.config.ignore_patterns,
636644
self.config.ignore_paths,
637645
):
646+
self.skipped_paths.add(root)
638647
skip_subtrees.append(root)
639648
continue
640649

641-
if "__init__.py" in files:
650+
if not all_files and "__init__.py" in files:
642651
skip_subtrees.append(root)
643652
yield root
644653
else:
@@ -851,6 +860,7 @@ def _get_file_descr_from_stdin(self, filepath: str) -> Iterator[FileItem]:
851860
self.config.ignore_patterns,
852861
self.config.ignore_paths,
853862
):
863+
self.skipped_paths.add(filepath)
854864
return
855865

856866
try:
@@ -873,7 +883,9 @@ def _iterate_file_descrs(
873883
"""
874884
for descr in self._expand_files(files_or_modules).values():
875885
name, filepath, is_arg = descr["name"], descr["path"], descr["isarg"]
876-
if self.should_analyze_file(name, filepath, is_argument=is_arg):
886+
if descr["isignored"]:
887+
self.skipped_paths.add(filepath)
888+
elif self.should_analyze_file(name, filepath, is_argument=is_arg):
877889
yield FileItem(name, filepath, descr["basename"])
878890

879891
def _expand_files(
@@ -1100,6 +1112,7 @@ def generate_reports(self, verbose: bool = False) -> int | None:
11001112

11011113
if self.config.reports:
11021114
self.reporter.display_reports(sect)
1115+
11031116
score_value = self._report_evaluation(verbose)
11041117
# save results if persistent run
11051118
if self.config.persistent:
@@ -1143,8 +1156,11 @@ def _report_evaluation(self, verbose: bool = False) -> int | None:
11431156

11441157
if verbose:
11451158
checked_files_count = self.stats.node_count["module"]
1146-
unchecked_files_count = self.stats.undocumented["module"]
1147-
msg += f"\nChecked {checked_files_count} files, skipped {unchecked_files_count} files"
1159+
skipped_files = list(
1160+
self._discover_files(list(self.skipped_paths), all_files=True)
1161+
)
1162+
skipped_files_count = len(skipped_files)
1163+
msg += f"\nChecked {checked_files_count} files, skipped {skipped_files_count} files"
11481164

11491165
if self.config.score:
11501166
sect = report_nodes.EvaluationSection(msg)

pylint/typing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ModuleDescriptionDict(TypedDict):
5151
isarg: bool
5252
basepath: str
5353
basename: str
54+
isignored: bool
5455

5556

5657
class ErrorDescriptionDict(TypedDict):

tests/test_self.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,23 @@ def test_disable_all_enable_invalid(self) -> None:
241241

242242
def test_output_with_verbose(self) -> None:
243243
out = StringIO()
244-
self._runtest([UNNECESSARY_LAMBDA, "--verbose"], out=out, code=4)
245-
assert "Checked 1 files, skipped 0 files" in out.getvalue().strip()
244+
self._runtest(
245+
[
246+
UNNECESSARY_LAMBDA,
247+
join(
248+
HERE,
249+
"regrtest_data",
250+
"directory",
251+
"ignored_subdirectory",
252+
"failing.py",
253+
),
254+
"--ignore-paths=.*failing.*",
255+
"--verbose",
256+
],
257+
out=out,
258+
code=4,
259+
)
260+
assert "Checked 1 files, skipped 1 files" in out.getvalue().strip()
246261

247262
def test_no_out_encoding(self) -> None:
248263
"""Test redirection of stdout with non ascii characters."""
@@ -1104,7 +1119,7 @@ def test_fail_on_info_only_exit_code(self, args: list[str], expected: int) -> No
11041119
(
11051120
"colorized",
11061121
(
1107-
"{path}:4:4: W0612: \x1B[35mUnused variable 'variable'\x1B[0m (\x1B[35munused-variable\x1B[0m)"
1122+
"{path}:4:4: W0612: \x1b[35mUnused variable 'variable'\x1b[0m (\x1b[35munused-variable\x1b[0m)"
11081123
),
11091124
),
11101125
("json", '"message": "Unused variable \'variable\'",'),
@@ -1212,7 +1227,10 @@ def test_ignore_recursive(self, ignore_value: str) -> None:
12121227
test would fail due these errors.
12131228
"""
12141229
directory = join(HERE, "regrtest_data", "directory")
1215-
self._runtest([directory, "--recursive=y", f"--ignore={ignore_value}"], code=0)
1230+
self._runtest(
1231+
[directory, "--verbose", "--recursive=y", f"--ignore={ignore_value}"],
1232+
code=0,
1233+
)
12161234

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

0 commit comments

Comments
 (0)