-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from MartinBernstorff/mb/rewrite_entrypoint
refactor: rewrite entrypoint
- Loading branch information
Showing
15 changed files
with
181 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ updates: | |
commit-message: | ||
prefix: "deps:" | ||
include: "scope" | ||
ignore: | ||
- dependency-name: invoke |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from collections.abc import Sequence | ||
from pathlib import Path | ||
from typing import List | ||
|
||
from personal_mnemonic_medium.exporters.anki.card_types.base import AnkiCard | ||
from personal_mnemonic_medium.exporters.base import CardExporter | ||
from personal_mnemonic_medium.note_factories.base import DocumentFactory | ||
from personal_mnemonic_medium.note_factories.note import Document | ||
from personal_mnemonic_medium.prompt_extractors.base import PromptExtractor | ||
from personal_mnemonic_medium.prompt_extractors.prompt import Prompt | ||
|
||
|
||
class CardPipeline: | ||
def __init__( | ||
self, | ||
document_factory: DocumentFactory, | ||
prompt_extractors: Sequence[PromptExtractor], | ||
card_exporter: CardExporter, | ||
) -> None: | ||
self.document_factory = document_factory | ||
self.prompt_extractors = prompt_extractors | ||
self.card_exporter = card_exporter | ||
|
||
def run( | ||
self, | ||
input_path: Path, | ||
) -> List[AnkiCard]: | ||
notes: List[Document] = [] | ||
if input_path.is_dir(): | ||
notes += list(self.document_factory.get_notes_from_dir(dir_path=input_path)) | ||
|
||
if not input_path.is_dir(): | ||
note_from_file = self.document_factory.get_note_from_file( | ||
file_path=input_path, | ||
) | ||
notes.append(note_from_file) | ||
|
||
collected_prompts: list[Prompt] = [] | ||
|
||
for extractor in self.prompt_extractors: | ||
for note in notes: | ||
collected_prompts += extractor.extract_prompts(note) | ||
|
||
cards: list[AnkiCard] = self.card_exporter.prompts_to_cards( | ||
prompts=collected_prompts, | ||
) | ||
return cards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from abc import ABC, abstractmethod | ||
from collections.abc import Sequence | ||
|
||
from personal_mnemonic_medium.exporters.anki.card_types.base import AnkiCard | ||
from personal_mnemonic_medium.prompt_extractors.prompt import Prompt | ||
|
||
|
||
class CardExporter(ABC): | ||
@abstractmethod | ||
def prompts_to_cards(self, prompts: Sequence[Prompt]) -> list[AnkiCard]: | ||
pass |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from abc import ABC, abstractmethod | ||
from collections.abc import Sequence | ||
from pathlib import Path | ||
|
||
from personal_mnemonic_medium.note_factories.note import Document | ||
|
||
|
||
class DocumentFactory(ABC): | ||
@abstractmethod | ||
def get_notes_from_dir(self, dir_path: Path) -> Sequence[Document]: | ||
pass | ||
|
||
@abstractmethod | ||
def get_note_from_file(self, file_path: Path) -> Document: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from abc import ABC, abstractmethod | ||
from collections.abc import Sequence | ||
|
||
from personal_mnemonic_medium.note_factories.note import Document | ||
from personal_mnemonic_medium.prompt_extractors.prompt import Prompt | ||
|
||
|
||
class PromptExtractor(ABC): | ||
@abstractmethod | ||
def extract_prompts(self, note: Document) -> Sequence[Prompt]: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.