From 9fc4e3efa9e89c26461795b535309ecfad85f3ac Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Wed, 13 Dec 2023 17:31:21 +0000 Subject: [PATCH 1/2] refactor: remove tmp_dirs from PushPrompts and `PromptDiffDeterminer` Fixes #323 --- .../diff_determiner/base_diff_determiner.py | 24 +------------------ .../test_ankiconnect_destination.py | 4 +--- .../destination_commands.py | 3 --- 3 files changed, 2 insertions(+), 29 deletions(-) diff --git a/personal_mnemonic_medium/v2/domain/diff_determiner/base_diff_determiner.py b/personal_mnemonic_medium/v2/domain/diff_determiner/base_diff_determiner.py index 62ff37fe..5976ffa1 100644 --- a/personal_mnemonic_medium/v2/domain/diff_determiner/base_diff_determiner.py +++ b/personal_mnemonic_medium/v2/domain/diff_determiner/base_diff_determiner.py @@ -1,5 +1,4 @@ from collections.abc import Mapping, Sequence -from pathlib import Path from typing import Generic, Protocol, TypeVar from personal_mnemonic_medium.v2.domain.prompt_destination.base_prompt_destination import ( @@ -49,14 +48,6 @@ def only_in_destination(self) -> Sequence[S]: class PromptDiffDeterminer(BaseDiffDeterminer): - def __init__(self, tmp_read_dir: Path, tmp_write_dir: Path): - # TODO: https://github.com/MartinBernstorff/personal-mnemonic-medium/issues/308 refactor: get rid of tmp_read_dir and tmp_write_dir - self.tmp_read_dir = tmp_read_dir - self.tmp_read_dir.mkdir(exist_ok=True) - - self.tmp_write_dir = tmp_write_dir - self.tmp_write_dir.mkdir(exist_ok=True) - def sync( self, source_prompts: Sequence[BasePrompt], @@ -71,18 +62,5 @@ def sync( return [ DeletePrompts(syncer.only_in_destination()), - PushPrompts( - syncer.only_in_source(), - tmp_write_dir=self.tmp_write_dir, - tmp_read_dir=self.tmp_read_dir, - ), + PushPrompts(syncer.only_in_source()), ] - - -class FakeDiffDeterminer(BaseDiffDeterminer): - def sync( - self, - source_prompts: Sequence[BasePrompt], - destination_prompts: Sequence[BasePrompt], - ) -> Sequence[PromptDestinationCommand]: - ... diff --git a/personal_mnemonic_medium/v2/domain/prompt_destination/anki_connect/test_ankiconnect_destination.py b/personal_mnemonic_medium/v2/domain/prompt_destination/anki_connect/test_ankiconnect_destination.py index 9af0b492..2c90a25e 100644 --- a/personal_mnemonic_medium/v2/domain/prompt_destination/anki_connect/test_ankiconnect_destination.py +++ b/personal_mnemonic_medium/v2/domain/prompt_destination/anki_connect/test_ankiconnect_destination.py @@ -72,9 +72,7 @@ def test_ankiconnect_push_prompts(tmpdir: Path): add_tags=["FakeTag"], remote_id="1", ), - ], - tmp_write_dir=tmpdir, - tmp_read_dir=tmpdir, + ] ) ] ) diff --git a/personal_mnemonic_medium/v2/domain/prompt_destination/destination_commands.py b/personal_mnemonic_medium/v2/domain/prompt_destination/destination_commands.py index 45a3bddc..db66ded5 100644 --- a/personal_mnemonic_medium/v2/domain/prompt_destination/destination_commands.py +++ b/personal_mnemonic_medium/v2/domain/prompt_destination/destination_commands.py @@ -1,6 +1,5 @@ from collections.abc import Sequence from dataclasses import dataclass -from pathlib import Path from ..prompts.base_prompt import BasePrompt @@ -13,8 +12,6 @@ class DeletePrompts: @dataclass(frozen=True) class PushPrompts: prompts: Sequence[BasePrompt] - tmp_write_dir: Path - tmp_read_dir: Path PromptDestinationCommand = DeletePrompts | PushPrompts From 8e804696b5ddd7832a27c9ebc19caa1b1c313b92 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Wed, 13 Dec 2023 17:32:43 +0000 Subject: [PATCH 2/2] refactor: remove tmp_dirs from pushprompts and promptdiffdeterminer --- .../domain/diff_determiner/test_diff_determiner.py | 14 +++----------- .../anki_connect/test_ankiconnect_destination.py | 3 +-- personal_mnemonic_medium/v2/presentation/cli.py | 4 +--- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/personal_mnemonic_medium/v2/domain/diff_determiner/test_diff_determiner.py b/personal_mnemonic_medium/v2/domain/diff_determiner/test_diff_determiner.py index 8a922fbe..a215cbc9 100644 --- a/personal_mnemonic_medium/v2/domain/diff_determiner/test_diff_determiner.py +++ b/personal_mnemonic_medium/v2/domain/diff_determiner/test_diff_determiner.py @@ -1,5 +1,3 @@ -from pathlib import Path - from ..prompt_destination.destination_commands import ( DeletePrompts, PushPrompts, @@ -18,10 +16,8 @@ def test_diff_determiner(): assert syncer.only_in_destination() == ["3"] -def test_prompt_diff_determiner(tmp_path: Path): - syncer = PromptDiffDeterminer( - tmp_read_dir=tmp_path, tmp_write_dir=tmp_path - ) +def test_prompt_diff_determiner(): + syncer = PromptDiffDeterminer() source_prompts = [ QAPrompt(question="a", answer="a"), @@ -49,9 +45,5 @@ def test_prompt_diff_determiner(tmp_path: Path): ) ] ), - PushPrompts( - [QAPrompt(question="a", answer="a")], - tmp_write_dir=tmp_path, - tmp_read_dir=tmp_path, - ), + PushPrompts([QAPrompt(question="a", answer="a")]), ] diff --git a/personal_mnemonic_medium/v2/domain/prompt_destination/anki_connect/test_ankiconnect_destination.py b/personal_mnemonic_medium/v2/domain/prompt_destination/anki_connect/test_ankiconnect_destination.py index fd5132c0..35f1751a 100644 --- a/personal_mnemonic_medium/v2/domain/prompt_destination/anki_connect/test_ankiconnect_destination.py +++ b/personal_mnemonic_medium/v2/domain/prompt_destination/anki_connect/test_ankiconnect_destination.py @@ -1,5 +1,4 @@ from collections.abc import Mapping -from pathlib import Path import pytest @@ -49,7 +48,7 @@ def test_ankiconnect_get_all_prompts(fields: Mapping[str, AnkiField]): assert len(prompts) == 1 -def test_ankiconnect_push_prompts(tmpdir: Path): +def test_ankiconnect_push_prompts(): gateway = SpieAnkiconnectGateway() dest = AnkiConnectDestination( gateway=gateway, diff --git a/personal_mnemonic_medium/v2/presentation/cli.py b/personal_mnemonic_medium/v2/presentation/cli.py index 883c6f34..c34259aa 100644 --- a/personal_mnemonic_medium/v2/presentation/cli.py +++ b/personal_mnemonic_medium/v2/presentation/cli.py @@ -47,9 +47,7 @@ def _sync_deck( ) destination_prompts = destination.get_all_prompts() - update_commands = PromptDiffDeterminer( - tmp_write_dir=Path("/tmp"), tmp_read_dir=Path("/tmp") - ).sync( + update_commands = PromptDiffDeterminer().sync( source_prompts=source_prompts, destination_prompts=destination_prompts, )