Optimize scancode ignore pattern size using wildcards#288
Conversation
📝 WalkthroughWalkthroughThe scanner now normalizes custom exclusions into path-aware ignore patterns, applies coarse ignores while walking directories, skips covered files, and passes exclusion configuration through the CLI scan invocation. ChangesScan exclusion flow
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant run_scan
participant FileSystemWalk
participant check_binary
CLI->>run_scan: path_to_exclude and scan options
run_scan->>FileSystemWalk: traverse with coarse patterns
FileSystemWalk->>run_scan: uncovered files
run_scan->>check_binary: inspect candidate files
check_binary->>run_scan: binary result
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
f9e24ec to
b343fe5
Compare
Signed-off-by: Park Wonjae <wonjae.park@lge.com>
63be6ee to
f2aa083
Compare
Signed-off-by: Park Wonjae <wonjae.park@lge.com>
f2aa083 to
9df5b7f
Compare
2a12273 to
78d419c
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
src/fosslight_source/run_scancode.py (3)
294-298: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSilently swallowed
check_binaryerrors. Ruff flags the blindexcept Exception: continue(BLE001, S112). The safe fallback (treat as non-binary, keep scanning) is fine, but logging at debug helps diagnose why files were skipped.♻️ Optional
- try: - if not check_binary(full_path, True): - continue - except Exception: - continue + try: + if not check_binary(full_path, True): + continue + except Exception as ex: + logger.debug(f"check_binary failed for {rel_path}: {ex}") + continue🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/fosslight_source/run_scancode.py` around lines 294 - 298, Update the exception handler around check_binary in the scanning loop to catch the error as an exception variable and log it at debug level before continuing; preserve the existing fallback of treating the file as non-binary and continuing the scan.Source: Linters/SAST tools
279-286: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDirectory-coverage probe via
+ "/a"is a bit cryptic. Appending a synthetic child so**/dir/**patterns match works, but it is non-obvious. A short inline comment explaining the intent would help future maintainers.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/fosslight_source/run_scancode.py` around lines 279 - 286, Add a brief inline comment in the directory filtering logic within the os.walk loop explaining that the synthetic “/a” child probes directory contents so recursive coarse-ignore patterns such as “**/dir/**” match correctly.
110-113: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid mutable default argument. Ruff flags
path_to_exclude: list = [](B006). Not mutated today, but useNoneand normalize inside to prevent shared-state surprises and satisfy the linter.♻️ Proposed fix
def _default_scancode_coarse_ignore_patterns( - path_to_exclude: list = [], + path_to_exclude: list = None, abs_path_to_scan: str = "" ) -> frozenset:(the existing
path_to_exclude or []at Line 127 already handlesNone.)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/fosslight_source/run_scancode.py` around lines 110 - 113, Update _default_scancode_coarse_ignore_patterns to use None instead of [] for the path_to_exclude default, and retain or add normalization to an empty list inside the function before iterating, leveraging the existing path_to_exclude or [] handling.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/fosslight_source/run_scancode.py`:
- Around line 173-183: Single-file custom exclusions are incorrectly converted
to extension-wide wildcard patterns, excluding unintended files. In the
exclusion-pattern construction logic, preserve path-specific patterns for
explicit user-provided files in both branches, and only generate *.<ext>
patterns for auto-discovered binary_paths exclusions; use the relevant
binary-path classification or source flag to distinguish these cases.
- Around line 94-97: Relativize absolute exclude paths before coarse ignore
matching so they align with the relative paths produced by os.walk(). Update the
logic around _default_scancode_coarse_ignore_patterns() and
_normalize_custom_pattern() to convert each absolute -e path relative to
abs_path_to_scan before generating directory patterns, while preserving existing
handling for relative excludes.
---
Nitpick comments:
In `@src/fosslight_source/run_scancode.py`:
- Around line 294-298: Update the exception handler around check_binary in the
scanning loop to catch the error as an exception variable and log it at debug
level before continuing; preserve the existing fallback of treating the file as
non-binary and continuing the scan.
- Around line 279-286: Add a brief inline comment in the directory filtering
logic within the os.walk loop explaining that the synthetic “/a” child probes
directory contents so recursive coarse-ignore patterns such as “**/dir/**” match
correctly.
- Around line 110-113: Update _default_scancode_coarse_ignore_patterns to use
None instead of [] for the path_to_exclude default, and retain or add
normalization to an empty list inside the function before iterating, leveraging
the existing path_to_exclude or [] handling.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a88b3031-1a7f-440b-ba11-cb768b83dd05
📒 Files selected for processing (2)
src/fosslight_source/cli.pysrc/fosslight_source/run_scancode.py
…walk Consolidate custom exclude handling into coarse patterns once, compress binary paths by extension, and cache exclude filters during os.walk to keep ignore_tuple small and avoid redundant is_included calls.
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
Avoid adding redundant per-file ignore paths when a custom exclude already matches a default exclude extension covered by *.ext patterns.
Description
Optimize the performance of Scancode's pre-scan tree traversal by reducing the size of the ignore pattern tuple.
Key Changes
png,jpg,exe,mp3) into*.extensionwildcard patterns.-eoption from expanding into the ignore tuple by adding user-specified custom exclude patterns directly tocoarse_patterns.-einput from the CLI torun_scanascustom_exclude_patternsparameter.