Skip to content

Commit f30fcc6

Browse files
Address code review feedback and improve documentation
Co-authored-by: danielmeppiel <51440732+danielmeppiel@users.noreply.github.com>
1 parent 9d47e04 commit f30fcc6

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/apm_cli/compilation/context_optimizer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ def _analyze_project_structure(self) -> None:
432432

433433
# Prune subdirectories from os.walk to avoid descending into excluded paths
434434
# This significantly improves performance by avoiding expensive traversal
435+
# Note: Modifying dirs[:] (slice assignment) is the standard Python idiom
436+
# to control which subdirectories os.walk will descend into
435437
dirs[:] = [d for d in dirs if not self._should_exclude_subdir(current_path / d)]
436438

437439
# Analyze files in this directory
@@ -520,8 +522,10 @@ def _matches_pattern(self, rel_path: Path, pattern: str) -> bool:
520522
Returns:
521523
True if path matches pattern, False otherwise
522524
"""
523-
# Normalize pattern to use forward slashes
524-
normalized_pattern = pattern.replace(os.sep, '/')
525+
# Normalize both pattern and path to use forward slashes for consistent matching
526+
# This handles Windows paths (backslashes) and Unix paths (forward slashes)
527+
# Users can provide patterns with either separator
528+
normalized_pattern = pattern.replace('\\', '/').replace(os.sep, '/')
525529

526530
# Convert path to string with forward slashes
527531
rel_path_str = str(rel_path).replace(os.sep, '/')
@@ -567,6 +571,8 @@ def _match_glob_recursive(self, path_parts: list, pattern_parts: list) -> bool:
567571

568572
if not path_parts:
569573
# Check if remaining pattern parts are all ** or empty
574+
# Empty parts can occur from patterns like "foo/" which split to ['foo', '']
575+
# or from consecutive slashes like "foo//bar"
570576
return all(p == '**' or p == '' for p in pattern_parts)
571577

572578
pattern_part = pattern_parts[0]

0 commit comments

Comments
 (0)