From 5680ad9663075465f5454b1f34311b349ade30e6 Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Sun, 19 Nov 2023 09:45:52 +0100 Subject: [PATCH] refactor: fix import errors after folder restructure (#202) Auto-created --------- Co-authored-by: github-actions --- .github/workflows/stalebot.yml | 4 +- .vscode/settings.json | 11 ----- makefile | 12 +++-- .../{exporters => data_access}/__init__.py | 0 .../document_ingesters}/__init__.py | 0 .../document_ingesters}/base.py | 4 +- .../document_ingesters/document.py} | 0 .../document_ingesters/markdown_ingester.py} | 6 ++- .../exporters}/__init__.py | 0 .../data_access/exporters/anki/__init__.py | 0 .../exporters/anki/anki_css.py | 0 .../exporters/anki/card_types/base.py | 12 +++-- .../exporters/anki/card_types/cloze.py | 14 +++--- .../exporters/anki/card_types/qa.py | 22 +++++---- .../exporters/anki/card_types/test_cards.md} | 0 .../exporters/anki/card_types/test_cards.py} | 45 +++++++++---------- .../exporters/anki/globals.py | 2 +- .../exporters/anki/package_generator.py | 18 +++++--- .../{ => data_access}/exporters/anki/sync.py | 4 +- .../exporters/anki/test_package_generator.py | 12 ++--- .../{ => data_access}/exporters/base.py | 6 ++- .../{ => domain}/card_pipeline.py | 20 ++++++--- .../markdown_to_html.py} | 4 +- .../{ => domain}/prompt_extractors/base.py | 8 +++- .../prompt_extractors/cloze_extractor.py | 10 +++-- .../{ => domain}/prompt_extractors/prompt.py | 4 +- .../prompt_extractors/qa_extractor.py | 10 +++-- .../prompt_extractors/test_cloze_extractor.py | 6 ++- .../prompt_extractors/test_qa_extractor.py} | 6 ++- .../url_generators/1writer_url.py | 0 .../url_generators/obsidian_url.py | 0 personal_mnemonic_medium/main.py | 18 ++++---- .../{ => presentation}/cli.py | 0 .../tests/integration_test.sh | 2 +- .../note_factories/test_markdown_extractor.py | 28 ------------ pyproject.toml | 1 + 36 files changed, 152 insertions(+), 137 deletions(-) rename personal_mnemonic_medium/{exporters => data_access}/__init__.py (100%) rename personal_mnemonic_medium/{exporters/anki => data_access/document_ingesters}/__init__.py (100%) rename personal_mnemonic_medium/{note_factories => data_access/document_ingesters}/base.py (78%) rename personal_mnemonic_medium/{note_factories/note.py => data_access/document_ingesters/document.py} (100%) rename personal_mnemonic_medium/{note_factories/markdown.py => data_access/document_ingesters/markdown_ingester.py} (93%) rename personal_mnemonic_medium/{note_factories => data_access/exporters}/__init__.py (100%) create mode 100644 personal_mnemonic_medium/data_access/exporters/anki/__init__.py rename personal_mnemonic_medium/{ => data_access}/exporters/anki/anki_css.py (100%) rename personal_mnemonic_medium/{ => data_access}/exporters/anki/card_types/base.py (94%) rename personal_mnemonic_medium/{ => data_access}/exporters/anki/card_types/cloze.py (79%) rename personal_mnemonic_medium/{ => data_access}/exporters/anki/card_types/qa.py (66%) rename personal_mnemonic_medium/{tests/test_md_files/test_card_guid.md => data_access/exporters/anki/card_types/test_cards.md} (100%) rename personal_mnemonic_medium/{tests/exporters/anki/test_card_converter.py => data_access/exporters/anki/card_types/test_cards.py} (79%) rename personal_mnemonic_medium/{ => data_access}/exporters/anki/globals.py (96%) rename personal_mnemonic_medium/{ => data_access}/exporters/anki/package_generator.py (85%) rename personal_mnemonic_medium/{ => data_access}/exporters/anki/sync.py (98%) rename personal_mnemonic_medium/{tests => data_access}/exporters/anki/test_package_generator.py (76%) rename personal_mnemonic_medium/{ => data_access}/exporters/base.py (59%) rename personal_mnemonic_medium/{ => domain}/card_pipeline.py (72%) rename personal_mnemonic_medium/{exporters/markdown_to_html/html_compiler.py => domain/markdown_to_html.py} (95%) rename personal_mnemonic_medium/{ => domain}/prompt_extractors/base.py (53%) rename personal_mnemonic_medium/{ => domain}/prompt_extractors/cloze_extractor.py (92%) rename personal_mnemonic_medium/{ => domain}/prompt_extractors/prompt.py (76%) rename personal_mnemonic_medium/{ => domain}/prompt_extractors/qa_extractor.py (93%) rename personal_mnemonic_medium/{tests => domain}/prompt_extractors/test_cloze_extractor.py (81%) rename personal_mnemonic_medium/{tests/prompt_extractors/test_qa_prompt_extractor.py => domain/prompt_extractors/test_qa_extractor.py} (91%) rename personal_mnemonic_medium/{exporters => domain}/url_generators/1writer_url.py (100%) rename personal_mnemonic_medium/{exporters => domain}/url_generators/obsidian_url.py (100%) rename personal_mnemonic_medium/{ => presentation}/cli.py (100%) delete mode 100644 personal_mnemonic_medium/tests/note_factories/test_markdown_extractor.py diff --git a/.github/workflows/stalebot.yml b/.github/workflows/stalebot.yml index 9a2d2d6..16dc7d5 100644 --- a/.github/workflows/stalebot.yml +++ b/.github/workflows/stalebot.yml @@ -10,8 +10,8 @@ jobs: steps: - uses: actions/stale@v6 with: - days-before-issue-stale: 14 - days-before-issue-close: 7 + days-before-issue-stale: 9999 + days-before-issue-close: 9999 stale-issue-message: "This issue is stale because it has been open for 14 days with no activity. Feel free to either 1) remove the stale label or 2) comment. If nothing happens, this will be closed in 7 days." close-issue-message: "This issue was closed automatically. Feel free to re-open it if it's important." days-before-pr-stale: 2 diff --git a/.vscode/settings.json b/.vscode/settings.json index 64c840d..982f91a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,16 +6,5 @@ "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, "explorer.excludeGitIgnore": false, - "files.exclude": { - "**/.git": true, - "**/.svn": true, - "**/.hg": true, - "**/CVS": true, - "**/.DS_Store": true, - "**/Thumbs.db": true, - "**/BUILD": true, - "*.egg-info": true, - "*.pytest_cache": true, - }, "python.analysis.diagnosticMode": "workspace" } \ No newline at end of file diff --git a/makefile b/makefile index 2241462..1c73d54 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,9 @@ SRC_PATH = personal_mnemonic_medium +# TODO: https://github.com/MartinBernstorff/personal-mnemonic-medium/issues/205 Decrease makefile verbosity +# E.g. entering/leaving directory +# Or showing each command when running make pr + deploy: ./docker_cmd.sh @@ -14,11 +18,11 @@ install: pip install -e . test: ## Run tests - pytest personal_mnemonic_medium/tests + pytest personal_mnemonic_medium test-cov: ## Run tests with coverage # TODO: https://github.com/MartinBernstorff/personal-mnemonic-medium/issues/209 Fix coverage and add it to make pr - pytest --cov=personal_mnemonic_medium --cov-report=term-missing personal_mnemonic_medium/tests + pytest --cov=personal_mnemonic_medium --cov-report=term-missing personal_mnemonic_medium lint: ## Format code ruff format . @@ -26,12 +30,12 @@ lint: ## Format code --extend-select F401 \ --extend-select F841 -type-check: ## Type-check code +types: ## Type-check code pyright $(SRC_PATH) validate: ## Run all checks make lint - make type-check + make types make test merge-main: diff --git a/personal_mnemonic_medium/exporters/__init__.py b/personal_mnemonic_medium/data_access/__init__.py similarity index 100% rename from personal_mnemonic_medium/exporters/__init__.py rename to personal_mnemonic_medium/data_access/__init__.py diff --git a/personal_mnemonic_medium/exporters/anki/__init__.py b/personal_mnemonic_medium/data_access/document_ingesters/__init__.py similarity index 100% rename from personal_mnemonic_medium/exporters/anki/__init__.py rename to personal_mnemonic_medium/data_access/document_ingesters/__init__.py diff --git a/personal_mnemonic_medium/note_factories/base.py b/personal_mnemonic_medium/data_access/document_ingesters/base.py similarity index 78% rename from personal_mnemonic_medium/note_factories/base.py rename to personal_mnemonic_medium/data_access/document_ingesters/base.py index 75f91c7..4a3ff4a 100644 --- a/personal_mnemonic_medium/note_factories/base.py +++ b/personal_mnemonic_medium/data_access/document_ingesters/base.py @@ -2,7 +2,9 @@ from collections.abc import Sequence from pathlib import Path -from personal_mnemonic_medium.note_factories.note import Document +from personal_mnemonic_medium.data_access.document_ingesters.document import ( + Document, +) class DocumentFactory(ABC): diff --git a/personal_mnemonic_medium/note_factories/note.py b/personal_mnemonic_medium/data_access/document_ingesters/document.py similarity index 100% rename from personal_mnemonic_medium/note_factories/note.py rename to personal_mnemonic_medium/data_access/document_ingesters/document.py diff --git a/personal_mnemonic_medium/note_factories/markdown.py b/personal_mnemonic_medium/data_access/document_ingesters/markdown_ingester.py similarity index 93% rename from personal_mnemonic_medium/note_factories/markdown.py rename to personal_mnemonic_medium/data_access/document_ingesters/markdown_ingester.py index 455d3e3..579b3ff 100644 --- a/personal_mnemonic_medium/note_factories/markdown.py +++ b/personal_mnemonic_medium/data_access/document_ingesters/markdown_ingester.py @@ -5,10 +5,12 @@ from tqdm import tqdm -from personal_mnemonic_medium.note_factories.base import ( +from personal_mnemonic_medium.data_access.document_ingesters.base import ( DocumentFactory, ) -from personal_mnemonic_medium.note_factories.note import Document +from personal_mnemonic_medium.data_access.document_ingesters.document import ( + Document, +) class MarkdownNoteFactory(DocumentFactory): diff --git a/personal_mnemonic_medium/note_factories/__init__.py b/personal_mnemonic_medium/data_access/exporters/__init__.py similarity index 100% rename from personal_mnemonic_medium/note_factories/__init__.py rename to personal_mnemonic_medium/data_access/exporters/__init__.py diff --git a/personal_mnemonic_medium/data_access/exporters/anki/__init__.py b/personal_mnemonic_medium/data_access/exporters/anki/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/personal_mnemonic_medium/exporters/anki/anki_css.py b/personal_mnemonic_medium/data_access/exporters/anki/anki_css.py similarity index 100% rename from personal_mnemonic_medium/exporters/anki/anki_css.py rename to personal_mnemonic_medium/data_access/exporters/anki/anki_css.py diff --git a/personal_mnemonic_medium/exporters/anki/card_types/base.py b/personal_mnemonic_medium/data_access/exporters/anki/card_types/base.py similarity index 94% rename from personal_mnemonic_medium/exporters/anki/card_types/base.py rename to personal_mnemonic_medium/data_access/exporters/anki/card_types/base.py index 7e5b8ab..ba33a88 100644 --- a/personal_mnemonic_medium/exporters/anki/card_types/base.py +++ b/personal_mnemonic_medium/data_access/exporters/anki/card_types/base.py @@ -8,14 +8,18 @@ import genanki -from personal_mnemonic_medium.exporters.markdown_to_html.html_compiler import ( +from personal_mnemonic_medium.data_access.document_ingesters.document import ( + Document, +) +from personal_mnemonic_medium.domain.markdown_to_html import ( compile_field, ) -from personal_mnemonic_medium.exporters.url_generators.obsidian_url import ( +from personal_mnemonic_medium.domain.prompt_extractors.prompt import ( + Prompt, +) +from personal_mnemonic_medium.domain.url_generators.obsidian_url import ( get_obsidian_url, ) -from personal_mnemonic_medium.note_factories.note import Document -from personal_mnemonic_medium.prompt_extractors.prompt import Prompt class AnkiCard(ABC): diff --git a/personal_mnemonic_medium/exporters/anki/card_types/cloze.py b/personal_mnemonic_medium/data_access/exporters/anki/card_types/cloze.py similarity index 79% rename from personal_mnemonic_medium/exporters/anki/card_types/cloze.py rename to personal_mnemonic_medium/data_access/exporters/anki/card_types/cloze.py index f6cf771..0ad173f 100644 --- a/personal_mnemonic_medium/exporters/anki/card_types/cloze.py +++ b/personal_mnemonic_medium/data_access/exporters/anki/card_types/cloze.py @@ -4,17 +4,21 @@ import genanki -from personal_mnemonic_medium.exporters.anki.card_types.base import ( +from personal_mnemonic_medium.data_access.exporters.anki.card_types.base import ( AnkiCard, ) -from personal_mnemonic_medium.exporters.anki.globals import CONFIG -from personal_mnemonic_medium.exporters.markdown_to_html.html_compiler import ( +from personal_mnemonic_medium.data_access.exporters.anki.globals import ( + CONFIG, +) +from personal_mnemonic_medium.domain.markdown_to_html import ( compile_field, ) -from personal_mnemonic_medium.exporters.url_generators.obsidian_url import ( +from personal_mnemonic_medium.domain.prompt_extractors.prompt import ( + Prompt, +) +from personal_mnemonic_medium.domain.url_generators.obsidian_url import ( get_obsidian_url, ) -from personal_mnemonic_medium.prompt_extractors.prompt import Prompt from personal_mnemonic_medium.utils.hasher import simple_hash diff --git a/personal_mnemonic_medium/exporters/anki/card_types/qa.py b/personal_mnemonic_medium/data_access/exporters/anki/card_types/qa.py similarity index 66% rename from personal_mnemonic_medium/exporters/anki/card_types/qa.py rename to personal_mnemonic_medium/data_access/exporters/anki/card_types/qa.py index 7f7afc3..98c0a7c 100644 --- a/personal_mnemonic_medium/exporters/anki/card_types/qa.py +++ b/personal_mnemonic_medium/data_access/exporters/anki/card_types/qa.py @@ -2,19 +2,22 @@ from pathlib import Path import genanki -from personal_mnemonic_medium.exporters.anki.card_types.base import ( +from personal_mnemonic_medium.data_access.exporters.anki.card_types.base import ( AnkiCard, ) -from personal_mnemonic_medium.exporters.anki.globals import CONFIG -from personal_mnemonic_medium.exporters.markdown_to_html.html_compiler import ( +from personal_mnemonic_medium.domain.markdown_to_html import ( compile_field, ) -from personal_mnemonic_medium.exporters.url_generators.obsidian_url import ( +from personal_mnemonic_medium.domain.url_generators.obsidian_url import ( get_obsidian_url, ) -from personal_mnemonic_medium.prompt_extractors.prompt import Prompt +from personal_mnemonic_medium.domain.prompt_extractors.prompt import ( + Prompt, +) from personal_mnemonic_medium.utils.hasher import simple_hash -from personal_mnemonic_medium.exporters.anki.globals import CONFIG # noqa +from personal_mnemonic_medium.data_access.exporters.anki.globals import ( # noqa + CONFIG, +) class AnkiQA(AnkiCard): @@ -39,12 +42,13 @@ def genanki_model(self) -> genanki.Model: global CONFIG # noqa return genanki.Model( model_id=simple_hash(CONFIG["card_model_name_qa"]), # type: ignore - name=CONFIG["card_model_name_qa"], - fields=CONFIG["card_model_fields_qa"], - templates=CONFIG["card_model_template_qa"], + name=CONFIG["card_model_name_qa"], # type: ignore + fields=CONFIG["card_model_fields_qa"], # type: ignore + templates=CONFIG["card_model_template_qa"], # type: ignore css=CONFIG["card_model_css"], # type: ignore model_type=0, ) + # TODO: https://github.com/MartinBernstorff/personal-mnemonic-medium/issues/203 Refactor the CONFIG to be a dataclass @property def card_uuid(self) -> int: diff --git a/personal_mnemonic_medium/tests/test_md_files/test_card_guid.md b/personal_mnemonic_medium/data_access/exporters/anki/card_types/test_cards.md similarity index 100% rename from personal_mnemonic_medium/tests/test_md_files/test_card_guid.md rename to personal_mnemonic_medium/data_access/exporters/anki/card_types/test_cards.md diff --git a/personal_mnemonic_medium/tests/exporters/anki/test_card_converter.py b/personal_mnemonic_medium/data_access/exporters/anki/card_types/test_cards.py similarity index 79% rename from personal_mnemonic_medium/tests/exporters/anki/test_card_converter.py rename to personal_mnemonic_medium/data_access/exporters/anki/card_types/test_cards.py index 9cb5ed4..b7b2305 100644 --- a/personal_mnemonic_medium/tests/exporters/anki/test_card_converter.py +++ b/personal_mnemonic_medium/data_access/exporters/anki/card_types/test_cards.py @@ -1,31 +1,35 @@ from collections.abc import Sequence from pathlib import Path -from personal_mnemonic_medium.card_pipeline import CardPipeline -from personal_mnemonic_medium.exporters.anki.card_types.base import ( +from personal_mnemonic_medium.data_access.document_ingesters.base import ( + DocumentFactory, +) +from personal_mnemonic_medium.data_access.document_ingesters.document import ( + Document, +) +from personal_mnemonic_medium.data_access.document_ingesters.markdown_ingester import ( + MarkdownNoteFactory, +) +from personal_mnemonic_medium.data_access.exporters.anki.card_types.base import ( AnkiCard, ) -from personal_mnemonic_medium.exporters.anki.card_types.qa import ( +from personal_mnemonic_medium.data_access.exporters.anki.card_types.qa import ( AnkiQA, ) -from personal_mnemonic_medium.exporters.anki.package_generator import ( +from personal_mnemonic_medium.data_access.exporters.anki.package_generator import ( AnkiPackageGenerator, ) -from personal_mnemonic_medium.exporters.base import CardExporter -from personal_mnemonic_medium.note_factories.base import ( - DocumentFactory, -) -from personal_mnemonic_medium.note_factories.markdown import ( - MarkdownNoteFactory, +from personal_mnemonic_medium.data_access.exporters.base import ( + CardExporter, ) -from personal_mnemonic_medium.note_factories.note import Document -from personal_mnemonic_medium.prompt_extractors.base import ( +from personal_mnemonic_medium.domain.card_pipeline import CardPipeline +from personal_mnemonic_medium.domain.prompt_extractors.base import ( PromptExtractor, ) -from personal_mnemonic_medium.prompt_extractors.cloze_extractor import ( +from personal_mnemonic_medium.domain.prompt_extractors.cloze_extractor import ( ClozePromptExtractor, ) -from personal_mnemonic_medium.prompt_extractors.qa_extractor import ( +from personal_mnemonic_medium.domain.prompt_extractors.qa_extractor import ( QAPrompt, QAPromptExtractor, ) @@ -91,11 +95,8 @@ def test_get_subtags(): def test_qa_uuid_generation(): - file_path = ( - Path(__file__).parent.parent.parent - / "test_md_files" - / "test_card_guid.md" - ) + # TODO: https://github.com/MartinBernstorff/personal-mnemonic-medium/issues/204 Remove dependency on test_md_files + file_path = Path(__file__).parent / "test_cards.md" cards = MockCardPipeline( prompt_extractors=[QAPromptExtractor()] ).run(input_path=file_path) @@ -109,11 +110,7 @@ def test_qa_uuid_generation(): def test_cloze_uuid_generation(): - file_path = ( - Path(__file__).parent.parent.parent - / "test_md_files" - / "test_card_guid.md" - ) + file_path = Path(__file__).parent / "test_cards.md" cloze_cards = MockCardPipeline( prompt_extractors=[ClozePromptExtractor()] ).run(input_path=file_path) diff --git a/personal_mnemonic_medium/exporters/anki/globals.py b/personal_mnemonic_medium/data_access/exporters/anki/globals.py similarity index 96% rename from personal_mnemonic_medium/exporters/anki/globals.py rename to personal_mnemonic_medium/data_access/exporters/anki/globals.py index b0adbbd..f30bfa9 100644 --- a/personal_mnemonic_medium/exporters/anki/globals.py +++ b/personal_mnemonic_medium/data_access/exporters/anki/globals.py @@ -2,7 +2,7 @@ import textwrap from typing import Any -from personal_mnemonic_medium.exporters.anki.anki_css import ( +from personal_mnemonic_medium.data_access.exporters.anki.anki_css import ( CARD_MODEL_CSS, ) diff --git a/personal_mnemonic_medium/exporters/anki/package_generator.py b/personal_mnemonic_medium/data_access/exporters/anki/package_generator.py similarity index 85% rename from personal_mnemonic_medium/exporters/anki/package_generator.py rename to personal_mnemonic_medium/data_access/exporters/anki/package_generator.py index 47b9616..7d113a2 100644 --- a/personal_mnemonic_medium/exporters/anki/package_generator.py +++ b/personal_mnemonic_medium/data_access/exporters/anki/package_generator.py @@ -11,21 +11,25 @@ import genanki -from personal_mnemonic_medium.exporters.anki.card_types.base import ( +from personal_mnemonic_medium.data_access.exporters.anki.card_types.base import ( AnkiCard, ) -from personal_mnemonic_medium.exporters.anki.card_types.cloze import ( +from personal_mnemonic_medium.data_access.exporters.anki.card_types.cloze import ( AnkiCloze, ) -from personal_mnemonic_medium.exporters.anki.card_types.qa import ( +from personal_mnemonic_medium.data_access.exporters.anki.card_types.qa import ( AnkiQA, ) -from personal_mnemonic_medium.exporters.base import CardExporter -from personal_mnemonic_medium.prompt_extractors.cloze_extractor import ( +from personal_mnemonic_medium.data_access.exporters.base import ( + CardExporter, +) +from personal_mnemonic_medium.domain.prompt_extractors.cloze_extractor import ( ClozePrompt, ) -from personal_mnemonic_medium.prompt_extractors.prompt import Prompt -from personal_mnemonic_medium.prompt_extractors.qa_extractor import ( +from personal_mnemonic_medium.domain.prompt_extractors.prompt import ( + Prompt, +) +from personal_mnemonic_medium.domain.prompt_extractors.qa_extractor import ( QAPrompt, ) from personal_mnemonic_medium.utils.hasher import simple_hash diff --git a/personal_mnemonic_medium/exporters/anki/sync.py b/personal_mnemonic_medium/data_access/exporters/anki/sync.py similarity index 98% rename from personal_mnemonic_medium/exporters/anki/sync.py rename to personal_mnemonic_medium/data_access/exporters/anki/sync.py index 0db42f0..3afdb01 100644 --- a/personal_mnemonic_medium/exporters/anki/sync.py +++ b/personal_mnemonic_medium/data_access/exporters/anki/sync.py @@ -8,10 +8,10 @@ from genanki import Model, Note from wasabi import Printer -from personal_mnemonic_medium.exporters.anki.globals import ( +from personal_mnemonic_medium.data_access.exporters.anki.globals import ( ANKICONNECT_URL, ) -from personal_mnemonic_medium.exporters.anki.package_generator import ( +from personal_mnemonic_medium.data_access.exporters.anki.package_generator import ( DeckBundle, ) diff --git a/personal_mnemonic_medium/tests/exporters/anki/test_package_generator.py b/personal_mnemonic_medium/data_access/exporters/anki/test_package_generator.py similarity index 76% rename from personal_mnemonic_medium/tests/exporters/anki/test_package_generator.py rename to personal_mnemonic_medium/data_access/exporters/anki/test_package_generator.py index ba41cfd..92f659c 100644 --- a/personal_mnemonic_medium/tests/exporters/anki/test_package_generator.py +++ b/personal_mnemonic_medium/data_access/exporters/anki/test_package_generator.py @@ -1,16 +1,18 @@ from pathlib import Path -from personal_mnemonic_medium.exporters.anki.card_types.base import ( +from personal_mnemonic_medium.data_access.document_ingesters.document import ( + Document, +) +from personal_mnemonic_medium.data_access.exporters.anki.card_types.base import ( AnkiCard, ) -from personal_mnemonic_medium.exporters.anki.card_types.qa import ( +from personal_mnemonic_medium.data_access.exporters.anki.card_types.qa import ( AnkiQA, ) -from personal_mnemonic_medium.exporters.anki.package_generator import ( +from personal_mnemonic_medium.data_access.exporters.anki.package_generator import ( AnkiPackageGenerator, ) -from personal_mnemonic_medium.note_factories.note import Document -from personal_mnemonic_medium.prompt_extractors.qa_extractor import ( +from personal_mnemonic_medium.domain.prompt_extractors.qa_extractor import ( QAPrompt, ) diff --git a/personal_mnemonic_medium/exporters/base.py b/personal_mnemonic_medium/data_access/exporters/base.py similarity index 59% rename from personal_mnemonic_medium/exporters/base.py rename to personal_mnemonic_medium/data_access/exporters/base.py index 3e13b75..088cc54 100644 --- a/personal_mnemonic_medium/exporters/base.py +++ b/personal_mnemonic_medium/data_access/exporters/base.py @@ -1,10 +1,12 @@ from abc import ABC, abstractmethod from collections.abc import Sequence -from personal_mnemonic_medium.exporters.anki.card_types.base import ( +from personal_mnemonic_medium.data_access.exporters.anki.card_types.base import ( AnkiCard, ) -from personal_mnemonic_medium.prompt_extractors.prompt import Prompt +from personal_mnemonic_medium.domain.prompt_extractors.prompt import ( + Prompt, +) class CardExporter(ABC): diff --git a/personal_mnemonic_medium/card_pipeline.py b/personal_mnemonic_medium/domain/card_pipeline.py similarity index 72% rename from personal_mnemonic_medium/card_pipeline.py rename to personal_mnemonic_medium/domain/card_pipeline.py index c11beca..57b6b9b 100644 --- a/personal_mnemonic_medium/card_pipeline.py +++ b/personal_mnemonic_medium/domain/card_pipeline.py @@ -1,18 +1,24 @@ from collections.abc import Sequence from pathlib import Path -from personal_mnemonic_medium.exporters.anki.card_types.base import ( +from personal_mnemonic_medium.data_access.document_ingesters.base import ( + DocumentFactory, +) +from personal_mnemonic_medium.data_access.document_ingesters.document import ( + Document, +) +from personal_mnemonic_medium.data_access.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.data_access.exporters.base import ( + CardExporter, ) -from personal_mnemonic_medium.note_factories.note import Document -from personal_mnemonic_medium.prompt_extractors.base import ( +from personal_mnemonic_medium.domain.prompt_extractors.base import ( PromptExtractor, ) -from personal_mnemonic_medium.prompt_extractors.prompt import Prompt +from personal_mnemonic_medium.domain.prompt_extractors.prompt import ( + Prompt, +) class CardPipeline: diff --git a/personal_mnemonic_medium/exporters/markdown_to_html/html_compiler.py b/personal_mnemonic_medium/domain/markdown_to_html.py similarity index 95% rename from personal_mnemonic_medium/exporters/markdown_to_html/html_compiler.py rename to personal_mnemonic_medium/domain/markdown_to_html.py index 9857f26..d14a446 100644 --- a/personal_mnemonic_medium/exporters/markdown_to_html/html_compiler.py +++ b/personal_mnemonic_medium/domain/markdown_to_html.py @@ -3,7 +3,9 @@ import misaka -from personal_mnemonic_medium.exporters.anki.globals import CONFIG +from personal_mnemonic_medium.data_access.exporters.anki.globals import ( + CONFIG, +) def field_to_html(field: Any) -> str: diff --git a/personal_mnemonic_medium/prompt_extractors/base.py b/personal_mnemonic_medium/domain/prompt_extractors/base.py similarity index 53% rename from personal_mnemonic_medium/prompt_extractors/base.py rename to personal_mnemonic_medium/domain/prompt_extractors/base.py index a731abd..9fdc6d8 100644 --- a/personal_mnemonic_medium/prompt_extractors/base.py +++ b/personal_mnemonic_medium/domain/prompt_extractors/base.py @@ -1,8 +1,12 @@ 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 +from personal_mnemonic_medium.data_access.document_ingesters.document import ( + Document, +) +from personal_mnemonic_medium.domain.prompt_extractors.prompt import ( + Prompt, +) class PromptExtractor(ABC): diff --git a/personal_mnemonic_medium/prompt_extractors/cloze_extractor.py b/personal_mnemonic_medium/domain/prompt_extractors/cloze_extractor.py similarity index 92% rename from personal_mnemonic_medium/prompt_extractors/cloze_extractor.py rename to personal_mnemonic_medium/domain/prompt_extractors/cloze_extractor.py index 1095aec..936da94 100644 --- a/personal_mnemonic_medium/prompt_extractors/cloze_extractor.py +++ b/personal_mnemonic_medium/domain/prompt_extractors/cloze_extractor.py @@ -3,11 +3,15 @@ from collections.abc import Sequence from typing import Any -from personal_mnemonic_medium.note_factories.note import Document -from personal_mnemonic_medium.prompt_extractors.base import ( +from personal_mnemonic_medium.data_access.document_ingesters.document import ( + Document, +) +from personal_mnemonic_medium.domain.prompt_extractors.base import ( PromptExtractor, ) -from personal_mnemonic_medium.prompt_extractors.prompt import Prompt +from personal_mnemonic_medium.domain.prompt_extractors.prompt import ( + Prompt, +) class ClozePrompt(Prompt): diff --git a/personal_mnemonic_medium/prompt_extractors/prompt.py b/personal_mnemonic_medium/domain/prompt_extractors/prompt.py similarity index 76% rename from personal_mnemonic_medium/prompt_extractors/prompt.py rename to personal_mnemonic_medium/domain/prompt_extractors/prompt.py index 147ddc7..8ce07c6 100644 --- a/personal_mnemonic_medium/prompt_extractors/prompt.py +++ b/personal_mnemonic_medium/domain/prompt_extractors/prompt.py @@ -1,4 +1,6 @@ -from personal_mnemonic_medium.note_factories.note import Document +from personal_mnemonic_medium.data_access.document_ingesters.document import ( + Document, +) class Prompt: diff --git a/personal_mnemonic_medium/prompt_extractors/qa_extractor.py b/personal_mnemonic_medium/domain/prompt_extractors/qa_extractor.py similarity index 93% rename from personal_mnemonic_medium/prompt_extractors/qa_extractor.py rename to personal_mnemonic_medium/domain/prompt_extractors/qa_extractor.py index 82c13e0..4e533e8 100644 --- a/personal_mnemonic_medium/prompt_extractors/qa_extractor.py +++ b/personal_mnemonic_medium/domain/prompt_extractors/qa_extractor.py @@ -3,11 +3,15 @@ from collections.abc import Sequence from typing import Any -from personal_mnemonic_medium.note_factories.note import Document -from personal_mnemonic_medium.prompt_extractors.base import ( +from personal_mnemonic_medium.data_access.document_ingesters.document import ( + Document, +) +from personal_mnemonic_medium.domain.prompt_extractors.base import ( PromptExtractor, ) -from personal_mnemonic_medium.prompt_extractors.prompt import Prompt +from personal_mnemonic_medium.domain.prompt_extractors.prompt import ( + Prompt, +) log = logging.getLogger(__name__) # Log to disk, not to console. diff --git a/personal_mnemonic_medium/tests/prompt_extractors/test_cloze_extractor.py b/personal_mnemonic_medium/domain/prompt_extractors/test_cloze_extractor.py similarity index 81% rename from personal_mnemonic_medium/tests/prompt_extractors/test_cloze_extractor.py rename to personal_mnemonic_medium/domain/prompt_extractors/test_cloze_extractor.py index 8267a4b..95c8b2c 100644 --- a/personal_mnemonic_medium/tests/prompt_extractors/test_cloze_extractor.py +++ b/personal_mnemonic_medium/domain/prompt_extractors/test_cloze_extractor.py @@ -1,7 +1,9 @@ from pathlib import Path -from personal_mnemonic_medium.note_factories.note import Document -from personal_mnemonic_medium.prompt_extractors.cloze_extractor import ( +from personal_mnemonic_medium.data_access.document_ingesters.document import ( + Document, +) +from personal_mnemonic_medium.domain.prompt_extractors.cloze_extractor import ( ClozePromptExtractor, ) diff --git a/personal_mnemonic_medium/tests/prompt_extractors/test_qa_prompt_extractor.py b/personal_mnemonic_medium/domain/prompt_extractors/test_qa_extractor.py similarity index 91% rename from personal_mnemonic_medium/tests/prompt_extractors/test_qa_prompt_extractor.py rename to personal_mnemonic_medium/domain/prompt_extractors/test_qa_extractor.py index a42670b..a6333fa 100644 --- a/personal_mnemonic_medium/tests/prompt_extractors/test_qa_prompt_extractor.py +++ b/personal_mnemonic_medium/domain/prompt_extractors/test_qa_extractor.py @@ -2,8 +2,10 @@ import pytest -from personal_mnemonic_medium.note_factories.note import Document -from personal_mnemonic_medium.prompt_extractors.qa_extractor import ( +from personal_mnemonic_medium.data_access.document_ingesters.document import ( + Document, +) +from personal_mnemonic_medium.domain.prompt_extractors.qa_extractor import ( QAPromptExtractor, ) diff --git a/personal_mnemonic_medium/exporters/url_generators/1writer_url.py b/personal_mnemonic_medium/domain/url_generators/1writer_url.py similarity index 100% rename from personal_mnemonic_medium/exporters/url_generators/1writer_url.py rename to personal_mnemonic_medium/domain/url_generators/1writer_url.py diff --git a/personal_mnemonic_medium/exporters/url_generators/obsidian_url.py b/personal_mnemonic_medium/domain/url_generators/obsidian_url.py similarity index 100% rename from personal_mnemonic_medium/exporters/url_generators/obsidian_url.py rename to personal_mnemonic_medium/domain/url_generators/obsidian_url.py diff --git a/personal_mnemonic_medium/main.py b/personal_mnemonic_medium/main.py index 6f9940f..409d43f 100644 --- a/personal_mnemonic_medium/main.py +++ b/personal_mnemonic_medium/main.py @@ -7,21 +7,23 @@ import typer from wasabi import Printer -from personal_mnemonic_medium.card_pipeline import CardPipeline -from personal_mnemonic_medium.exporters.anki.card_types.base import ( +from personal_mnemonic_medium.data_access.document_ingesters.markdown_ingester import ( + MarkdownNoteFactory, +) +from personal_mnemonic_medium.data_access.exporters.anki.card_types.base import ( AnkiCard, ) -from personal_mnemonic_medium.exporters.anki.package_generator import ( +from personal_mnemonic_medium.data_access.exporters.anki.package_generator import ( AnkiPackageGenerator, ) -from personal_mnemonic_medium.exporters.anki.sync import sync_deck -from personal_mnemonic_medium.note_factories.markdown import ( - MarkdownNoteFactory, +from personal_mnemonic_medium.data_access.exporters.anki.sync import ( + sync_deck, ) -from personal_mnemonic_medium.prompt_extractors.cloze_extractor import ( +from personal_mnemonic_medium.domain.card_pipeline import CardPipeline +from personal_mnemonic_medium.domain.prompt_extractors.cloze_extractor import ( ClozePromptExtractor, ) -from personal_mnemonic_medium.prompt_extractors.qa_extractor import ( +from personal_mnemonic_medium.domain.prompt_extractors.qa_extractor import ( QAPromptExtractor, ) diff --git a/personal_mnemonic_medium/cli.py b/personal_mnemonic_medium/presentation/cli.py similarity index 100% rename from personal_mnemonic_medium/cli.py rename to personal_mnemonic_medium/presentation/cli.py diff --git a/personal_mnemonic_medium/tests/integration_test.sh b/personal_mnemonic_medium/tests/integration_test.sh index fbd839c..b0ecbde 100755 --- a/personal_mnemonic_medium/tests/integration_test.sh +++ b/personal_mnemonic_medium/tests/integration_test.sh @@ -13,7 +13,7 @@ docker run -itd \ -v $OUTPUT_DIR:/output \ --restart unless-stopped \ personal-mnemonic-medium \ - python personal_mnemonic_medium/cli.py /input/ $OUTPUT_DIR \ + python personal_mnemonic_medium/presentation/cli.py /input/ $OUTPUT_DIR \ --watch \ --no-use-anki-connect diff --git a/personal_mnemonic_medium/tests/note_factories/test_markdown_extractor.py b/personal_mnemonic_medium/tests/note_factories/test_markdown_extractor.py deleted file mode 100644 index df8a045..0000000 --- a/personal_mnemonic_medium/tests/note_factories/test_markdown_extractor.py +++ /dev/null @@ -1,28 +0,0 @@ -from pathlib import Path - -PROJECT_ROOT = Path(__file__).parent.parent.parent - -from personal_mnemonic_medium.note_factories.markdown import ( - MarkdownNoteFactory, -) - - -def test_get_notes_from_dir(): - notes = MarkdownNoteFactory().get_notes_from_dir( - PROJECT_ROOT / "tests" / "test_md_files" - ) - - assert len(notes) == 4 - assert ( - len( - [note for note in notes if note.title == "test_card_guid"] - ) - == 1 - ) - assert ( - len([note for note in notes if "7696CDCD" in note.content]) - == 1 - ) - assert ( - len([note for note in notes if "7696CDCD" in note.uuid]) == 1 - ) diff --git a/pyproject.toml b/pyproject.toml index eb34d4a..b21b63d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -136,6 +136,7 @@ suppress-none-returning = true [tool.ruff.isort] known-third-party = ["wandb"] +split-on-trailing-comma = false [tool.ruff.mccabe] # Unlike Flake8, default to a complexity level of 10.