Skip to content

Commit

Permalink
move old scheduler files into scheduler/
Browse files Browse the repository at this point in the history
Includes a hack that should allow existing imports to continue to work;
if this breaks things for you, please let me know.
  • Loading branch information
dae committed Mar 12, 2021
1 parent ad973bb commit ec8adf7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 29 deletions.
4 changes: 2 additions & 2 deletions pylib/anki/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
from anki.media import MediaManager, media_paths_from_col_path
from anki.models import ModelManager, NoteType
from anki.notes import Note
from anki.sched import Scheduler as V1Scheduler
from anki.scheduler.v1 import Scheduler as V1Scheduler
from anki.scheduler.v2 import Scheduler as V2Scheduler
from anki.scheduler.v3 import Scheduler as V3TestScheduler
from anki.schedv2 import Scheduler as V2Scheduler
from anki.sync import SyncAuth, SyncOutput, SyncStatus
from anki.tags import TagManager
from anki.types import assert_exhaustive
Expand Down
11 changes: 11 additions & 0 deletions pylib/anki/scheduler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@

from __future__ import annotations

import sys

import anki.scheduler.base as _base

UnburyCurrentDeck = _base.UnburyCurrentDeck
CongratsInfo = _base.CongratsInfo
BuryOrSuspend = _base.BuryOrSuspend

# add aliases to the legacy pathnames
import anki.scheduler.v1
import anki.scheduler.v2

sys.modules["anki.sched"] = sys.modules["anki.scheduler.v1"]
sys.modules["anki.schedv2"] = sys.modules["anki.scheduler.v2"]
anki.sched = sys.modules["anki.scheduler.v1"] # type: ignore
anki.schedv2 = sys.modules["anki.scheduler.v2"] # type: ignore
32 changes: 6 additions & 26 deletions pylib/anki/scheduler/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
from typing import List, Optional, Tuple

from anki.cards import Card
from anki.consts import (
CARD_TYPE_RELEARNING,
CARD_TYPE_REV,
QUEUE_TYPE_DAY_LEARN_RELEARN,
)
from anki.decks import DeckConfig, QueueConfig
from anki.consts import CARD_TYPE_RELEARNING, QUEUE_TYPE_DAY_LEARN_RELEARN
from anki.decks import DeckConfig
from anki.scheduler.base import SchedulerBase, UnburyCurrentDeck
from anki.utils import from_json_bytes, ids2str

Expand Down Expand Up @@ -117,31 +113,15 @@ def deckDueTree(self) -> List:
)
return from_json_bytes(self.col._backend.deck_tree_legacy())[5]

# unit tests
def _fuzzIvlRange(self, ivl: int) -> Tuple[int, int]:
return (ivl, ivl)
# legacy in v3 but used by unit tests; redefined in v2/v1

def _cardConf(self, card: Card) -> DeckConfig:
return self.col.decks.confForDid(card.did)

def _home_config(self, card: Card) -> DeckConfig:
return self.col.decks.confForDid(card.odid or card.did)

def _newConf(self, card: Card) -> QueueConfig:
return self._home_config(card)["new"]

def _lapseConf(self, card: Card) -> QueueConfig:
return self._home_config(card)["lapse"]

def _revConf(self, card: Card) -> QueueConfig:
return self._home_config(card)["rev"]

def _lrnConf(self, card: Card) -> QueueConfig:
if card.type in (CARD_TYPE_REV, CARD_TYPE_RELEARNING):
return self._lapseConf(card)
else:
return self._newConf(card)
def _fuzzIvlRange(self, ivl: int) -> Tuple[int, int]:
return (ivl, ivl)

# simple aliases
unsuspendCards = SchedulerBase.unsuspend_cards
buryCards = SchedulerBase.bury_cards
suspendCards = SchedulerBase.suspend_cards
Expand Down
3 changes: 2 additions & 1 deletion pylib/anki/sched.py → pylib/anki/scheduler/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
from anki.cards import Card
from anki.consts import *
from anki.decks import QueueConfig
from anki.schedv2 import Scheduler as V2
from anki.utils import ids2str, intTime

from .v2 import Scheduler as V2

# queue types: 0=new/cram, 1=lrn, 2=rev, 3=day lrn, -1=suspended, -2=buried
# revlog types: 0=lrn, 1=rev, 2=relrn, 3=cram
# positive revlog intervals are in days (rev), negative in seconds (lrn)
Expand Down
File renamed without changes.

0 comments on commit ec8adf7

Please sign in to comment.