Implement Edit Feature #28

Merged
kfickel merged 12 commits from 8-edit-feature into main 2026-02-01 10:34:32 +01:00
8 changed files with 27 additions and 24 deletions
Showing only changes of commit 79095bad4a - Show all commits

View file

@ -37,7 +37,7 @@ def todo() -> None:
print(
Panel(
Markdown(task_shard.markdown_content),
title=f"{sharded_document.filename}:{task_shard.start_line}",
title=f"{sharded_document.file_name}:{task_shard.start_line}",
)
)

View file

@ -51,12 +51,14 @@ def localize_shard(
def localize_stream_file(
stream_file: StreamFile, config: RepositoryConfiguration
) -> LocalizedShard | None:
shard_date = extract_datetime_from_file_name(stream_file.filename)
shard_date = extract_datetime_from_file_name(stream_file.file_name)
if not shard_date or not stream_file.shard:
raise ValueError("Could not extract date")
return localize_shard(stream_file.shard, config, {}, shard_date)
return localize_shard(
stream_file.shard, config, {"file": stream_file.file_name}, shard_date
)
__all__ = ["localize_stream_file"]

View file

@ -26,10 +26,10 @@ def attach_markdown_shard(shard: Shard, markdown_text: str) -> ShardWithMarkdown
def attach_markdown(file: StreamFile, markdown_text: str) -> StreamFileWithMarkdown:
if file.shard is None:
return StreamFileWithMarkdown(filename=file.filename, shard=None)
return StreamFileWithMarkdown(file_name=file.file_name, shard=None)
attached_shard = attach_markdown_shard(file.shard, markdown_text)
return StreamFileWithMarkdown(filename=file.filename, shard=attached_shard)
return StreamFileWithMarkdown(file_name=file.file_name, shard=attached_shard)
__all__ = ["attach_markdown"]

View file

@ -236,7 +236,7 @@ def parse_markdown_file(file_name: str, file_content: str) -> StreamFile:
):
shard = parsed_shard
return StreamFile(shard=shard, filename=file_name)
return StreamFile(shard=shard, file_name=file_name)
__all__ = ["Shard", "StreamFile", "parse_markdown_file"]

View file

@ -1,4 +1,5 @@
from __future__ import annotations
from pydantic import BaseModel
@ -11,7 +12,7 @@ class Shard(BaseModel):
class StreamFile(BaseModel):
filename: str
file_name: str
shard: Shard | None = None

View file

@ -16,12 +16,12 @@ class TestAttachMarkdown:
def test_attach_markdown_with_shard(self):
markdown_text = "Hello World\n\nThis is a test."
shard = Shard(start_line=1, end_line=3)
stream_file = StreamFile(filename=self.file_name, shard=shard)
stream_file = StreamFile(file_name=self.file_name, shard=shard)
result = attach_markdown(stream_file, markdown_text)
assert result == StreamFileWithMarkdown(
filename=self.file_name,
file_name=self.file_name,
shard=ShardWithMarkdown(
start_line=1,
end_line=3,
@ -33,11 +33,11 @@ class TestAttachMarkdown:
)
def test_attach_markdown_without_shard(self):
stream_file = StreamFile(filename=self.file_name, shard=None)
stream_file = StreamFile(file_name=self.file_name, shard=None)
result = attach_markdown(stream_file, "Some markdown text")
assert result == StreamFileWithMarkdown(filename=self.file_name, shard=None)
assert result == StreamFileWithMarkdown(file_name=self.file_name, shard=None)
def test_attach_markdown_with_nested_shards(self):
markdown_text = "Header\n\n@Marker1 Content 1\n\n@Marker2 Content 2"
@ -49,11 +49,11 @@ class TestAttachMarkdown:
Shard(markers=["Marker2"], start_line=5, end_line=5),
],
)
stream_file = StreamFile(filename=self.file_name, shard=shard)
stream_file = StreamFile(file_name=self.file_name, shard=shard)
result = attach_markdown(stream_file, markdown_text)
assert result.filename == self.file_name
assert result.file_name == self.file_name
assert result.shard is not None
assert result.shard.start_line == 1
assert result.shard.end_line == 5

View file

@ -10,13 +10,13 @@ class TestParseProcess:
def test_parse_empty_file(self):
assert parse_markdown_file(self.file_name, "") == StreamFile(
filename=self.file_name, shard=Shard(start_line=1, end_line=1)
file_name=self.file_name, shard=Shard(start_line=1, end_line=1)
)
def test_parse_basic_one_line_file(self):
test_file = "Hello World"
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
filename=self.file_name,
file_name=self.file_name,
shard=Shard(
start_line=1,
end_line=1,
@ -26,7 +26,7 @@ class TestParseProcess:
def test_parse_basic_multi_line_file(self):
test_file = "Hello World\n\nHello again!"
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
filename=self.file_name,
file_name=self.file_name,
shard=Shard(
start_line=1,
end_line=3,
@ -36,7 +36,7 @@ class TestParseProcess:
def test_parse_single_line_with_tag(self):
test_file = "@Tag Hello World"
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
filename=self.file_name,
file_name=self.file_name,
shard=Shard(
markers=["Tag"],
start_line=1,
@ -47,7 +47,7 @@ class TestParseProcess:
def test_parse_single_line_with_two_tags(self):
test_file = "@Marker1 @Marker2 Hello World"
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
filename=self.file_name,
file_name=self.file_name,
shard=Shard(
markers=["Marker1", "Marker2"],
start_line=1,
@ -58,7 +58,7 @@ class TestParseProcess:
def test_parse_single_line_with_two_tags_and_misplaced_tag(self):
test_file = "@Tag1 @Tag2 Hello World @Tag3"
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
filename=self.file_name,
file_name=self.file_name,
shard=Shard(
markers=["Tag1", "Tag2"],
tags=["Tag3"],
@ -71,7 +71,7 @@ class TestParseProcess:
file_text = "Hello World!\n\n@Tag1 Block 1\n\n@Tag2 Block 2"
assert parse_markdown_file(self.file_name, file_text) == StreamFile(
filename=self.file_name,
file_name=self.file_name,
shard=Shard(
start_line=1,
end_line=5,
@ -114,7 +114,7 @@ class TestParseProcess:
file_text = "# Heading @Tag1\n\n## @Marker1 Subheading @Tag2\n\n# Heading @Tag3"
assert parse_markdown_file(self.file_name, file_text) == StreamFile(
filename=self.file_name,
file_name=self.file_name,
shard=Shard(
start_line=1,
end_line=5,
@ -141,7 +141,7 @@ class TestParseProcess:
file_text = "# @Marker1 Heading @Tag1\n\n## Subheading @Tag2"
assert parse_markdown_file(self.file_name, file_text) == StreamFile(
filename=self.file_name,
file_name=self.file_name,
shard=Shard(
markers=["Marker1"],
tags=["Tag1", "Tag2"],

View file

@ -32,7 +32,7 @@ repository_configuration = RepositoryConfiguration(
class TestExtractDateTime:
def test_project_simple_stream_file(self):
stream_file = StreamFile(
filename="20250622-121000 Test File.md",
file_name="20250622-121000 Test File.md",
shard=Shard(start_line=1, end_line=1, markers=["Streamer"]),
)
@ -45,5 +45,5 @@ class TestExtractDateTime:
start_line=1,
end_line=1,
children=[],
location={"project": "streamer"},
location={"project": "streamer", "file": stream_file.file_name},
)