mirror of
https://github.com/Ascyii/typstar.git
synced 2026-01-01 05:24:24 -05:00
style: format python
This commit is contained in:
@@ -18,7 +18,11 @@ class RecursiveConfigParser:
|
|||||||
def _parse_recursive(self):
|
def _parse_recursive(self):
|
||||||
files = []
|
files = []
|
||||||
for target in self.targets:
|
for target in self.targets:
|
||||||
files.extend(glob(f"{self.dir}/**/{target}", include_hidden=target.startswith("."), recursive=True))
|
files.extend(
|
||||||
|
glob(
|
||||||
|
f"{self.dir}/**/{target}", include_hidden=target.startswith("."), recursive=True
|
||||||
|
)
|
||||||
|
)
|
||||||
for file in files:
|
for file in files:
|
||||||
file = Path(file)
|
file = Path(file)
|
||||||
if file.name in self.targets:
|
if file.name in self.targets:
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing_extensions import Annotated
|
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
|
from typing_extensions import Annotated
|
||||||
|
|
||||||
from anki.anki_api import AnkiConnectApi
|
from anki.anki_api import AnkiConnectApi
|
||||||
from anki.parser import FlashcardParser
|
from anki.parser import FlashcardParser
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ ts_deck_query = """
|
|||||||
deck_regex = re.compile(r"\W+ANKI:\s*([\S ]*)")
|
deck_regex = re.compile(r"\W+ANKI:\s*([\S ]*)")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class FlashcardParser:
|
class FlashcardParser:
|
||||||
typst_language: tree_sitter.Language
|
typst_language: tree_sitter.Language
|
||||||
typst_parser: tree_sitter.Parser
|
typst_parser: tree_sitter.Parser
|
||||||
@@ -58,7 +56,9 @@ class FlashcardParser:
|
|||||||
self.file_handlers = []
|
self.file_handlers = []
|
||||||
self._load_file_hashes()
|
self._load_file_hashes()
|
||||||
|
|
||||||
def _parse_file(self, file: FileHandler, preamble: str | None, default_deck: str | None) -> List[Flashcard]:
|
def _parse_file(
|
||||||
|
self, file: FileHandler, preamble: str | None, default_deck: str | None
|
||||||
|
) -> List[Flashcard]:
|
||||||
cards = []
|
cards = []
|
||||||
tree = self.typst_parser.parse(file.get_bytes(), encoding="utf8")
|
tree = self.typst_parser.parse(file.get_bytes(), encoding="utf8")
|
||||||
card_captures = self.flashcard_query.captures(tree.root_node)
|
card_captures = self.flashcard_query.captures(tree.root_node)
|
||||||
@@ -136,7 +136,9 @@ class FlashcardParser:
|
|||||||
fh = FileHandler(file)
|
fh = FileHandler(file)
|
||||||
file_changed = self._hash_changed(fh)
|
file_changed = self._hash_changed(fh)
|
||||||
if is_force_scan or file_changed:
|
if is_force_scan or file_changed:
|
||||||
cards = self._parse_file(fh, configs.get_config(file, ".anki.typ"), configs.get_config(file, ".anki"))
|
cards = self._parse_file(
|
||||||
|
fh, configs.get_config(file, ".anki.typ"), configs.get_config(file, ".anki")
|
||||||
|
)
|
||||||
self.file_handlers.append((fh, cards))
|
self.file_handlers.append((fh, cards))
|
||||||
flashcards.extend(cards)
|
flashcards.extend(cards)
|
||||||
return flashcards
|
return flashcards
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user