Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ query_depth=3

For `graphify query`, explicit `--budget N` / `--budget=N` and `--depth N` / `--depth=N` override these settings independently. Without a project setting or explicit option, the defaults remain budget 2000 and depth 2. These keys do not change the MCP server's defaults.

Set `demote_docs=false` (alias `query_demote_docs`; accepts `true`/`false`, `1`/`0`, `yes`/`no`, `on`/`off`) to turn off document demotion in `graphify query` by default. `--demote-docs` / `--no-doc-demotion` on the command line override it.

Settings come from the project owning the selected `--graph`, even when the command runs from another directory. An existing absolute directory in the graph's sibling `.graphify_root` marker identifies that project. Otherwise a matching relative `GRAPHIFY_OUT` suffix identifies it; absolute, empty, traversal-containing or nonmatching output paths fall back to the graph file's directory. Relative markers are ignored.

The query command always reads that project's `.graphifyrc`. An invalid recognized setting or an unreadable file produces one stderr warning and discards all project settings for that query; explicit options still apply. The settings parser stays strict for its other callers. Existing explicit budget values retain their behavior; persisted `query_budget` values must be positive.
Expand Down
16 changes: 15 additions & 1 deletion graphify/rcfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,17 @@ def parse_language_value(value: str) -> str:
) from None


_BOOL_VALUES = {
"true": True, "1": True, "yes": True, "on": True,
"false": False, "0": False, "no": False, "off": False,
}


def load_graphifyrc(root: Path) -> dict:
"""Parse ``<root>/.graphifyrc``. Returns ``{}`` when absent.

Returned keys: ``viz_node_limit``, ``query_budget``, ``query_depth`` (ints),
and ``languages``
``demote_docs`` / ``query_demote_docs`` (bools), and ``languages``
(``{".inc": ".php", ...}``) — each present only when the file sets it.
Unknown keys are ignored so a newer graphify's options do not break an
older one. Malformed lines raise ``ValueError`` naming the line.
Expand Down Expand Up @@ -164,6 +170,14 @@ def load_graphifyrc(root: Path) -> dict:
f"Invalid {key} in {rc_path} at line {line_num}: {val!r}. "
f"Must be {requirement}."
) from exc
elif key in {"demote_docs", "query_demote_docs"}:
flag = _BOOL_VALUES.get(val.lower())
if flag is None:
raise ValueError(
f"Invalid {key} in {rc_path} at line {line_num}: {val!r}. "
f"Must be true or false."
)
cfg[key] = flag
elif key.startswith("language."):
ext_part = key[len("language."):].strip()
if not ext_part or any(ch.isspace() for ch in ext_part):
Expand Down
22 changes: 22 additions & 0 deletions tests/test_language_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ def test_invalid_query_defaults_report_key_path_and_line(tmp_path, key, value):
assert "line 2" in str(error.value)


@pytest.mark.parametrize("content, expected", [
("demote_docs=false\n", {"demote_docs": False}),
("demote_docs=True\n", {"demote_docs": True}),
("query_demote_docs=0\n", {"query_demote_docs": False}),
("demote_docs=yes\nquery_demote_docs=off\n", {"demote_docs": True, "query_demote_docs": False}),
])
def test_demote_docs_is_a_project_setting(tmp_path, content, expected):
(tmp_path / ".graphifyrc").write_text(content, encoding="utf-8")
assert load_graphifyrc(tmp_path) == expected


@pytest.mark.parametrize("key", ["demote_docs", "query_demote_docs"])
@pytest.mark.parametrize("value", ["maybe", ""])
def test_invalid_demote_docs_reports_key_path_and_line(tmp_path, key, value):
rc = tmp_path / ".graphifyrc"
rc.write_text(f"# project settings\n{key}={value}\n", encoding="utf-8")
with pytest.raises(ValueError) as error:
load_graphifyrc(tmp_path)
assert key in str(error.value) and str(rc) in str(error.value)
assert "line 2" in str(error.value)


def test_hooks_still_reads_the_same_file_through_its_old_name(tmp_path):
from graphify.hooks import _load_graphifyrc
(tmp_path / ".graphifyrc").write_text("viz_node_limit=3\nlanguage.inc=php\n", encoding="utf-8")
Expand Down
Loading