Implement Edit Feature #28
8 changed files with 27 additions and 24 deletions
|
|
@ -37,7 +37,7 @@ def todo() -> None:
|
||||||
print(
|
print(
|
||||||
Panel(
|
Panel(
|
||||||
Markdown(task_shard.markdown_content),
|
Markdown(task_shard.markdown_content),
|
||||||
title=f"{sharded_document.filename}:{task_shard.start_line}",
|
title=f"{sharded_document.file_name}:{task_shard.start_line}",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,12 +51,14 @@ def localize_shard(
|
||||||
def localize_stream_file(
|
def localize_stream_file(
|
||||||
stream_file: StreamFile, config: RepositoryConfiguration
|
stream_file: StreamFile, config: RepositoryConfiguration
|
||||||
) -> LocalizedShard | None:
|
) -> 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:
|
if not shard_date or not stream_file.shard:
|
||||||
raise ValueError("Could not extract date")
|
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"]
|
__all__ = ["localize_stream_file"]
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,10 @@ def attach_markdown_shard(shard: Shard, markdown_text: str) -> ShardWithMarkdown
|
||||||
|
|
||||||
def attach_markdown(file: StreamFile, markdown_text: str) -> StreamFileWithMarkdown:
|
def attach_markdown(file: StreamFile, markdown_text: str) -> StreamFileWithMarkdown:
|
||||||
if file.shard is None:
|
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)
|
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"]
|
__all__ = ["attach_markdown"]
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,7 @@ def parse_markdown_file(file_name: str, file_content: str) -> StreamFile:
|
||||||
):
|
):
|
||||||
shard = parsed_shard
|
shard = parsed_shard
|
||||||
|
|
||||||
return StreamFile(shard=shard, filename=file_name)
|
return StreamFile(shard=shard, file_name=file_name)
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["Shard", "StreamFile", "parse_markdown_file"]
|
__all__ = ["Shard", "StreamFile", "parse_markdown_file"]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -11,7 +12,7 @@ class Shard(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class StreamFile(BaseModel):
|
class StreamFile(BaseModel):
|
||||||
filename: str
|
file_name: str
|
||||||
shard: Shard | None = None
|
shard: Shard | None = None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,12 @@ class TestAttachMarkdown:
|
||||||
def test_attach_markdown_with_shard(self):
|
def test_attach_markdown_with_shard(self):
|
||||||
markdown_text = "Hello World\n\nThis is a test."
|
markdown_text = "Hello World\n\nThis is a test."
|
||||||
shard = Shard(start_line=1, end_line=3)
|
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)
|
result = attach_markdown(stream_file, markdown_text)
|
||||||
|
|
||||||
assert result == StreamFileWithMarkdown(
|
assert result == StreamFileWithMarkdown(
|
||||||
filename=self.file_name,
|
file_name=self.file_name,
|
||||||
shard=ShardWithMarkdown(
|
shard=ShardWithMarkdown(
|
||||||
start_line=1,
|
start_line=1,
|
||||||
end_line=3,
|
end_line=3,
|
||||||
|
|
@ -33,11 +33,11 @@ class TestAttachMarkdown:
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_attach_markdown_without_shard(self):
|
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")
|
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):
|
def test_attach_markdown_with_nested_shards(self):
|
||||||
markdown_text = "Header\n\n@Marker1 Content 1\n\n@Marker2 Content 2"
|
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),
|
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)
|
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 is not None
|
||||||
assert result.shard.start_line == 1
|
assert result.shard.start_line == 1
|
||||||
assert result.shard.end_line == 5
|
assert result.shard.end_line == 5
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,13 @@ class TestParseProcess:
|
||||||
|
|
||||||
def test_parse_empty_file(self):
|
def test_parse_empty_file(self):
|
||||||
assert parse_markdown_file(self.file_name, "") == StreamFile(
|
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):
|
def test_parse_basic_one_line_file(self):
|
||||||
test_file = "Hello World"
|
test_file = "Hello World"
|
||||||
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
||||||
filename=self.file_name,
|
file_name=self.file_name,
|
||||||
shard=Shard(
|
shard=Shard(
|
||||||
start_line=1,
|
start_line=1,
|
||||||
end_line=1,
|
end_line=1,
|
||||||
|
|
@ -26,7 +26,7 @@ class TestParseProcess:
|
||||||
def test_parse_basic_multi_line_file(self):
|
def test_parse_basic_multi_line_file(self):
|
||||||
test_file = "Hello World\n\nHello again!"
|
test_file = "Hello World\n\nHello again!"
|
||||||
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
||||||
filename=self.file_name,
|
file_name=self.file_name,
|
||||||
shard=Shard(
|
shard=Shard(
|
||||||
start_line=1,
|
start_line=1,
|
||||||
end_line=3,
|
end_line=3,
|
||||||
|
|
@ -36,7 +36,7 @@ class TestParseProcess:
|
||||||
def test_parse_single_line_with_tag(self):
|
def test_parse_single_line_with_tag(self):
|
||||||
test_file = "@Tag Hello World"
|
test_file = "@Tag Hello World"
|
||||||
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
||||||
filename=self.file_name,
|
file_name=self.file_name,
|
||||||
shard=Shard(
|
shard=Shard(
|
||||||
markers=["Tag"],
|
markers=["Tag"],
|
||||||
start_line=1,
|
start_line=1,
|
||||||
|
|
@ -47,7 +47,7 @@ class TestParseProcess:
|
||||||
def test_parse_single_line_with_two_tags(self):
|
def test_parse_single_line_with_two_tags(self):
|
||||||
test_file = "@Marker1 @Marker2 Hello World"
|
test_file = "@Marker1 @Marker2 Hello World"
|
||||||
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
||||||
filename=self.file_name,
|
file_name=self.file_name,
|
||||||
shard=Shard(
|
shard=Shard(
|
||||||
markers=["Marker1", "Marker2"],
|
markers=["Marker1", "Marker2"],
|
||||||
start_line=1,
|
start_line=1,
|
||||||
|
|
@ -58,7 +58,7 @@ class TestParseProcess:
|
||||||
def test_parse_single_line_with_two_tags_and_misplaced_tag(self):
|
def test_parse_single_line_with_two_tags_and_misplaced_tag(self):
|
||||||
test_file = "@Tag1 @Tag2 Hello World @Tag3"
|
test_file = "@Tag1 @Tag2 Hello World @Tag3"
|
||||||
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
assert parse_markdown_file(self.file_name, test_file) == StreamFile(
|
||||||
filename=self.file_name,
|
file_name=self.file_name,
|
||||||
shard=Shard(
|
shard=Shard(
|
||||||
markers=["Tag1", "Tag2"],
|
markers=["Tag1", "Tag2"],
|
||||||
tags=["Tag3"],
|
tags=["Tag3"],
|
||||||
|
|
@ -71,7 +71,7 @@ class TestParseProcess:
|
||||||
file_text = "Hello World!\n\n@Tag1 Block 1\n\n@Tag2 Block 2"
|
file_text = "Hello World!\n\n@Tag1 Block 1\n\n@Tag2 Block 2"
|
||||||
|
|
||||||
assert parse_markdown_file(self.file_name, file_text) == StreamFile(
|
assert parse_markdown_file(self.file_name, file_text) == StreamFile(
|
||||||
filename=self.file_name,
|
file_name=self.file_name,
|
||||||
shard=Shard(
|
shard=Shard(
|
||||||
start_line=1,
|
start_line=1,
|
||||||
end_line=5,
|
end_line=5,
|
||||||
|
|
@ -114,7 +114,7 @@ class TestParseProcess:
|
||||||
file_text = "# Heading @Tag1\n\n## @Marker1 Subheading @Tag2\n\n# Heading @Tag3"
|
file_text = "# Heading @Tag1\n\n## @Marker1 Subheading @Tag2\n\n# Heading @Tag3"
|
||||||
|
|
||||||
assert parse_markdown_file(self.file_name, file_text) == StreamFile(
|
assert parse_markdown_file(self.file_name, file_text) == StreamFile(
|
||||||
filename=self.file_name,
|
file_name=self.file_name,
|
||||||
shard=Shard(
|
shard=Shard(
|
||||||
start_line=1,
|
start_line=1,
|
||||||
end_line=5,
|
end_line=5,
|
||||||
|
|
@ -141,7 +141,7 @@ class TestParseProcess:
|
||||||
file_text = "# @Marker1 Heading @Tag1\n\n## Subheading @Tag2"
|
file_text = "# @Marker1 Heading @Tag1\n\n## Subheading @Tag2"
|
||||||
|
|
||||||
assert parse_markdown_file(self.file_name, file_text) == StreamFile(
|
assert parse_markdown_file(self.file_name, file_text) == StreamFile(
|
||||||
filename=self.file_name,
|
file_name=self.file_name,
|
||||||
shard=Shard(
|
shard=Shard(
|
||||||
markers=["Marker1"],
|
markers=["Marker1"],
|
||||||
tags=["Tag1", "Tag2"],
|
tags=["Tag1", "Tag2"],
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ repository_configuration = RepositoryConfiguration(
|
||||||
class TestExtractDateTime:
|
class TestExtractDateTime:
|
||||||
def test_project_simple_stream_file(self):
|
def test_project_simple_stream_file(self):
|
||||||
stream_file = StreamFile(
|
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"]),
|
shard=Shard(start_line=1, end_line=1, markers=["Streamer"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -45,5 +45,5 @@ class TestExtractDateTime:
|
||||||
start_line=1,
|
start_line=1,
|
||||||
end_line=1,
|
end_line=1,
|
||||||
children=[],
|
children=[],
|
||||||
location={"project": "streamer"},
|
location={"project": "streamer", "file": stream_file.file_name},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue