Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
Patch Anki 2.1.50 on Windows to have valid stdout
Browse files Browse the repository at this point in the history
Something in Anki is setting stdout to Null.
This is a problem because Anki itself is writing to it,
particularly when printing warnings about
the deprecated methods that we are using.

This patches Anki using the same method that
the upcoming Anki 2.1.51 is using.
  • Loading branch information
oakkitten committed Apr 26, 2022
1 parent ca90ef9 commit 8a84db9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import json
import os
import os.path
import platform
import re
import time
import unicodedata
Expand Down Expand Up @@ -1619,6 +1620,9 @@ def importPackage(self, path):
# when run inside Anki, `__name__` would be either numeric,
# or, if installed via `link.sh`, `AnkiConnectDev`
if __name__ != "plugin":
if platform.system() == "Windows" and anki_version == (2, 1, 50):
util.patch_anki_2_1_50_having_null_stdout_on_windows()

Edit.register_with_anki()

ac = AnkiConnect()
Expand Down
8 changes: 8 additions & 0 deletions plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os
import sys

import anki
import anki.sync
Expand Down Expand Up @@ -83,3 +84,10 @@ def setting(key):
return aqt.mw.addonManager.getConfig(__name__).get(key, DEFAULT_CONFIG[key])
except:
raise Exception('setting {} not found'.format(key))


# see https://github.com/FooSoft/anki-connect/issues/308
# fixed in https://github.com/ankitects/anki/commit/0b2a226d
def patch_anki_2_1_50_having_null_stdout_on_windows():
if sys.stdout is None:
sys.stdout = open(os.devnull, "w", encoding="utf8")

0 comments on commit 8a84db9

Please sign in to comment.