Skip to content

Commit 9a7f53d

Browse files
committed
fix: cache annotation format (before import, with brackets)
- Annotation before import line (not after) - Path wrapped in brackets: <path> - Format: # you see: <.imports/...> <sha256:...> REFERENCE: #40 (Import caching mechanism)
1 parent 5781899 commit 9a7f53d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/workflow_as_list/executor/loader.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,26 @@ def _has_cache_annotation(self, content: str, cache_path: str) -> bool:
7373
def _add_annotation_to_content(
7474
self, content: str, workflow_path: Path, cache_path: Path, hash_value: str
7575
) -> str:
76-
"""Add cache annotation to workflow content."""
76+
"""Add cache annotation BEFORE import line (not after)."""
7777
lines = content.split("\n")
7878
output = []
79+
added = set() # Track which imports have annotations
7980

8081
for i, line in enumerate(lines):
81-
output.append(line)
82-
# Add annotation after import lines
82+
# Check if this is an import line without annotation
8383
if line.strip().startswith("import:"):
84-
annotation = f"# you see: {cache_path} <{hash_value}>"
8584
# Check if next line is already an annotation
86-
if i + 1 < len(lines) and "# you see:" not in lines[i + 1]:
85+
has_annotation = False
86+
if i + 1 < len(lines) and "# you see:" in lines[i + 1]:
87+
has_annotation = True
88+
89+
if not has_annotation and str(workflow_path) not in added:
90+
# Add annotation BEFORE import line
91+
annotation = f"# you see: <{cache_path}> <{hash_value}>"
8792
output.append(annotation)
93+
added.add(str(workflow_path))
94+
95+
output.append(line)
8896

8997
return "\n".join(output)
9098

workflow/test-import.workflow.list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
- (start) Test Import Workflow
77
# Import base workflow for common steps
8+
# you see: <.imports/workflow/test-import.workflow.list> <sha256:f67debb9e7b8d86bdfaa071c6c22a15b85a69f720fb1c55de2dde1ac838b2505>
89
import: ./main.workflow.list
9-
# you see: .imports/workflow/test-import.workflow.list <sha256:f67debb9e7b8d86bdfaa071c6c22a15b85a69f720fb1c55de2dde1ac838b2505>
1010

1111
- (test) Local test step
1212
- Ask: Import caching works? (yes/no)

0 commit comments

Comments
 (0)