Skip to content

Commit 178de9d

Browse files
committed
CM-53667: improve ignore logging
1 parent ee30ee8 commit 178de9d

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python Debugger: Current File with Arguments",
9+
"type": "debugpy",
10+
"request": "launch",
11+
"program": "${file}",
12+
"console": "integratedTerminal",
13+
"args": "${command:pickArgs}"
14+
}
15+
]
16+
}

cycode/cli/files_collector/walk_ignore.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _collect_top_level_ignore_files(path: str) -> list[str]:
3030
for ignore_file in _SUPPORTED_IGNORE_PATTERN_FILES:
3131
ignore_file_path = os.path.join(dir_path, ignore_file)
3232
if os.path.exists(ignore_file_path):
33-
logger.debug('Apply top level ignore file: %s', ignore_file_path)
33+
logger.debug('Reading top level ignore file: %s', ignore_file_path)
3434
ignore_files.append(ignore_file_path)
3535
return ignore_files
3636

@@ -41,4 +41,15 @@ def walk_ignore(path: str) -> Generator[tuple[str, list[str], list[str]], None,
4141
global_ignore_file_paths=_collect_top_level_ignore_files(path),
4242
global_patterns=_DEFAULT_GLOBAL_IGNORE_PATTERNS,
4343
)
44-
yield from ignore_filter_manager.walk()
44+
45+
for dirpath, dirnames, filenames, ignored_dirnames, ignored_filenames in ignore_filter_manager.walk_with_ignored():
46+
rel_dirpath = '' if dirpath == path else os.path.relpath(dirpath, path)
47+
display_dir = rel_dirpath or '.'
48+
for kind, names in (
49+
('directory', ignored_dirnames),
50+
('file', ignored_filenames),
51+
):
52+
for name in names:
53+
logger.debug('Skipping ignore matched %s %s/%s', kind, display_dir, name)
54+
55+
yield dirpath, dirnames, filenames

cycode/cli/utils/ignore_utils.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
BinaryIO,
4646
Optional,
4747
Union,
48+
List,
49+
Dict,
4850
)
4951

5052

@@ -388,19 +390,30 @@ def is_ignored(self, path: str) -> Optional[bool]:
388390
return matches[-1].is_exclude
389391
return None
390392

391-
def walk(self, **kwargs) -> Generator[tuple[str, list[str], list[str]], None, None]:
392-
"""Wrap os.walk() without ignored files and subdirectories and kwargs are passed to walk."""
393+
def walk_with_ignored(
394+
self, **kwargs
395+
) -> Generator[tuple[str, list[str], list[str], list[str], list[str]], None, None]:
396+
"""Wrap os.walk() and also return lists of ignored directories and files.
397+
398+
Yields tuples: (dirpath, included_dirnames, included_filenames, ignored_dirnames, ignored_filenames)
399+
"""
393400
for dirpath, dirnames, filenames in os.walk(self.path, topdown=True, **kwargs):
394401
rel_dirpath = '' if dirpath == self.path else os.path.relpath(dirpath, self.path)
395402

403+
original_dirnames = list(dirnames)
404+
included_dirnames = [d for d in original_dirnames if not self.is_ignored(os.path.join(rel_dirpath, d))]
405+
396406
# decrease recursion depth of os.walk() by ignoring subdirectories because of topdown=True
397407
# slicing ([:]) is mandatory to change dict in-place!
398-
dirnames[:] = [d for d in dirnames if not self.is_ignored(os.path.join(rel_dirpath, d))]
408+
dirnames[:] = included_dirnames
409+
410+
ignored_dirnames = [d for d in original_dirnames if d not in included_dirnames]
399411

400-
# remove ignored files
401-
filenames = [f for f in filenames if not self.is_ignored(os.path.join(rel_dirpath, f))]
412+
original_filenames = list(filenames)
413+
included_filenames = [f for f in original_filenames if not self.is_ignored(os.path.join(rel_dirpath, f))]
414+
ignored_filenames = [f for f in original_filenames if f not in included_filenames]
402415

403-
yield dirpath, dirnames, filenames
416+
yield dirpath, dirnames, included_filenames, ignored_dirnames, ignored_filenames
404417

405418
@classmethod
406419
def build(

0 commit comments

Comments
 (0)