From bfbe55d2241c9ec260e0d2b9d762e30443f453bb Mon Sep 17 00:00:00 2001 From: Martin Bernstorff Date: Fri, 27 Oct 2023 20:25:24 +0200 Subject: [PATCH] ci: remove pull-request template --- .github/pull_request_template.md | 8 -------- application/main.py | 4 ++-- src/personal_mnemonic_medium/card_pipeline.py | 4 ++-- .../exporters/anki/card_types/base.py | 11 ++++++----- .../exporters/anki/card_types/cloze.py | 5 +++-- .../exporters/anki/card_types/qa.py | 5 +++-- .../exporters/anki/globals.py | 2 +- .../exporters/anki/package_generator.py | 8 ++++---- src/personal_mnemonic_medium/exporters/anki/sync.py | 8 ++++---- src/personal_mnemonic_medium/note_factories/note.py | 2 +- .../prompt_extractors/cloze_extractor.py | 2 +- .../prompt_extractors/prompt.py | 2 +- .../prompt_extractors/qa_extractor.py | 2 +- tasks.py | 4 ++-- tests/exporters/anki/test_card_converter.py | 6 +++--- 15 files changed, 34 insertions(+), 39 deletions(-) delete mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index 56f513c..0000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,8 +0,0 @@ -- [ ] I have considered whether this PR needs review, and requested a review if necessary. - -Fixes issue # - -# Notes for reviewers -Reviewers can skip X, but should pay attention to Y. - - \ No newline at end of file diff --git a/application/main.py b/application/main.py index 5a11010..367a804 100644 --- a/application/main.py +++ b/application/main.py @@ -21,7 +21,7 @@ # helper for creating anki connect requests -def request(action: Any, **params: Any) -> Dict[str, Any]: +def request(action: Any, **params: Any) -> dict[str, Any]: return {"action": action, "params": params, "version": 6} @@ -83,6 +83,6 @@ def main( sleep(sleep_seconds) main(input_dir=input_dir, watch=watch, host_output_dir=host_output_dir) - + if __name__ == "__main__": typer.run(main) diff --git a/src/personal_mnemonic_medium/card_pipeline.py b/src/personal_mnemonic_medium/card_pipeline.py index af01007..1bede07 100644 --- a/src/personal_mnemonic_medium/card_pipeline.py +++ b/src/personal_mnemonic_medium/card_pipeline.py @@ -24,8 +24,8 @@ def __init__( def run( self, input_path: Path, - ) -> List[AnkiCard]: - notes: List[Document] = [] + ) -> list[AnkiCard]: + notes: list[Document] = [] if input_path.is_dir(): notes += list(self.document_factory.get_notes_from_dir(dir_path=input_path)) diff --git a/src/personal_mnemonic_medium/exporters/anki/card_types/base.py b/src/personal_mnemonic_medium/exporters/anki/card_types/base.py index 109eb1d..862822d 100644 --- a/src/personal_mnemonic_medium/exporters/anki/card_types/base.py +++ b/src/personal_mnemonic_medium/exporters/anki/card_types/base.py @@ -2,8 +2,9 @@ import os import re from abc import ABC, abstractmethod +from collections.abc import Callable from pathlib import Path -from typing import Any, Callable, List, Optional, Tuple +from typing import Any, List, Optional, Tuple import genanki from personal_mnemonic_medium.exporters.anki.globals import CONFIG @@ -22,7 +23,7 @@ class AnkiCard(ABC): def __init__( self, - fields: List[str], + fields: list[str], source_prompt: Prompt, url_generator: Callable[[Path, Optional[int]], str] = get_obsidian_url, html_compiler: Callable[[str], str] = compile_field, @@ -38,11 +39,11 @@ def source_markdown(self) -> str: return self.source_doc.content @property - def html_fields(self) -> List[str]: + def html_fields(self) -> list[str]: return list(map(self.html_compiler, self.markdown_fields)) @property - def tags(self) -> List[str]: + def tags(self) -> list[str]: return self.source_doc.tags @property @@ -132,7 +133,7 @@ def to_genanki_note(self) -> genanki.Note: tags=self.tags, ) - def make_ref_pair(self, filename: str) -> Tuple[Path, str]: + def make_ref_pair(self, filename: str) -> tuple[Path, str]: """Take a filename relative to the card, and make it absolute.""" newname = "%".join(filename.split(os.sep)) diff --git a/src/personal_mnemonic_medium/exporters/anki/card_types/cloze.py b/src/personal_mnemonic_medium/exporters/anki/card_types/cloze.py index 3e5b854..51df772 100644 --- a/src/personal_mnemonic_medium/exporters/anki/card_types/cloze.py +++ b/src/personal_mnemonic_medium/exporters/anki/card_types/cloze.py @@ -1,6 +1,7 @@ import re +from collections.abc import Callable from pathlib import Path -from typing import Callable, List, Optional +from typing import List, Optional import genanki from personal_mnemonic_medium.exporters.anki.card_types.base import AnkiCard @@ -18,7 +19,7 @@ class AnkiCloze(AnkiCard): def __init__( self, - fields: List[str], + fields: list[str], source_prompt: Prompt, url_generator: Callable[[Path, Optional[int]], str] = get_obsidian_url, html_compiler: Callable[[str], str] = compile_field, diff --git a/src/personal_mnemonic_medium/exporters/anki/card_types/qa.py b/src/personal_mnemonic_medium/exporters/anki/card_types/qa.py index 98310ec..4ecccfa 100644 --- a/src/personal_mnemonic_medium/exporters/anki/card_types/qa.py +++ b/src/personal_mnemonic_medium/exporters/anki/card_types/qa.py @@ -1,5 +1,6 @@ +from collections.abc import Callable from pathlib import Path -from typing import Callable, List, Optional +from typing import List, Optional import genanki from personal_mnemonic_medium.exporters.anki.card_types.base import AnkiCard @@ -17,7 +18,7 @@ class AnkiQA(AnkiCard): def __init__( self, - fields: List[str], + fields: list[str], source_prompt: Prompt, url_generator: Callable[[Path, Optional[int]], str] = get_obsidian_url, html_compiler: Callable[[str], str] = compile_field, diff --git a/src/personal_mnemonic_medium/exporters/anki/globals.py b/src/personal_mnemonic_medium/exporters/anki/globals.py index 6f32482..35f1d1b 100644 --- a/src/personal_mnemonic_medium/exporters/anki/globals.py +++ b/src/personal_mnemonic_medium/exporters/anki/globals.py @@ -84,7 +84,7 @@ "card_model_template_cloze": CLOZE_MODEL_TEMPLATE, } -VERSION_LOG: Dict[Any, Any] = {} +VERSION_LOG: dict[Any, Any] = {} Q_TYPE_TAG = { "G": "med/type/1_GP", "A": "med/type/2_Acute_care", diff --git a/src/personal_mnemonic_medium/exporters/anki/package_generator.py b/src/personal_mnemonic_medium/exporters/anki/package_generator.py index 6fa3191..d99c28f 100644 --- a/src/personal_mnemonic_medium/exporters/anki/package_generator.py +++ b/src/personal_mnemonic_medium/exporters/anki/package_generator.py @@ -43,7 +43,7 @@ def __getitem__(self, deckname: str) -> Any: @dataclass(frozen=True) class DeckBundle: deck: genanki.Deck - media: Set[str] + media: set[str] def get_package(self) -> genanki.Package: return genanki.Package(deck_or_decks=self.deck, media_files=list(self.media)) @@ -61,7 +61,7 @@ def __init__(self) -> None: pass @staticmethod - def cards_to_deck_bundle(cards: List[AnkiCard]) -> DeckBundle: + def cards_to_deck_bundle(cards: list[AnkiCard]) -> DeckBundle: """Take an iterable prompts, output an .apkg in a file called output_name. NOTE: We _must_ be in a temp directory. """ @@ -75,7 +75,7 @@ def cards_to_deck_bundle(cards: List[AnkiCard]) -> DeckBundle: @staticmethod def cards_to_deck( cards: Sequence[AnkiCard], - ) -> tuple[genanki.Deck, Set[str]]: + ) -> tuple[genanki.Deck, set[str]]: media = set() deck_name = cards[0].deckname @@ -103,7 +103,7 @@ def cards_to_deck( def prompts_to_cards( self, prompts: Sequence[Prompt], - ) -> List[AnkiCard]: + ) -> list[AnkiCard]: """Takes an iterable of prompts and turns them into AnkiCards""" cards: list[AnkiCard] = [] diff --git a/src/personal_mnemonic_medium/exporters/anki/sync.py b/src/personal_mnemonic_medium/exporters/anki/sync.py index 33cbc21..4996df2 100644 --- a/src/personal_mnemonic_medium/exporters/anki/sync.py +++ b/src/personal_mnemonic_medium/exporters/anki/sync.py @@ -15,7 +15,7 @@ # helper for creating anki connect requests -def request(action: Any, **params: Any) -> Dict[str, Any]: +def request(action: Any, **params: Any) -> dict[str, Any]: return {"action": action, "params": params, "version": 6} @@ -139,19 +139,19 @@ def sync_deck( def get_md_note_infos(deck_bundle: DeckBundle) -> set[str]: - md_notes: List[Note] = deck_bundle.deck.notes + md_notes: list[Note] = deck_bundle.deck.notes md_note_guids = {str(n.guid) for n in md_notes} return md_note_guids def get_anki_note_infos(deck_bundle: DeckBundle) -> tuple[dict[str, Any], set[str]]: - anki_card_ids: List[int] = invoke( + anki_card_ids: list[int] = invoke( "findCards", query=f'"deck:{deck_bundle.deck.name}"', ) # get a list of anki notes in the deck - anki_note_ids: List[int] = invoke("cardsToNotes", cards=anki_card_ids) + anki_note_ids: list[int] = invoke("cardsToNotes", cards=anki_card_ids) # get the note info for the notes in the deck anki_notes_info = invoke("notesInfo", notes=anki_note_ids) diff --git a/src/personal_mnemonic_medium/note_factories/note.py b/src/personal_mnemonic_medium/note_factories/note.py index cb00172..67e5f4d 100644 --- a/src/personal_mnemonic_medium/note_factories/note.py +++ b/src/personal_mnemonic_medium/note_factories/note.py @@ -43,7 +43,7 @@ def _replace_alias_wiki_links(text: str) -> str: return text - def get_tags(self, input_str: str, import_time: str) -> List[str]: + def get_tags(self, input_str: str, import_time: str) -> list[str]: file_tags = [import_time] if self.has_supplementary_tags(input_str): diff --git a/src/personal_mnemonic_medium/prompt_extractors/cloze_extractor.py b/src/personal_mnemonic_medium/prompt_extractors/cloze_extractor.py index 03f7d9b..9e0a155 100644 --- a/src/personal_mnemonic_medium/prompt_extractors/cloze_extractor.py +++ b/src/personal_mnemonic_medium/prompt_extractors/cloze_extractor.py @@ -19,7 +19,7 @@ def __init__(self) -> None: pass @staticmethod - def _break_string_by_two_or_more_newlines(string: str) -> List[str]: + def _break_string_by_two_or_more_newlines(string: str) -> list[str]: """Break string into a list by 2+ newlines in a row.""" return re.split(r"(\n\n)+", string) diff --git a/src/personal_mnemonic_medium/prompt_extractors/prompt.py b/src/personal_mnemonic_medium/prompt_extractors/prompt.py index b92c0f3..1aa05cf 100644 --- a/src/personal_mnemonic_medium/prompt_extractors/prompt.py +++ b/src/personal_mnemonic_medium/prompt_extractors/prompt.py @@ -8,7 +8,7 @@ def __init__( self, note_uuid: str, source_note: Document, - tags: Optional[List[str]] = None, + tags: Optional[list[str]] = None, line_nr: Optional[int] = None, ): self.tags = tags diff --git a/src/personal_mnemonic_medium/prompt_extractors/qa_extractor.py b/src/personal_mnemonic_medium/prompt_extractors/qa_extractor.py index 50eb2b1..39ed760 100644 --- a/src/personal_mnemonic_medium/prompt_extractors/qa_extractor.py +++ b/src/personal_mnemonic_medium/prompt_extractors/qa_extractor.py @@ -50,7 +50,7 @@ def _get_first_answer(self, string: str) -> str: return answer[len(self.answer_prefix) + 2 :].rstrip() @staticmethod - def _break_string_by_two_or_more_newlines(string: str) -> List[str]: + def _break_string_by_two_or_more_newlines(string: str) -> list[str]: """Break string into a list by 2+ newlines in a row.""" return re.split(r"(\n\n)+", string) diff --git a/tasks.py b/tasks.py index 8de35b2..f1caf01 100644 --- a/tasks.py +++ b/tasks.py @@ -329,7 +329,7 @@ def update(c: Context): @task(iterable="pytest_args") def test( c: Context, - python_versions: List[str] = (SUPPORTED_PYTHON_VERSIONS[0],), # type: ignore + python_versions: list[str] = (SUPPORTED_PYTHON_VERSIONS[0],), # type: ignore pytest_args: List[str] = [], # noqa ): """Run tests""" @@ -382,7 +382,7 @@ def test( def test_for_rej(): # Get all paths in current directory or subdirectories that end in .rej - rej_files = list(Path(".").rglob("*.rej")) + rej_files = list(Path().rglob("*.rej")) if len(rej_files) > 0: print(f"\n{msg_type.FAIL} Found .rej files leftover from cruft update.\n") diff --git a/tests/exporters/anki/test_card_converter.py b/tests/exporters/anki/test_card_converter.py index 0e6c784..0bb1218 100644 --- a/tests/exporters/anki/test_card_converter.py +++ b/tests/exporters/anki/test_card_converter.py @@ -28,8 +28,8 @@ def __init__( self, document_factory: DocumentFactory = MarkdownNoteFactory(), # noqa: B008 prompt_extractors: Sequence[PromptExtractor] = [ - QAPromptExtractor(), # noqa: B008 - ClozePromptExtractor(), # noqa: B008 + QAPromptExtractor(), + ClozePromptExtractor(), ], card_exporter: CardExporter = AnkiPackageGenerator(), # noqa: B008 ) -> None: @@ -42,7 +42,7 @@ def __init__( def test_card_pipeline( self, input_path: Path, - ) -> List[AnkiCard]: + ) -> list[AnkiCard]: return self.run( input_path=input_path, )