Sync only the declaring module before a run; skip git-ignored paths

`fluksio run` walked the working directory and imported every module in
it, which ran a research repository's analysis scripts before the run was
submitted. A flow's origin now records the file and module name that
declared it, and run/sweep import just that, under the same name so the
generated node bodies do not change. A flow with no record still walks,
now skipping what .gitignore covers.

Every code-defined flow reports `flow` changed once on its next sync,
since the origin gained two fields.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QgG6TJw5qBZzaLghQSRVrq
This commit is contained in:
2026-09-16 16:55:02 +02:00
co-authored by Claude Opus 5
parent 7dfe646e2b
commit fccf89f849
9 changed files with 246 additions and 22 deletions
+37 -1
View File
@@ -582,6 +582,35 @@ def _code_of(spec: NodeSpec) -> dict[str, Any]:
return {"code_files": files, "code_digest": digest_of(files)}
def _declared_at() -> tuple[str, str]:
"""The file and module name of whatever constructed the flow.
Empty for a declaration no import could reach again: a script run
directly, or a notebook cell, which is not a file on disk.
"""
frame = inspect.currentframe()
# Out of this helper, then out of `Flow.__init__`.
for _ in range(2):
frame = frame.f_back if frame is not None else None
if frame is None:
return "", ""
module = str(frame.f_globals.get("__name__") or "")
path = Path(frame.f_code.co_filename)
if module == "__main__" or not path.is_file():
return "", ""
return str(path.resolve()), module
def _relative(path: str, repo: str) -> str:
"""``path`` as seen from ``repo``, or empty when it is not inside it."""
if not path or not repo:
return ""
try:
return Path(path).relative_to(Path(repo).resolve()).as_posix()
except ValueError:
return ""
def _serialisable(value: Any) -> bool:
try:
json.dumps(value)
@@ -619,6 +648,9 @@ class Flow:
self.inputs = list(inputs)
self.outputs = list(outputs)
self.nodes = [_spec_of(entry) for entry in nodes]
#: Where this flow was declared: the file, and the module name it was
#: imported under. What `fluksio run` imports by default.
self.declared_in, self.module = _declared_at()
self._resolve_types()
self._validate()
self._nodes = [_check(spec, mode) for spec in self.nodes]
@@ -719,7 +751,11 @@ class Flow:
"outputs": self.outputs,
}
if origin is not None:
doc["origin"] = origin
declared_in = _relative(self.declared_in, str(origin.get("repo") or ""))
doc["origin"] = origin | {
"declared_in": declared_in,
"module": self.module if declared_in else "",
}
return doc
def shims(self) -> dict[str, str]: