From 79095bad4ad1ef8aec6014fed49806d6dec6e97b Mon Sep 17 00:00:00 2001 From: Konstantin Fickel Date: Sat, 31 Jan 2026 17:21:55 +0100 Subject: [PATCH] refactor: store file in position, rename filename to file_name Signed-off-by: Konstantin Fickel --- src/streamer/__init__.py | 2 +- src/streamer/localize/localize.py | 6 ++++-- src/streamer/parse/attach_markdown.py | 4 ++-- src/streamer/parse/parse.py | 2 +- src/streamer/parse/shard.py | 3 ++- test/parse/test_attach_markdown.py | 12 ++++++------ test/parse/test_parse.py | 18 +++++++++--------- test/test_localize.py | 4 ++-- 8 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/streamer/__init__.py b/src/streamer/__init__.py index 47fa553..2e38293 100644 --- a/src/streamer/__init__.py +++ b/src/streamer/__init__.py @@ -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}", ) ) diff --git a/src/streamer/localize/localize.py b/src/streamer/localize/localize.py index 8a0851c..fcf0fa4 100644 --- a/src/streamer/localize/localize.py +++ b/src/streamer/localize/localize.py @@ -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"] diff --git a/src/streamer/parse/attach_markdown.py b/src/streamer/parse/attach_markdown.py index 349377f..85b5d6f 100644 --- a/src/streamer/parse/attach_markdown.py +++ b/src/streamer/parse/attach_markdown.py @@ -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"] diff --git a/src/streamer/parse/parse.py b/src/streamer/parse/parse.py index 4a8258f..058912a 100644 --- a/src/streamer/parse/parse.py +++ b/src/streamer/parse/parse.py @@ -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"] diff --git a/src/streamer/parse/shard.py b/src/streamer/parse/shard.py index 397950f..65432c3 100644 --- a/src/streamer/parse/shard.py +++ b/src/streamer/parse/shard.py @@ -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 diff --git a/test/parse/test_attach_markdown.py b/test/parse/test_attach_markdown.py index 21f8a1b..0ec1253 100644 --- a/test/parse/test_attach_markdown.py +++ b/test/parse/test_attach_markdown.py @@ -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 diff --git a/test/parse/test_parse.py b/test/parse/test_parse.py index 0a71671..b692120 100644 --- a/test/parse/test_parse.py +++ b/test/parse/test_parse.py @@ -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"], diff --git a/test/test_localize.py b/test/test_localize.py index adf8cad..f6c0dc0 100644 --- a/test/test_localize.py +++ b/test/test_localize.py @@ -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}, )