fix(extract): report paths skipped by ignore rules
Refs #4965
(cherry picked from commit 71958934cf)
This commit is contained in:
1 parent
a328198f84
commit
90e1b5f343
3 files changed
+146
No files matched your search
@@ -385,6 +385,12 @@ See the [full command reference](#full-command-reference) below.
|
||||
|
||||
graphify honors `.gitignore` and supports `--exclude` patterns and a project `.graphifyignore`. Details: **[Configuration](https://docs.graphify.com/reference/configuration)**.
|
||||
|
||||
`graphify extract` reports paths skipped by ignore rules, with up to three sorted examples relative to
|
||||
the scan root. Each pruned directory counts once; its contents are not enumerated. Default noise
|
||||
directories such as `node_modules` are excluded from this summary. If source is missing, review the
|
||||
ignore rules. `--no-gitignore` bypasses VCS ignore rules only; `.graphifyignore` and `--exclude`
|
||||
remain effective.
|
||||
|
||||
|
||||
## Project configuration
|
||||
|
||||
|
||||
@@ -4221,6 +4221,28 @@ def dispatch_command(cmd: str) -> None:
|
||||
f"{len(doc_files)} docs, {len(paper_files)} papers, "
|
||||
f"{len(image_files)} images"
|
||||
)
|
||||
_ignored = sorted(detection.get("ignored", []))
|
||||
if _ignored:
|
||||
# 目录记录代表剪枝边界,不能为统计或展示而下钻。
|
||||
_examples = []
|
||||
for _entry in _ignored[:3]:
|
||||
_rel = Path(os.path.relpath(_entry, target)).as_posix()
|
||||
if _entry.endswith(os.sep):
|
||||
_rel += "/"
|
||||
_examples.append(repr(_rel))
|
||||
_more = f" (+{len(_ignored) - 3} more)" if len(_ignored) > 3 else ""
|
||||
print(
|
||||
f"[graphify extract] {len(_ignored)} path(s) ignored by ignore rules "
|
||||
f"(pruned directories count once): {', '.join(_examples)}{_more}"
|
||||
)
|
||||
_vcs_hint = (
|
||||
"--no-gitignore bypasses VCS ignore rules only"
|
||||
if _effective_gitignore else "VCS ignore rules disabled"
|
||||
)
|
||||
print(
|
||||
f"[graphify extract] Review ignore rules if source is missing; {_vcs_hint}; "
|
||||
".graphifyignore and --exclude still apply."
|
||||
)
|
||||
# Surface files that were seen but not classified (extensionless non-shebang
|
||||
# project files like Dockerfile/Makefile, or unsupported extensions), so they
|
||||
# are no longer invisible in graphify's own output (#1692).
|
||||
|
||||
@@ -19,6 +19,124 @@ def _make_corpus(tmp_path):
|
||||
return tmp_path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ignored_nested_repo(monkeypatch, tmp_path):
|
||||
import subprocess
|
||||
|
||||
corpus = tmp_path / "corpus"
|
||||
nested = corpus / "nested"
|
||||
nested.mkdir(parents=True)
|
||||
monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1")
|
||||
monkeypatch.setenv("GIT_CONFIG_GLOBAL", os.devnull)
|
||||
for repo in (corpus, nested):
|
||||
subprocess.run(["git", "-C", str(repo), "init", "-q"], check=True)
|
||||
(nested / "tracked.py").write_text("def tracked():\n return 1\n", encoding="utf-8")
|
||||
subprocess.run(
|
||||
["git", "-C", str(nested), "add", "tracked.py"], check=True
|
||||
)
|
||||
(corpus / ".gitignore").write_text("nested/\n", encoding="utf-8")
|
||||
monkeypatch.setattr(mainmod, "_check_skill_version", lambda _: None)
|
||||
return corpus
|
||||
|
||||
|
||||
@pytest.mark.parametrize("has_visible_code", [False, True])
|
||||
def test_extract_reports_ignored_nested_tracked_repo(
|
||||
monkeypatch, tmp_path, capsys, ignored_nested_repo, has_visible_code
|
||||
):
|
||||
corpus = ignored_nested_repo
|
||||
if has_visible_code:
|
||||
(corpus / "keep.py").write_text("def keep():\n return 1\n", encoding="utf-8")
|
||||
real_scandir = os.scandir
|
||||
|
||||
def _guarded_scandir(path):
|
||||
from pathlib import Path
|
||||
|
||||
assert not Path(path).is_relative_to(corpus / "nested")
|
||||
return real_scandir(path)
|
||||
|
||||
monkeypatch.setattr(os, "scandir", _guarded_scandir)
|
||||
out = tmp_path / "output"
|
||||
_run_extract(monkeypatch, [
|
||||
"graphify", "extract", str(corpus), "--code-only", "--no-cluster",
|
||||
"--out", str(out),
|
||||
])
|
||||
text = capsys.readouterr().out
|
||||
assert "1 path(s) ignored by ignore rules" in text
|
||||
assert "pruned directories count once" in text
|
||||
assert "'nested/'" in text
|
||||
assert "--no-gitignore bypasses VCS ignore rules only" in text
|
||||
assert ".graphifyignore and --exclude still apply" in text
|
||||
assert "tracked.py" not in text
|
||||
graph = out / "graphify-out" / "graph.json"
|
||||
if graph.exists():
|
||||
assert "nested/tracked.py" not in _node_sources(graph)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("explicit_ignore", [None, "graphifyignore", "exclude"])
|
||||
def test_extract_no_gitignore_summary_respects_explicit_rules(
|
||||
monkeypatch, tmp_path, capsys, ignored_nested_repo, explicit_ignore
|
||||
):
|
||||
corpus = ignored_nested_repo
|
||||
args = ["--no-gitignore"]
|
||||
if explicit_ignore == "graphifyignore":
|
||||
(corpus / ".graphifyignore").write_text("nested/\n", encoding="utf-8")
|
||||
elif explicit_ignore == "exclude":
|
||||
args += ["--exclude", "nested/"]
|
||||
out = tmp_path / "output"
|
||||
_run_extract(monkeypatch, [
|
||||
"graphify", "extract", str(corpus), "--code-only", "--no-cluster",
|
||||
"--out", str(out), *args,
|
||||
])
|
||||
text = capsys.readouterr().out
|
||||
if explicit_ignore is None:
|
||||
assert "path(s) ignored" not in text
|
||||
assert "VCS ignore rules" not in text
|
||||
assert "nested/tracked.py" in _node_sources(out / "graphify-out" / "graph.json")
|
||||
else:
|
||||
assert "1 path(s) ignored by ignore rules" in text
|
||||
assert "'nested/'" in text
|
||||
assert "VCS ignore rules disabled" in text
|
||||
assert ".graphifyignore and --exclude still apply" in text
|
||||
assert "--no-gitignore bypasses" not in text
|
||||
|
||||
|
||||
def test_extract_ignored_samples_are_bounded_sorted_and_noise_free(monkeypatch, tmp_path, capsys):
|
||||
corpus = tmp_path / "corpus"
|
||||
corpus.mkdir()
|
||||
names = ["z-dir", "e-dir", "d-dir", "b-dir"]
|
||||
for name in [*names, "node_modules"]:
|
||||
directory = corpus / name
|
||||
directory.mkdir()
|
||||
(directory / "hidden.py").write_text("value = 1\n", encoding="utf-8")
|
||||
(corpus / "a.py").write_text("value = 1\n", encoding="utf-8")
|
||||
(corpus / ".graphifyignore").write_text("*-dir/\na.py\n", encoding="utf-8")
|
||||
monkeypatch.setattr(mainmod, "_check_skill_version", lambda _: None)
|
||||
_run_extract(monkeypatch, [
|
||||
"graphify", "extract", str(corpus), "--code-only", "--no-cluster",
|
||||
"--out", str(tmp_path / "output"),
|
||||
])
|
||||
text = capsys.readouterr().out
|
||||
assert "5 path(s) ignored by ignore rules" in text
|
||||
assert "'a.py', 'b-dir/', 'd-dir/' (+2 more)" in text
|
||||
assert "e-dir" not in text
|
||||
assert "z-dir" not in text
|
||||
assert "node_modules" not in text
|
||||
assert "hidden.py" not in text
|
||||
|
||||
|
||||
def test_extract_default_noise_alone_has_no_ignore_summary(monkeypatch, tmp_path, capsys):
|
||||
corpus = tmp_path / "corpus"
|
||||
(corpus / "node_modules").mkdir(parents=True)
|
||||
monkeypatch.setattr(mainmod, "_check_skill_version", lambda _: None)
|
||||
_run_extract(monkeypatch, [
|
||||
"graphify", "extract", str(corpus), "--code-only", "--no-cluster",
|
||||
"--out", str(tmp_path / "output"),
|
||||
])
|
||||
text = capsys.readouterr().out
|
||||
assert "path(s) ignored" not in text
|
||||
assert "VCS ignore rules" not in text
|
||||
|
||||
|
||||
def test_extract_exits_nonzero_when_ast_extraction_raises(
|
||||
monkeypatch, tmp_path, capsys
|
||||
):
|
||||
|
||||
Reference in new issue
Block a user