Skip to content

Commit 67abc9c

Browse files
committed
CM-53667: improved logging and process
1 parent e3c46c7 commit 67abc9c

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

cycode/cli/files_collector/walk_ignore.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from cycode.cli.logger import get_logger
55
from cycode.cli.utils.ignore_utils import IgnoreFilterManager
66

7-
logger = get_logger('File Ignore')
7+
logger = get_logger('Ignores')
88

99
_SUPPORTED_IGNORE_PATTERN_FILES = {
1010
'.gitignore',
@@ -43,15 +43,17 @@ def walk_ignore(path: str) -> Generator[tuple[str, list[str], list[str]], None,
4343
global_ignore_file_paths=_collect_top_level_ignore_files(path),
4444
global_patterns=_DEFAULT_GLOBAL_IGNORE_PATTERNS,
4545
)
46-
4746
for dirpath, dirnames, filenames, ignored_dirnames, ignored_filenames in ignore_filter_manager.walk_with_ignored():
4847
rel_dirpath = '' if dirpath == path else os.path.relpath(dirpath, path)
4948
display_dir = rel_dirpath or '.'
50-
for kind, names in (
51-
('directory', ignored_dirnames),
52-
('file', ignored_filenames),
49+
for is_dir, names in (
50+
(True, ignored_dirnames),
51+
(False, ignored_filenames),
5352
):
5453
for name in names:
55-
logger.debug('Skipping matched %s %s/%s', kind, display_dir, name)
54+
full_path = os.path.join(path, display_dir, name)
55+
if is_dir:
56+
full_path = os.path.join(full_path, '*')
57+
logger.debug('Ignoring match %s', full_path)
5658

5759
yield dirpath, dirnames, filenames

cycode/cli/utils/ignore_utils.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,17 +399,25 @@ def walk_with_ignored(
399399
rel_dirpath = '' if dirpath == self.path else os.path.relpath(dirpath, self.path)
400400

401401
original_dirnames = list(dirnames)
402-
included_dirnames = [d for d in original_dirnames if not self.is_ignored(os.path.join(rel_dirpath, d))]
402+
included_dirnames = []
403+
ignored_dirnames = []
404+
for d in original_dirnames:
405+
if self.is_ignored(os.path.join(rel_dirpath, d)):
406+
ignored_dirnames.append(d)
407+
else:
408+
included_dirnames.append(d)
403409

404410
# decrease recursion depth of os.walk() by ignoring subdirectories because of topdown=True
405411
# slicing ([:]) is mandatory to change dict in-place!
406412
dirnames[:] = included_dirnames
407413

408-
ignored_dirnames = [d for d in original_dirnames if d not in included_dirnames]
409-
410-
original_filenames = list(filenames)
411-
included_filenames = [f for f in original_filenames if not self.is_ignored(os.path.join(rel_dirpath, f))]
412-
ignored_filenames = [f for f in original_filenames if f not in included_filenames]
414+
included_filenames = []
415+
ignored_filenames = []
416+
for f in filenames:
417+
if self.is_ignored(os.path.join(rel_dirpath, f)):
418+
ignored_filenames.append(f)
419+
else:
420+
included_filenames.append(f)
413421

414422
yield dirpath, dirnames, included_filenames, ignored_dirnames, ignored_filenames
415423

0 commit comments

Comments
 (0)