Skip to content

collect_files() in extract.py ignores .graphifyignore #188

Description

@Leo86868

Bug

collect_files() in extract.py does not filter files through .graphifyignore. This means _rebuild_code() in watch.py (which calls collect_files()) scans all files regardless of ignore patterns.

Meanwhile, detect() in detect.py correctly loads and applies .graphifyignore via _load_graphifyignore() + _is_ignored().

Impact

On a project with node_modules/ in .graphifyignore, collect_files() returns 40,272 files instead of 210. The resulting Louvain clustering takes ~17 minutes and produces a polluted graph.

Steps to Reproduce

  1. Create a project with a node_modules/ directory and a .graphifyignore containing node_modules/
  2. Run _rebuild_code(Path('.')) from graphify.watch
  3. Observe that collect_files() returns files from node_modules/

Expected Behavior

collect_files() should respect .graphifyignore the same way detect() does.

Suggested Fix

Have collect_files() accept an optional root parameter and call _load_graphifyignore(root) + _is_ignored() to filter results, similar to how detect() does it in detect.py lines 306-333.

Workaround

Monkey-patching collect_files before calling _rebuild_code:

from graphify.detect import _load_graphifyignore, _is_ignored
from graphify.extract import collect_files as _original
from graphify import extract as _mod

def _filtered(target, *, follow_symlinks=False):
    files = _original(target, follow_symlinks=follow_symlinks)
    root = target if target.is_dir() else target.parent
    patterns = _load_graphifyignore(root)
    return [f for f in files if not _is_ignored(f, root, patterns)] if patterns else files

_mod.collect_files = _filtered

Environment

  • graphify 0.4.6
  • Python 3.13
  • macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions