Skip to content
This repository was archived by the owner on Aug 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #28 from AlexRiina/anki-2.1.45
Browse files Browse the repository at this point in the history
Anki 2.1.45 compatibility
  • Loading branch information
AlexRiina authored Jul 20, 2021
2 parents 23123bd + 06bc623 commit 37e2508
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="anki_cousins",
version="0.4",
version="0.6",
tests_require=["PyQt5-stubs" "anki", "black", "flake8", "isort", "mypy"],
packages=["src"],
)
9 changes: 8 additions & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
from anki.hooks import wrap
from anki.sched import Scheduler
from anki.schedv2 import Scheduler as SchedulerV2
from anki import buildinfo

from . import interface # noqa: F401
from . import main # noqa: F401

version = tuple(map(int, buildinfo.version.split(".")))

# Anki doesn't have hooks in all of the right places, so monkey patching
# private methods is an established if fragile pattern
Scheduler._burySiblings = wrap(Scheduler._burySiblings, main.buryCousins, "after") # type: ignore
SchedulerV2._burySiblings = wrap(SchedulerV2._burySiblings, main.buryCousins, "after") # type: ignore
Collection.findDupes = wrap(Collection.findDupes, main.findDupes, None) # type: ignore

if version >= (2, 1, 45):
Collection.find_dupes = wrap(Collection.find_dupes, main.findDupes, None) # type: ignore
else:
Collection.findDupes = wrap(Collection.findDupes, main.findDupes, None) # type: ignore
5 changes: 4 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ def field_value(note, field_name) -> str:
self.newCount -= len(count_adjustments[QUEUE_TYPE_NEW])

if cousin_cards:
tooltip("burying %d cousin card" % len(cousin_cards))
tooltip(
"burying %d cousin card%s"
% (len(cousin_cards), "s" if len(cousin_cards) > 1 else "")
)

card_ids_to_bury = [
id
Expand Down
5 changes: 5 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Bury Cousins",
"package": "bury_cousins",
"human_version": "0.5"
}
5 changes: 4 additions & 1 deletion src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def save(self, match_rules: Iterable[MatchRule]):
set_config = self.col.set_config
except AttributeError:
# Compatibility with Anki<2.1.24
set_config = self.col.conf.__setitem__
set_config = self.col.conf.__setitem__ # type: ignore

set_config(
self.key,
Expand Down Expand Up @@ -246,6 +246,9 @@ class _cloze_contained_by:
>>> bool(_cloze_contained_by()(['Phase {{c1::2::#N}} clinical trial'], ['2 x 2'], 1))
False
>>> bool(_cloze_contained_by()(['{{c1::hello}}'], ['phelloderm'], 1))
False
"""

@staticmethod
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ deps =
PyQT5-stubs
anki_2125: anki == 2.1.25
anki_2135: anki == 2.1.35
anki_latest: anki >= 2.1.38
anki_2144: anki == 2.1.44
anki_latest: anki >= 2.1.44

commands =
mypy src

0 comments on commit 37e2508

Please sign in to comment.