feat(extract): record the --code-only scope in .graphify_build.json (#4923)
Persist `code_only` beside `excludes` and `gitignore` (the #1886/#1971 pattern)
so a later rebuild can tell a code-only graph from a full one. Nothing reads it
yet; this commit changes no rebuild behaviour.
test_explicit_exclude_replaces_persisted_setting_with_custom_out asserted the
whole file equals {"excludes": [...]} after a --code-only run; the file now also
carries code_only, so the expectation includes it.
(cherry picked from commit a504674847)
This commit is contained in:
1 parent
f3421ff133
commit
9e6f271ae9
3 files changed
+26
-2
No files matched your search
@@ -4005,6 +4005,7 @@ def dispatch_command(cmd: str) -> None:
|
||||
graphify_out,
|
||||
excludes=cli_excludes or None,
|
||||
gitignore=False if no_gitignore else None,
|
||||
code_only=True if code_only else None,
|
||||
)
|
||||
|
||||
stages = _StageTimer(cli_timing)
|
||||
|
||||
+23
-1
@@ -114,12 +114,15 @@ def _write_build_config(
|
||||
*,
|
||||
excludes: "list[str] | None",
|
||||
gitignore: bool | None = None,
|
||||
code_only: bool | None = None,
|
||||
) -> None:
|
||||
"""Persist corpus-shaping options under ``out_dir``.
|
||||
|
||||
Best effort and non clobbering: omitted options retain their existing values.
|
||||
``code_only`` records that the graph was built with ``extract --code-only``
|
||||
so a later hook/update/watch rebuild keeps that scope (#4923).
|
||||
"""
|
||||
if not excludes and gitignore is None:
|
||||
if not excludes and gitignore is None and code_only is None:
|
||||
return
|
||||
try:
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
@@ -134,6 +137,8 @@ def _write_build_config(
|
||||
config["excludes"] = list(excludes)
|
||||
if gitignore is not None:
|
||||
config["gitignore"] = gitignore
|
||||
if code_only is not None:
|
||||
config["code_only"] = code_only
|
||||
path.write_text(json.dumps(config), encoding="utf-8")
|
||||
except OSError:
|
||||
pass
|
||||
@@ -166,6 +171,23 @@ def _read_build_gitignore(out_dir: Path) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def _read_build_code_only(out_dir: Path) -> bool:
|
||||
"""Return whether the graph was built with ``--code-only`` (default False).
|
||||
|
||||
A rebuild has no CLI flag of its own, so this record is the only way it can
|
||||
tell a deliberately code-only graph from a full one (#4923).
|
||||
"""
|
||||
try:
|
||||
path = out_dir / _BUILD_CONFIG_FILENAME
|
||||
if path.is_file():
|
||||
cfg = json.loads(path.read_text(encoding="utf-8"))
|
||||
if isinstance(cfg, dict) and cfg.get("code_only") is True:
|
||||
return True
|
||||
except (OSError, json.JSONDecodeError):
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def _merge_changed_paths(*sources: "list[Path] | None") -> list[Path]:
|
||||
"""Concatenate path lists, preserving order and dropping duplicates.
|
||||
|
||||
|
||||
@@ -242,7 +242,8 @@ def test_explicit_exclude_replaces_persisted_setting_with_custom_out(tmp_path):
|
||||
assert any(source.endswith("vendor/lib.py") for source in sources)
|
||||
assert not any(source.endswith("generated/gen.py") for source in sources)
|
||||
assert json.loads((graph_out / ".graphify_build.json").read_text()) == {
|
||||
"excludes": ["generated"]
|
||||
"excludes": ["generated"],
|
||||
"code_only": True,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user