From ea31e8ca3ef5fc29da93947e8edf78ea6d771a95 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 31 Jan 2021 17:17:28 +1000 Subject: [PATCH] move the remaining exports from _backend --- pylib/anki/_backend/__init__.py | 42 ++++++++++----------------------- pylib/anki/collection.py | 14 ++++------- pylib/anki/models.py | 2 +- pylib/anki/schedv2.py | 8 ++++--- 4 files changed, 23 insertions(+), 43 deletions(-) diff --git a/pylib/anki/_backend/__init__.py b/pylib/anki/_backend/__init__.py index 8edeacba4..18cb0ca5e 100644 --- a/pylib/anki/_backend/__init__.py +++ b/pylib/anki/_backend/__init__.py @@ -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, diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index 5bf8617e3..ec49f8bda 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -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) diff --git a/pylib/anki/models.py b/pylib/anki/models.py index 11142dcdf..09b5f756d 100644 --- a/pylib/anki/models.py +++ b/pylib/anki/models.py @@ -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)) diff --git a/pylib/anki/schedv2.py b/pylib/anki/schedv2.py index d9a0a21dc..5eec5ce5d 100644 --- a/pylib/anki/schedv2.py +++ b/pylib/anki/schedv2.py @@ -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: