mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
move the remaining exports from _backend
This commit is contained in:
parent
260a270eb0
commit
ea31e8ca3e
4 changed files with 23 additions and 43 deletions
|
@ -1,25 +1,9 @@
|
|||
# Copyright: Ankitects Pty Ltd and contributors
|
||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
# pylint: skip-file
|
||||
|
||||
"""
|
||||
Python bindings for Anki's Rust libraries.
|
||||
|
||||
Please do not access methods on the backend directly - they may be changed
|
||||
or removed at any time. Instead, please use the methods on the collection
|
||||
instead. Eg, don't use col.backend.all_deck_config(), instead use
|
||||
col.decks.all_config()
|
||||
|
||||
If you need to access a backend method that is not currently accessible
|
||||
via the collection, please send through a pull request that adds a method.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import enum
|
||||
import json
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Union
|
||||
|
||||
import anki.buildinfo
|
||||
|
@ -38,21 +22,21 @@ if TYPE_CHECKING:
|
|||
|
||||
assert rsbridge.buildhash() == anki.buildinfo.buildhash
|
||||
|
||||
# FIXME: rather than adding new items here, items intended to be consumed
|
||||
# by external libraries (eg aqt) should be exported in the module that
|
||||
# refers to them, eg collection.py
|
||||
SchedTimingToday = pb.SchedTimingTodayOut
|
||||
BackendCard = pb.Card
|
||||
BackendNote = pb.Note
|
||||
Tag = pb.Tag
|
||||
TagTreeNode = pb.TagTreeNode
|
||||
NoteType = pb.NoteType
|
||||
BackendNoteTypeID = pb.NoteTypeID
|
||||
ConcatSeparator = pb.ConcatenateSearchesIn.Separator
|
||||
CountsForDeckToday = pb.CountsForDeckTodayOut
|
||||
|
||||
|
||||
class RustBackend(RustBackendGenerated):
|
||||
"""
|
||||
Python bindings for Anki's Rust libraries.
|
||||
|
||||
Please do not access methods on the backend directly - they may be changed
|
||||
or removed at any time. Instead, please use the methods on the collection
|
||||
instead. Eg, don't use col._backend.all_deck_config(), instead use
|
||||
col.decks.all_config()
|
||||
|
||||
If you need to access a backend method that is not currently accessible
|
||||
via the collection, please send through a pull request that adds a
|
||||
public method.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
ftl_folder: Optional[str] = None,
|
||||
|
|
|
@ -19,20 +19,14 @@ import anki.find
|
|||
import anki.latex # sets up hook
|
||||
import anki.template
|
||||
from anki import hooks
|
||||
from anki._backend import ( # pylint: disable=unused-import
|
||||
ConcatSeparator,
|
||||
FormatTimeSpanContext,
|
||||
RustBackend,
|
||||
)
|
||||
|
||||
# from anki._backend import _SyncStatus as SyncStatus
|
||||
from anki._backend import RustBackend
|
||||
from anki.cards import Card
|
||||
from anki.config import ConfigManager
|
||||
from anki.consts import *
|
||||
from anki.dbproxy import DBProxy
|
||||
from anki.decks import DeckManager
|
||||
from anki.errors import AnkiError, DBError
|
||||
from anki.lang import TR
|
||||
from anki.lang import TR, FormatTimeSpanContext
|
||||
from anki.media import MediaManager, media_paths_from_col_path
|
||||
from anki.models import ModelManager
|
||||
from anki.notes import Note
|
||||
|
@ -551,9 +545,9 @@ class Collection:
|
|||
term = self.backend.filter_to_search(term)
|
||||
searches.append(term)
|
||||
if match_any:
|
||||
sep = ConcatSeparator.OR
|
||||
sep = _pb.ConcatenateSearchesIn.Separator.OR
|
||||
else:
|
||||
sep = ConcatSeparator.AND
|
||||
sep = _pb.ConcatenateSearchesIn.Separator.AND
|
||||
search_string = self.backend.concatenate_searches(sep=sep, searches=searches)
|
||||
if negate:
|
||||
search_string = self.backend.negate_search(search_string)
|
||||
|
|
|
@ -510,5 +510,5 @@ and notes.mid = ? and cards.ord = ?""",
|
|||
self, m: NoteType, flds: str, allowEmpty: bool = True
|
||||
) -> List[int]:
|
||||
print("_availClozeOrds() is deprecated; use note.cloze_numbers_in_fields()")
|
||||
note = anki._backend.BackendNote(fields=[flds])
|
||||
note = _pb.Note(fields=[flds])
|
||||
return list(self.col.backend.cloze_numbers_in_note(note))
|
||||
|
|
|
@ -22,14 +22,16 @@ from typing import (
|
|||
import anki # pylint: disable=unused-import
|
||||
import anki._backend.backend_pb2 as _pb
|
||||
from anki import hooks
|
||||
from anki._backend import CountsForDeckToday, FormatTimeSpanContext, SchedTimingToday
|
||||
from anki.cards import Card
|
||||
from anki.consts import *
|
||||
from anki.decks import Deck, DeckConfig, DeckManager, DeckTreeNode, QueueConfig
|
||||
from anki.lang import FormatTimeSpanContext
|
||||
from anki.notes import Note
|
||||
from anki.utils import from_json_bytes, ids2str, intTime
|
||||
|
||||
CongratsInfoOut = anki._backend.backend_pb2.CongratsInfoOut
|
||||
CongratsInfo = _pb.CongratsInfoOut
|
||||
CountsForDeckToday = _pb.CountsForDeckTodayOut
|
||||
SchedTimingToday = _pb.SchedTimingTodayOut
|
||||
|
||||
UnburyCurrentDeckMode = _pb.UnburyCardsInCurrentDeckIn.Mode # pylint:disable=no-member
|
||||
BuryOrSuspendMode = _pb.BuryOrSuspendCardsIn.Mode # pylint:disable=no-member
|
||||
|
@ -1236,7 +1238,7 @@ due = (case when odue>0 then odue else due end), odue = 0, odid = 0, usn = ? whe
|
|||
# Deck finished state
|
||||
##########################################################################
|
||||
|
||||
def congratulations_info(self) -> CongratsInfoOut:
|
||||
def congratulations_info(self) -> CongratsInfo:
|
||||
return self.col.backend.congrats_info()
|
||||
|
||||
def finishedMsg(self) -> str:
|
||||
|
|
Loading…
Reference in a new issue