Skip to content

Commit

Permalink
refactor: remove tmp_dirs from PushPrompts and PromptDiffDeterminer (
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBernstorff authored Dec 13, 2023
2 parents 5f38dfe + 8e80469 commit b61fd15
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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],
Expand All @@ -72,9 +63,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()),
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from pathlib import Path

from ..prompt_destination.destination_commands import (
DeletePrompts,
PushPrompts,
Expand All @@ -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"),
Expand Down Expand Up @@ -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")]),
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from collections.abc import Mapping
from pathlib import Path

import pytest

Expand Down Expand Up @@ -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,
Expand All @@ -69,9 +68,7 @@ def test_ankiconnect_push_prompts(tmpdir: Path):
ClozeWithoutDoc(
text="FakeText", add_tags=["FakeTag"]
),
],
tmp_write_dir=tmpdir,
tmp_read_dir=tmpdir,
]
)
]
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections.abc import Sequence
from dataclasses import dataclass
from pathlib import Path

from ..prompts.base_prompt import BasePrompt, DestinationPrompt

Expand All @@ -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
4 changes: 1 addition & 3 deletions personal_mnemonic_medium/v2/presentation/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

0 comments on commit b61fd15

Please sign in to comment.