mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Import submodules directly (#1662)
* Use submodule imports in aqt * Use submodule imports in pylib * More submodule imports in pylib These required removing some direct imports to get rid of import cycles.
This commit is contained in:
parent
6a21261c84
commit
9c54f85be6
53 changed files with 104 additions and 15 deletions
|
@ -7,6 +7,10 @@ import pprint
|
|||
import time
|
||||
|
||||
import anki # pylint: disable=unused-import
|
||||
import anki.collection
|
||||
import anki.decks
|
||||
import anki.notes
|
||||
import anki.template
|
||||
from anki import cards_pb2, hooks
|
||||
from anki._legacy import DeprecatedNamesMixin, deprecated
|
||||
from anki.consts import *
|
||||
|
|
|
@ -25,6 +25,7 @@ from typing import Any
|
|||
from weakref import ref
|
||||
|
||||
import anki
|
||||
import anki.collection
|
||||
from anki import config_pb2
|
||||
from anki.collection import OpChanges
|
||||
from anki.errors import NotFoundError
|
||||
|
|
|
@ -9,9 +9,10 @@ from typing import TYPE_CHECKING, Any, Iterable, NewType, Sequence, no_type_chec
|
|||
if TYPE_CHECKING:
|
||||
import anki
|
||||
|
||||
import anki.cards
|
||||
import anki.collection
|
||||
from anki import deckconfig_pb2, decks_pb2
|
||||
from anki._legacy import DeprecatedNamesMixin, deprecated, print_deprecation_warning
|
||||
from anki.cards import CardId
|
||||
from anki.collection import OpChanges, OpChangesWithCount, OpChangesWithId
|
||||
from anki.consts import *
|
||||
from anki.errors import NotFoundError
|
||||
|
@ -383,7 +384,7 @@ class DeckManager(DeprecatedNamesMixin):
|
|||
return deck["name"]
|
||||
return None
|
||||
|
||||
def cids(self, did: DeckId, children: bool = False) -> list[CardId]:
|
||||
def cids(self, did: DeckId, children: bool = False) -> list[anki.cards.CardId]:
|
||||
if not children:
|
||||
return self.col.db.list("select id from cards where did=?", did)
|
||||
dids = [did]
|
||||
|
@ -391,7 +392,7 @@ class DeckManager(DeprecatedNamesMixin):
|
|||
dids.append(id)
|
||||
return self.col.db.list(f"select id from cards where did in {ids2str(dids)}")
|
||||
|
||||
def for_card_ids(self, cids: list[CardId]) -> list[DeckId]:
|
||||
def for_card_ids(self, cids: list[anki.cards.CardId]) -> list[DeckId]:
|
||||
return self.col.db.list(f"select did from cards where id in {ids2str(cids)}")
|
||||
|
||||
# Deck selection
|
||||
|
@ -543,7 +544,7 @@ class DeckManager(DeprecatedNamesMixin):
|
|||
return {d["name"]: d for d in self.all()}
|
||||
|
||||
@deprecated(info="use col.set_deck() instead")
|
||||
def set_deck(self, cids: list[CardId], did: DeckId) -> None:
|
||||
def set_deck(self, cids: list[anki.cards.CardId], did: DeckId) -> None:
|
||||
self.col.set_deck(card_ids=cids, deck_id=did)
|
||||
self.col.db.execute(
|
||||
f"update cards set did=?,usn=?,mod=? where id in {ids2str(cids)}",
|
||||
|
|
|
@ -10,6 +10,7 @@ from dataclasses import dataclass
|
|||
from typing import Any
|
||||
|
||||
import anki
|
||||
import anki.collection
|
||||
from anki import card_rendering_pb2, hooks
|
||||
from anki.models import NotetypeDict
|
||||
from anki.template import TemplateRenderContext, TemplateRenderOutput
|
||||
|
|
|
@ -10,6 +10,8 @@ import time
|
|||
from typing import Any, NewType, Sequence, Union
|
||||
|
||||
import anki # pylint: disable=unused-import
|
||||
import anki.collection
|
||||
import anki.notes
|
||||
from anki import notetypes_pb2
|
||||
from anki._legacy import DeprecatedNamesMixin, deprecated, print_deprecation_warning
|
||||
from anki.collection import OpChanges, OpChangesWithId
|
||||
|
|
|
@ -7,6 +7,10 @@ import copy
|
|||
from typing import Any, NewType, Sequence
|
||||
|
||||
import anki # pylint: disable=unused-import
|
||||
import anki.cards
|
||||
import anki.collection
|
||||
import anki.decks
|
||||
import anki.template
|
||||
from anki import hooks, notes_pb2
|
||||
from anki._legacy import DeprecatedNamesMixin
|
||||
from anki.consts import MODEL_STD
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import anki
|
||||
import anki.collection
|
||||
from anki import decks_pb2, scheduler_pb2
|
||||
from anki._legacy import DeprecatedNamesMixin
|
||||
from anki.collection import OpChanges, OpChangesWithCount, OpChangesWithId
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import anki
|
||||
import anki.collection
|
||||
from anki.cards import Card
|
||||
from anki.consts import *
|
||||
from anki.decks import DeckId
|
||||
|
|
|
@ -11,6 +11,7 @@ from heapq import *
|
|||
from typing import Any, Callable, cast
|
||||
|
||||
import anki # pylint: disable=unused-import
|
||||
import anki.collection
|
||||
from anki import hooks, scheduler_pb2
|
||||
from anki.cards import Card, CardId
|
||||
from anki.consts import *
|
||||
|
|
|
@ -32,12 +32,13 @@ from dataclasses import dataclass
|
|||
from typing import Any, Sequence, Union
|
||||
|
||||
import anki
|
||||
import anki.cards
|
||||
import anki.collection
|
||||
import anki.notes
|
||||
from anki import card_rendering_pb2, hooks
|
||||
from anki.cards import Card
|
||||
from anki.decks import DeckManager
|
||||
from anki.errors import TemplateError
|
||||
from anki.models import NotetypeDict
|
||||
from anki.notes import Note
|
||||
from anki.sound import AVTag, SoundOrVideoTag, TTSTag
|
||||
from anki.utils import to_json_bytes
|
||||
|
||||
|
@ -116,14 +117,16 @@ class TemplateRenderContext:
|
|||
using the _private fields directly."""
|
||||
|
||||
@staticmethod
|
||||
def from_existing_card(card: Card, browser: bool) -> TemplateRenderContext:
|
||||
def from_existing_card(
|
||||
card: anki.cards.Card, browser: bool
|
||||
) -> TemplateRenderContext:
|
||||
return TemplateRenderContext(card.col, card, card.note(), browser)
|
||||
|
||||
@classmethod
|
||||
def from_card_layout(
|
||||
cls,
|
||||
note: Note,
|
||||
card: Card,
|
||||
note: anki.notes.Note,
|
||||
card: anki.cards.Card,
|
||||
notetype: NotetypeDict,
|
||||
template: dict,
|
||||
fill_empty: bool,
|
||||
|
@ -140,8 +143,8 @@ class TemplateRenderContext:
|
|||
def __init__(
|
||||
self,
|
||||
col: anki.collection.Collection,
|
||||
card: Card,
|
||||
note: Note,
|
||||
card: anki.cards.Card,
|
||||
note: anki.notes.Note,
|
||||
browser: bool = False,
|
||||
notetype: NotetypeDict = None,
|
||||
template: dict | None = None,
|
||||
|
@ -188,14 +191,14 @@ class TemplateRenderContext:
|
|||
|
||||
return self._fields
|
||||
|
||||
def card(self) -> Card:
|
||||
def card(self) -> anki.cards.Card:
|
||||
"""Returns the card being rendered.
|
||||
|
||||
Be careful not to call .question() or .answer() on the card, or you'll create an
|
||||
infinite loop."""
|
||||
return self._card
|
||||
|
||||
def note(self) -> Note:
|
||||
def note(self) -> anki.notes.Note:
|
||||
return self._note
|
||||
|
||||
def note_type(self) -> NotetypeDict:
|
||||
|
@ -281,7 +284,7 @@ class TemplateRenderOutput:
|
|||
|
||||
|
||||
# legacy
|
||||
def templates_for_card(card: Card, browser: bool) -> tuple[str, str]:
|
||||
def templates_for_card(card: anki.cards.Card, browser: bool) -> tuple[str, str]:
|
||||
template = card.template()
|
||||
if browser:
|
||||
question, answer = template.get("bqfmt"), template.get("bafmt")
|
||||
|
@ -317,7 +320,7 @@ def apply_custom_filters(
|
|||
field_text, node.field_name, filter_name, ctx
|
||||
)
|
||||
# legacy hook - the second and fifth argument are no longer used.
|
||||
field_text = anki.hooks.runFilter(
|
||||
field_text = hooks.runFilter(
|
||||
f"fmod_{filter_name}",
|
||||
field_text,
|
||||
"",
|
||||
|
|
|
@ -9,6 +9,7 @@ from ctypes import CDLL, CFUNCTYPE, c_char_p
|
|||
from typing import Callable
|
||||
|
||||
import aqt
|
||||
import aqt.utils
|
||||
|
||||
|
||||
class _MacOSHelper:
|
||||
|
|
|
@ -22,6 +22,7 @@ from jsonschema.exceptions import ValidationError
|
|||
from send2trash import send2trash
|
||||
|
||||
import anki
|
||||
import anki.utils
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.main
|
||||
|
|
|
@ -7,7 +7,10 @@ import json
|
|||
from typing import Callable, Sequence
|
||||
|
||||
import aqt
|
||||
import aqt.browser
|
||||
import aqt.editor
|
||||
import aqt.forms
|
||||
import aqt.operations
|
||||
from anki._legacy import deprecated
|
||||
from anki.cards import Card, CardId
|
||||
from anki.collection import Collection, Config, OpChanges, SearchNode
|
||||
|
|
|
@ -6,6 +6,8 @@ from __future__ import annotations
|
|||
from typing import Sequence
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.operations
|
||||
from anki.notes import NoteId
|
||||
from aqt import AnkiQt
|
||||
from aqt.operations import QueryOp
|
||||
|
|
|
@ -9,6 +9,7 @@ from typing import Any
|
|||
import anki
|
||||
import anki.find
|
||||
import aqt
|
||||
import aqt.forms
|
||||
from anki.collection import SearchNode
|
||||
from anki.notes import NoteId
|
||||
from aqt.qt import *
|
||||
|
|
|
@ -5,6 +5,7 @@ from __future__ import annotations
|
|||
from typing import cast
|
||||
|
||||
import aqt
|
||||
import aqt.browser
|
||||
from aqt.browser.sidebar.item import SidebarItem
|
||||
from aqt.qt import *
|
||||
from aqt.theme import theme_manager
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import aqt
|
||||
import aqt.browser
|
||||
import aqt.gui_hooks
|
||||
from aqt import colors
|
||||
from aqt.browser.sidebar import _want_right_border
|
||||
from aqt.qt import *
|
||||
|
|
|
@ -6,6 +6,8 @@ from __future__ import annotations
|
|||
from enum import Enum, auto
|
||||
|
||||
import aqt
|
||||
import aqt.browser
|
||||
import aqt.gui_hooks
|
||||
from aqt.qt import *
|
||||
from aqt.theme import theme_manager
|
||||
from aqt.utils import tr
|
||||
|
|
|
@ -6,6 +6,8 @@ from enum import Enum, auto
|
|||
from typing import Iterable, cast
|
||||
|
||||
import aqt
|
||||
import aqt.browser
|
||||
import aqt.operations
|
||||
from anki.collection import (
|
||||
Config,
|
||||
OpChanges,
|
||||
|
|
|
@ -7,6 +7,7 @@ from dataclasses import dataclass
|
|||
from typing import TYPE_CHECKING, Generator, Sequence, Union
|
||||
|
||||
import aqt
|
||||
import aqt.browser
|
||||
from anki.cards import CardId
|
||||
from anki.collection import BrowserColumns as Columns
|
||||
from anki.collection import BrowserRow
|
||||
|
|
|
@ -6,6 +6,7 @@ import time
|
|||
from typing import Any, Callable, Sequence
|
||||
|
||||
import aqt
|
||||
import aqt.browser
|
||||
from anki.cards import Card, CardId
|
||||
from anki.collection import BrowserColumns as Columns
|
||||
from anki.collection import Collection
|
||||
|
|
|
@ -5,6 +5,7 @@ from __future__ import annotations
|
|||
from typing import Any, Callable, Sequence
|
||||
|
||||
import aqt
|
||||
import aqt.browser
|
||||
import aqt.forms
|
||||
from anki.cards import Card, CardId
|
||||
from anki.collection import Collection, Config, OpChanges
|
||||
|
|
|
@ -7,6 +7,8 @@ from typing import Sequence
|
|||
|
||||
import aqt
|
||||
import aqt.deckconf
|
||||
import aqt.main
|
||||
import aqt.operations
|
||||
from anki.collection import OpChanges
|
||||
from anki.models import ChangeNotetypeRequest, NotetypeId
|
||||
from anki.notes import NoteId
|
||||
|
|
|
@ -6,6 +6,8 @@ from concurrent.futures import Future
|
|||
from typing import Any, Match, Optional
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.operations
|
||||
from anki.collection import OpChanges
|
||||
from anki.consts import *
|
||||
from anki.lang import without_unicode_isolation
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.operations
|
||||
from anki.consts import *
|
||||
from anki.scheduler import CustomStudyRequest
|
||||
from aqt.operations.scheduling import custom_study
|
||||
|
|
|
@ -6,6 +6,7 @@ from __future__ import annotations
|
|||
from concurrent.futures import Future
|
||||
|
||||
import aqt
|
||||
import aqt.main
|
||||
from aqt.qt import *
|
||||
from aqt.utils import showText, tooltip
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ from dataclasses import dataclass
|
|||
from typing import Any
|
||||
|
||||
import aqt
|
||||
import aqt.operations
|
||||
from anki.collection import OpChanges
|
||||
from anki.decks import DeckCollapseScope, DeckId, DeckTreeNode
|
||||
from aqt import AnkiQt, gui_hooks
|
||||
|
|
|
@ -7,6 +7,7 @@ from operator import itemgetter
|
|||
from typing import Any
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
from anki.consts import NEW_CARDS_RANDOM
|
||||
from anki.decks import DeckConfigDict
|
||||
from anki.lang import without_unicode_isolation
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import aqt
|
||||
import aqt.main
|
||||
import aqt.operations
|
||||
from anki.decks import DeckDict
|
||||
from aqt.operations import QueryOp
|
||||
from aqt.operations.deck import update_deck_dict
|
||||
|
|
|
@ -5,6 +5,7 @@ from __future__ import annotations
|
|||
|
||||
import aqt
|
||||
import aqt.deckconf
|
||||
import aqt.main
|
||||
from anki.cards import Card
|
||||
from anki.decks import DeckDict, DeckId
|
||||
from anki.lang import without_unicode_isolation
|
||||
|
|
|
@ -22,6 +22,8 @@ import requests
|
|||
from bs4 import BeautifulSoup
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.operations
|
||||
import aqt.sound
|
||||
from anki._legacy import deprecated
|
||||
from anki.cards import Card
|
||||
|
|
|
@ -8,6 +8,8 @@ from concurrent.futures import Future
|
|||
from typing import Any
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.main
|
||||
from anki.cards import CardId
|
||||
from anki.collection import EmptyCardsReport
|
||||
from aqt import gui_hooks
|
||||
|
|
|
@ -9,6 +9,8 @@ import time
|
|||
from concurrent.futures import Future
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.main
|
||||
from anki import hooks
|
||||
from anki.cards import CardId
|
||||
from anki.decks import DeckId
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
from typing import Optional
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.operations
|
||||
from anki.collection import OpChanges
|
||||
from anki.consts import *
|
||||
from anki.lang import without_unicode_isolation
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.operations
|
||||
from anki.collection import OpChangesWithId, SearchNode
|
||||
from anki.decks import DeckDict, DeckId, FilteredDeckConfig
|
||||
from anki.errors import SearchError
|
||||
|
|
|
@ -6,6 +6,7 @@ from dataclasses import dataclass
|
|||
from typing import cast
|
||||
|
||||
import aqt
|
||||
import aqt.main
|
||||
from anki.collection import SearchNode
|
||||
from aqt import colors, gui_hooks
|
||||
from aqt.theme import ColoredIcon
|
||||
|
|
|
@ -10,6 +10,8 @@ from __future__ import annotations
|
|||
from typing import Any
|
||||
|
||||
import anki
|
||||
import anki.sound
|
||||
import anki.utils
|
||||
import aqt
|
||||
from aqt.theme import theme_manager
|
||||
|
||||
|
|
|
@ -16,9 +16,13 @@ from threading import Thread
|
|||
from typing import Any, Literal, Sequence, TextIO, TypeVar, cast
|
||||
|
||||
import anki
|
||||
import anki.cards
|
||||
import anki.sound
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.mediasrv
|
||||
import aqt.mpv
|
||||
import aqt.operations
|
||||
import aqt.progress
|
||||
import aqt.sound
|
||||
import aqt.stats
|
||||
|
|
|
@ -9,6 +9,7 @@ from concurrent.futures import Future
|
|||
from typing import Iterable, Sequence, TypeVar
|
||||
|
||||
import aqt
|
||||
import aqt.progress
|
||||
from anki.collection import Collection, SearchNode
|
||||
from anki.errors import Interrupted
|
||||
from anki.media import CheckMediaResponse
|
||||
|
|
|
@ -21,6 +21,8 @@ from flask import Response, request
|
|||
from waitress.server import create_server
|
||||
|
||||
import aqt
|
||||
import aqt.main
|
||||
import aqt.operations
|
||||
from anki import hooks
|
||||
from anki._vendor import stringcase
|
||||
from anki.collection import OpChanges
|
||||
|
|
|
@ -9,6 +9,8 @@ from dataclasses import dataclass
|
|||
from typing import Any, Callable, Union
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.main
|
||||
from anki.collection import Progress
|
||||
from anki.errors import Interrupted, NetworkError
|
||||
from anki.types import assert_exhaustive
|
||||
|
|
|
@ -7,6 +7,7 @@ from concurrent.futures._base import Future
|
|||
from typing import Any, Callable, Generic, Protocol, TypeVar, Union
|
||||
|
||||
import aqt
|
||||
import aqt.gui_hooks
|
||||
from anki.collection import (
|
||||
Collection,
|
||||
OpChanges,
|
||||
|
|
|
@ -6,6 +6,7 @@ from __future__ import annotations
|
|||
from typing import Sequence
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
from anki.cards import CardId
|
||||
from anki.collection import (
|
||||
CARD_TYPE_NEW,
|
||||
|
|
|
@ -6,6 +6,7 @@ from dataclasses import dataclass
|
|||
from typing import Any, Callable
|
||||
|
||||
import aqt
|
||||
import aqt.operations
|
||||
from anki.collection import OpChanges
|
||||
from anki.scheduler import UnburyDeck
|
||||
from aqt import gui_hooks
|
||||
|
|
|
@ -5,6 +5,8 @@ from typing import Any, cast
|
|||
|
||||
import anki.lang
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.operations
|
||||
from anki.collection import OpChanges
|
||||
from anki.consts import new_card_scheduling_labels
|
||||
from aqt import AnkiQt
|
||||
|
|
|
@ -14,6 +14,8 @@ from enum import Enum, auto
|
|||
from typing import Any, Callable, Literal, Match, Sequence, cast
|
||||
|
||||
import aqt
|
||||
import aqt.browser
|
||||
import aqt.operations
|
||||
from anki import hooks
|
||||
from anki.cards import Card, CardId
|
||||
from anki.collection import Config, OpChanges, OpChangesWithCount
|
||||
|
|
|
@ -19,6 +19,8 @@ from typing import Any, Callable, cast
|
|||
from markdown import markdown
|
||||
|
||||
import aqt
|
||||
import aqt.mpv
|
||||
import aqt.qt
|
||||
from anki import hooks
|
||||
from anki.cards import Card
|
||||
from anki.sound import AV_REF_RE, AVTag, SoundOrVideoTag
|
||||
|
|
|
@ -6,6 +6,8 @@ import time
|
|||
from typing import Any
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.main
|
||||
from aqt import gui_hooks
|
||||
from aqt.qt import *
|
||||
from aqt.theme import theme_manager
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
from typing import Optional
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
import aqt.operations
|
||||
from anki.collection import OpChangesWithId
|
||||
from anki.decks import DeckId
|
||||
from aqt import gui_hooks
|
||||
|
|
|
@ -9,6 +9,7 @@ from concurrent.futures import Future
|
|||
from typing import Callable
|
||||
|
||||
import aqt
|
||||
import aqt.main
|
||||
from anki.errors import Interrupted, SyncError, SyncErrorKind
|
||||
from anki.lang import without_unicode_isolation
|
||||
from anki.sync import SyncOutput, SyncStatus
|
||||
|
|
|
@ -6,6 +6,8 @@ from __future__ import annotations
|
|||
from typing import List, Optional, Tuple
|
||||
|
||||
import aqt
|
||||
import aqt.customstudy
|
||||
import aqt.forms
|
||||
from anki.lang import with_collapsed_whitespace
|
||||
from aqt.main import AnkiQt
|
||||
from aqt.qt import *
|
||||
|
|
|
@ -39,6 +39,7 @@ from operator import attrgetter
|
|||
from typing import Any, cast
|
||||
|
||||
import anki
|
||||
import anki.template
|
||||
from anki import hooks
|
||||
from anki.sound import AVTag, TTSTag
|
||||
from anki.utils import checksum, is_win, tmpdir
|
||||
|
|
|
@ -8,6 +8,7 @@ import sys
|
|||
from typing import Any, Callable, Optional, Sequence, cast
|
||||
|
||||
import anki
|
||||
import anki.lang
|
||||
from anki.lang import is_rtl
|
||||
from anki.utils import is_lin, is_mac, is_win
|
||||
from aqt import colors, gui_hooks
|
||||
|
|
Loading…
Reference in a new issue