update to latest black
This commit is contained in:
parent
603210149c
commit
a517accee3
@ -129,9 +129,11 @@ class Card:
|
||||
self, reload: bool = False, browser: bool = False
|
||||
) -> anki.template.TemplateRenderOutput:
|
||||
if not self._render_output or reload:
|
||||
self._render_output = anki.template.TemplateRenderContext.from_existing_card(
|
||||
self._render_output = (
|
||||
anki.template.TemplateRenderContext.from_existing_card(
|
||||
self, browser
|
||||
).render()
|
||||
)
|
||||
return self._render_output
|
||||
|
||||
def set_render_output(self, output: anki.template.TemplateRenderOutput) -> None:
|
||||
|
@ -104,7 +104,12 @@ class DeckManager:
|
||||
# Deck save/load
|
||||
#############################################################
|
||||
|
||||
def id(self, name: str, create: bool = True, type: int = 0,) -> Optional[int]:
|
||||
def id(
|
||||
self,
|
||||
name: str,
|
||||
create: bool = True,
|
||||
type: int = 0,
|
||||
) -> Optional[int]:
|
||||
"Add a deck with NAME. Reuse deck if already exists. Return id as int."
|
||||
id = self.id_for_name(name)
|
||||
if id:
|
||||
|
@ -437,7 +437,15 @@ and notes.mid = ? and cards.ord = ?""",
|
||||
for c in range(nfields):
|
||||
flds.append(newflds.get(c, ""))
|
||||
flds = joinFields(flds)
|
||||
d.append((flds, newModel["id"], intTime(), self.col.usn(), nid,))
|
||||
d.append(
|
||||
(
|
||||
flds,
|
||||
newModel["id"],
|
||||
intTime(),
|
||||
self.col.usn(),
|
||||
nid,
|
||||
)
|
||||
)
|
||||
self.col.db.executemany(
|
||||
"update notes set flds=?,mid=?,mod=?,usn=? where id = ?", d
|
||||
)
|
||||
|
@ -209,7 +209,9 @@ class RustBackend(RustBackendGenerated):
|
||||
langs = [anki.lang.currentLang]
|
||||
|
||||
init_msg = pb.BackendInit(
|
||||
locale_folder_path=ftl_folder, preferred_langs=langs, server=server,
|
||||
locale_folder_path=ftl_folder,
|
||||
preferred_langs=langs,
|
||||
server=server,
|
||||
)
|
||||
self._backend = ankirspy.open_backend(init_msg.SerializeToString())
|
||||
|
||||
|
@ -668,7 +668,10 @@ did = ? and queue = {QUEUE_TYPE_DAY_LEARN_RELEARN} and due <= ? limit ?""",
|
||||
return tot + tod * 1000
|
||||
|
||||
def _leftToday(
|
||||
self, delays: List[int], left: int, now: Optional[int] = None,
|
||||
self,
|
||||
delays: List[int],
|
||||
left: int,
|
||||
now: Optional[int] = None,
|
||||
) -> int:
|
||||
"The number of steps that can be completed by the day cutoff."
|
||||
if not now:
|
||||
@ -1603,7 +1606,16 @@ and (queue={QUEUE_TYPE_NEW} or (queue={QUEUE_TYPE_REV} and due<=?))""",
|
||||
mod = intTime()
|
||||
for id in ids:
|
||||
r = random.randint(imin, imax)
|
||||
d.append((max(1, r), r + t, self.col.usn(), mod, STARTING_FACTOR, id,))
|
||||
d.append(
|
||||
(
|
||||
max(1, r),
|
||||
r + t,
|
||||
self.col.usn(),
|
||||
mod,
|
||||
STARTING_FACTOR,
|
||||
id,
|
||||
)
|
||||
)
|
||||
self.remFromDyn(ids)
|
||||
self.col.db.executemany(
|
||||
f"""
|
||||
|
@ -243,7 +243,9 @@ from revlog where id > ? """
|
||||
def _dueInfo(self, tot: int, num: int) -> str:
|
||||
i: List[str] = []
|
||||
self._line(
|
||||
i, _("Total"), self.col.tr(TR.STATISTICS_REVIEWS, reviews=tot),
|
||||
i,
|
||||
_("Total"),
|
||||
self.col.tr(TR.STATISTICS_REVIEWS, reviews=tot),
|
||||
)
|
||||
self._line(i, _("Average"), self._avgDay(tot, num, _("reviews")))
|
||||
tomorrow = self.col.db.scalar(
|
||||
@ -436,7 +438,9 @@ group by day order by day"""
|
||||
return self._lineTbl(i), int(tot)
|
||||
|
||||
def _splitRepData(
|
||||
self, data: List[Tuple[Any, ...]], spec: Sequence[Tuple[int, str, str]],
|
||||
self,
|
||||
data: List[Tuple[Any, ...]],
|
||||
spec: Sequence[Tuple[int, str, str]],
|
||||
) -> Tuple[List[Dict[str, Any]], List[Tuple[Any, Any]]]:
|
||||
sep: Dict[int, Any] = {}
|
||||
totcnt = {}
|
||||
|
@ -1,6 +1,6 @@
|
||||
wheel
|
||||
mypy
|
||||
mypy_protobuf>=1.21
|
||||
black
|
||||
black>=20.1b0
|
||||
pytest>=6.0.1
|
||||
stringcase==1.2.0
|
||||
|
@ -93,10 +93,14 @@ hooks = [
|
||||
doc="Obsolete, do not use.",
|
||||
),
|
||||
Hook(
|
||||
name="sync_stage_did_change", args=["stage: str"], doc="Obsolete, do not use.",
|
||||
name="sync_stage_did_change",
|
||||
args=["stage: str"],
|
||||
doc="Obsolete, do not use.",
|
||||
),
|
||||
Hook(
|
||||
name="sync_progress_did_change", args=["msg: str"], doc="Obsolete, do not use.",
|
||||
name="sync_progress_did_change",
|
||||
args=["msg: str"],
|
||||
doc="Obsolete, do not use.",
|
||||
),
|
||||
]
|
||||
|
||||
|
@ -760,7 +760,9 @@ class AddonsDialog(QDialog):
|
||||
def should_grey(self, addon: AddonMeta) -> bool:
|
||||
return not addon.enabled or not addon.compatible()
|
||||
|
||||
def redrawAddons(self,) -> None:
|
||||
def redrawAddons(
|
||||
self,
|
||||
) -> None:
|
||||
addonList = self.form.addonList
|
||||
mgr = self.mgr
|
||||
|
||||
@ -1321,7 +1323,11 @@ class ConfigEditor(QDialog):
|
||||
|
||||
def updateText(self, conf: Dict[str, Any]) -> None:
|
||||
text = json.dumps(
|
||||
conf, ensure_ascii=False, sort_keys=True, indent=4, separators=(",", ": "),
|
||||
conf,
|
||||
ensure_ascii=False,
|
||||
sort_keys=True,
|
||||
indent=4,
|
||||
separators=(",", ": "),
|
||||
)
|
||||
text = gui_hooks.addon_config_editor_will_display_json(text)
|
||||
self.form.editor.setPlainText(text)
|
||||
|
@ -166,13 +166,19 @@ class CardLayout(QDialog):
|
||||
self.tform.back_button.setToolTip(shortcut("Ctrl+2"))
|
||||
self.tform.style_button.setToolTip(shortcut("Ctrl+3"))
|
||||
QShortcut( # type: ignore
|
||||
QKeySequence("Ctrl+1"), self, activated=self.tform.front_button.click,
|
||||
QKeySequence("Ctrl+1"),
|
||||
self,
|
||||
activated=self.tform.front_button.click,
|
||||
)
|
||||
QShortcut( # type: ignore
|
||||
QKeySequence("Ctrl+2"), self, activated=self.tform.back_button.click,
|
||||
QKeySequence("Ctrl+2"),
|
||||
self,
|
||||
activated=self.tform.back_button.click,
|
||||
)
|
||||
QShortcut( # type: ignore
|
||||
QKeySequence("Ctrl+3"), self, activated=self.tform.style_button.click,
|
||||
QKeySequence("Ctrl+3"),
|
||||
self,
|
||||
activated=self.tform.style_button.click,
|
||||
)
|
||||
|
||||
# Main area setup
|
||||
@ -303,7 +309,10 @@ class CardLayout(QDialog):
|
||||
"reviewer.js",
|
||||
]
|
||||
self.preview_web.stdHtml(
|
||||
self.mw.reviewer.revHtml(), css=["reviewer.css"], js=jsinc, context=self,
|
||||
self.mw.reviewer.revHtml(),
|
||||
css=["reviewer.css"],
|
||||
js=jsinc,
|
||||
context=self,
|
||||
)
|
||||
self.preview_web.set_bridge_command(self._on_bridge_cmd, self)
|
||||
|
||||
@ -764,7 +773,9 @@ Enter deck to place new %s cards in, or leave blank:"""
|
||||
row = form.fields.currentIndex().row()
|
||||
if row >= 0:
|
||||
self._addField(
|
||||
fields[row], form.font.currentFont().family(), form.size.value(),
|
||||
fields[row],
|
||||
form.font.currentFont().family(),
|
||||
form.size.value(),
|
||||
)
|
||||
|
||||
def _addField(self, field, font, size):
|
||||
|
@ -118,7 +118,8 @@ class DeckBrowser:
|
||||
|
||||
def __renderPage(self, offset):
|
||||
content = DeckBrowserContent(
|
||||
tree=self._renderDeckTree(self._dueTree), stats=self._renderStats(),
|
||||
tree=self._renderDeckTree(self._dueTree),
|
||||
stats=self._renderStats(),
|
||||
)
|
||||
gui_hooks.deck_browser_will_render_content(self, content)
|
||||
self.web.stdHtml(
|
||||
|
@ -233,7 +233,9 @@ class Editor:
|
||||
self._links[cmd] = func
|
||||
if keys:
|
||||
QShortcut( # type: ignore
|
||||
QKeySequence(keys), self.widget, activated=lambda s=self: func(s),
|
||||
QKeySequence(keys),
|
||||
self.widget,
|
||||
activated=lambda s=self: func(s),
|
||||
)
|
||||
btn = self._addButton(
|
||||
icon,
|
||||
|
@ -120,7 +120,12 @@ class ExportDialog(QDialog):
|
||||
key_str = self.exporter.key
|
||||
while 1:
|
||||
file = getSaveFile(
|
||||
self, _("Export"), "export", key_str, self.exporter.ext, fname=filename,
|
||||
self,
|
||||
_("Export"),
|
||||
"export",
|
||||
key_str,
|
||||
self.exporter.ext,
|
||||
fname=filename,
|
||||
)
|
||||
if not file:
|
||||
return
|
||||
@ -175,14 +180,18 @@ class ExportDialog(QDialog):
|
||||
if self.isTextNote:
|
||||
msg = (
|
||||
ngettext(
|
||||
"%d note exported.", "%d notes exported.", self.exporter.count,
|
||||
"%d note exported.",
|
||||
"%d notes exported.",
|
||||
self.exporter.count,
|
||||
)
|
||||
% self.exporter.count
|
||||
)
|
||||
else:
|
||||
msg = (
|
||||
ngettext(
|
||||
"%d card exported.", "%d cards exported.", self.exporter.count,
|
||||
"%d card exported.",
|
||||
"%d cards exported.",
|
||||
self.exporter.count,
|
||||
)
|
||||
% self.exporter.count
|
||||
)
|
||||
|
@ -92,7 +92,10 @@ def allroutes(pathin):
|
||||
try:
|
||||
directory, path = _redirectWebExports(pathin)
|
||||
except TypeError:
|
||||
return flask.make_response(f"Invalid path: {pathin}", HTTPStatus.FORBIDDEN,)
|
||||
return flask.make_response(
|
||||
f"Invalid path: {pathin}",
|
||||
HTTPStatus.FORBIDDEN,
|
||||
)
|
||||
|
||||
try:
|
||||
isdir = os.path.isdir(os.path.join(directory, path))
|
||||
@ -153,7 +156,10 @@ def allroutes(pathin):
|
||||
return flask.send_file(fullpath, mimetype=mimetype, conditional=True)
|
||||
else:
|
||||
print(f"Not found: {ascii(pathin)}")
|
||||
return flask.make_response(f"Invalid path: {pathin}", HTTPStatus.NOT_FOUND,)
|
||||
return flask.make_response(
|
||||
f"Invalid path: {pathin}",
|
||||
HTTPStatus.NOT_FOUND,
|
||||
)
|
||||
|
||||
except Exception as error:
|
||||
if devMode:
|
||||
@ -165,7 +171,10 @@ def allroutes(pathin):
|
||||
# swallow it - user likely surfed away from
|
||||
# review screen before an image had finished
|
||||
# downloading
|
||||
return flask.make_response(str(error), HTTPStatus.INTERNAL_SERVER_ERROR,)
|
||||
return flask.make_response(
|
||||
str(error),
|
||||
HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
|
||||
|
||||
def _redirectWebExports(path):
|
||||
|
@ -116,8 +116,7 @@ class MPVBase:
|
||||
# Process
|
||||
#
|
||||
def _prepare_process(self):
|
||||
"""Prepare the argument list for the mpv process.
|
||||
"""
|
||||
"""Prepare the argument list for the mpv process."""
|
||||
self.argv = [self.executable]
|
||||
self.argv += self.default_argv
|
||||
self.argv += ["--input-ipc-server=" + self._sock_filename]
|
||||
@ -125,13 +124,11 @@ class MPVBase:
|
||||
self.argv += ["--wid=" + str(self.window_id)]
|
||||
|
||||
def _start_process(self):
|
||||
"""Start the mpv process.
|
||||
"""
|
||||
"""Start the mpv process."""
|
||||
self._proc = subprocess.Popen(self.argv, env=self.popenEnv)
|
||||
|
||||
def _stop_process(self):
|
||||
"""Stop the mpv process.
|
||||
"""
|
||||
"""Stop the mpv process."""
|
||||
if hasattr(self, "_proc"):
|
||||
try:
|
||||
self._proc.terminate()
|
||||
@ -197,8 +194,7 @@ class MPVBase:
|
||||
raise MPVProcessError("unable to start process")
|
||||
|
||||
def _stop_socket(self):
|
||||
"""Clean up the socket.
|
||||
"""
|
||||
"""Clean up the socket."""
|
||||
if hasattr(self, "_sock"):
|
||||
self._sock.close()
|
||||
if hasattr(self, "_sock_filename"):
|
||||
@ -208,23 +204,20 @@ class MPVBase:
|
||||
pass
|
||||
|
||||
def _prepare_thread(self):
|
||||
"""Set up the queues for the communication threads.
|
||||
"""
|
||||
"""Set up the queues for the communication threads."""
|
||||
self._request_queue = Queue(1)
|
||||
self._response_queues = {}
|
||||
self._event_queue = Queue()
|
||||
self._stop_event = threading.Event()
|
||||
|
||||
def _start_thread(self):
|
||||
"""Start up the communication threads.
|
||||
"""
|
||||
"""Start up the communication threads."""
|
||||
self._thread = threading.Thread(target=self._reader)
|
||||
self._thread.daemon = True
|
||||
self._thread.start()
|
||||
|
||||
def _stop_thread(self):
|
||||
"""Stop the communication threads.
|
||||
"""
|
||||
"""Stop the communication threads."""
|
||||
if hasattr(self, "_stop_event"):
|
||||
self._stop_event.set()
|
||||
if hasattr(self, "_thread"):
|
||||
@ -276,15 +269,13 @@ class MPVBase:
|
||||
# Message handling
|
||||
#
|
||||
def _compose_message(self, message):
|
||||
"""Return a json representation from a message dictionary.
|
||||
"""
|
||||
"""Return a json representation from a message dictionary."""
|
||||
# XXX may be strict is too strict ;-)
|
||||
data = json.dumps(message)
|
||||
return data.encode("utf8", "strict") + b"\n"
|
||||
|
||||
def _parse_message(self, data):
|
||||
"""Return a message dictionary from a json representation.
|
||||
"""
|
||||
"""Return a message dictionary from a json representation."""
|
||||
# XXX may be strict is too strict ;-)
|
||||
data = data.decode("utf8", "strict")
|
||||
return json.loads(data)
|
||||
@ -374,8 +365,7 @@ class MPVBase:
|
||||
return None
|
||||
|
||||
def _send_request(self, message, timeout=None, _retry=1):
|
||||
"""Send a command to the mpv process and collect the result.
|
||||
"""
|
||||
"""Send a command to the mpv process and collect the result."""
|
||||
self.ensure_running()
|
||||
try:
|
||||
self._send_message(message, timeout)
|
||||
@ -399,8 +389,7 @@ class MPVBase:
|
||||
# Public API
|
||||
#
|
||||
def is_running(self):
|
||||
"""Return True if the mpv process is still active.
|
||||
"""
|
||||
"""Return True if the mpv process is still active."""
|
||||
return self._proc.poll() is None
|
||||
|
||||
def ensure_running(self):
|
||||
@ -417,8 +406,7 @@ class MPVBase:
|
||||
self._register_callbacks()
|
||||
|
||||
def close(self):
|
||||
"""Shutdown the mpv process and our communication setup.
|
||||
"""
|
||||
"""Shutdown the mpv process and our communication setup."""
|
||||
if self.is_running():
|
||||
self._send_request({"command": ["quit"]}, timeout=1)
|
||||
self._stop_process()
|
||||
@ -498,8 +486,7 @@ class MPV(MPVBase):
|
||||
# Socket communication
|
||||
#
|
||||
def _start_thread(self):
|
||||
"""Start up the communication threads.
|
||||
"""
|
||||
"""Start up the communication threads."""
|
||||
super()._start_thread()
|
||||
if not hasattr(self, "_event_thread"):
|
||||
self._event_thread = threading.Thread(target=self._event_reader)
|
||||
@ -510,8 +497,7 @@ class MPV(MPVBase):
|
||||
# Event/callback API
|
||||
#
|
||||
def _event_reader(self):
|
||||
"""Collect incoming event messages and call the event handler.
|
||||
"""
|
||||
"""Collect incoming event messages and call the event handler."""
|
||||
while True:
|
||||
message = self._get_event(timeout=1)
|
||||
if message is None:
|
||||
@ -520,8 +506,7 @@ class MPV(MPVBase):
|
||||
self._handle_event(message)
|
||||
|
||||
def _handle_event(self, message):
|
||||
"""Lookup and call the callbacks for a particular event message.
|
||||
"""
|
||||
"""Lookup and call the callbacks for a particular event message."""
|
||||
if not self._callbacks_initialized:
|
||||
self._callbacks_queue.put(message)
|
||||
return
|
||||
@ -538,8 +523,7 @@ class MPV(MPVBase):
|
||||
callback()
|
||||
|
||||
def register_callback(self, name, callback):
|
||||
"""Register a function `callback` for the event `name`.
|
||||
"""
|
||||
"""Register a function `callback` for the event `name`."""
|
||||
try:
|
||||
self.command("enable_event", name)
|
||||
except MPVCommandError:
|
||||
@ -606,18 +590,15 @@ class MPV(MPVBase):
|
||||
# Public API
|
||||
#
|
||||
def command(self, *args, timeout=1):
|
||||
"""Execute a single command on the mpv process and return the result.
|
||||
"""
|
||||
"""Execute a single command on the mpv process and return the result."""
|
||||
return self._send_request({"command": list(args)}, timeout=timeout)
|
||||
|
||||
def get_property(self, name):
|
||||
"""Return the value of property `name`.
|
||||
"""
|
||||
"""Return the value of property `name`."""
|
||||
return self.command("get_property", name)
|
||||
|
||||
def set_property(self, name, value):
|
||||
"""Set the value of property `name`.
|
||||
"""
|
||||
"""Set the value of property `name`."""
|
||||
return self.command("set_property", name, value)
|
||||
|
||||
|
||||
|
@ -119,7 +119,10 @@ class Previewer(QDialog):
|
||||
"reviewer.js",
|
||||
]
|
||||
self._web.stdHtml(
|
||||
self.mw.reviewer.revHtml(), css=["reviewer.css"], js=jsinc, context=self,
|
||||
self.mw.reviewer.revHtml(),
|
||||
css=["reviewer.css"],
|
||||
js=jsinc,
|
||||
context=self,
|
||||
)
|
||||
self._web.set_bridge_command(self._on_bridge_cmd, self)
|
||||
|
||||
|
@ -146,7 +146,9 @@ class ProfileManager:
|
||||
app = QtWidgets.QApplication([])
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(
|
||||
QtGui.QPixmap(":/icons/anki.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off,
|
||||
QtGui.QPixmap(":/icons/anki.png"),
|
||||
QtGui.QIcon.Normal,
|
||||
QtGui.QIcon.Off,
|
||||
)
|
||||
window_title = "Data Folder Migration"
|
||||
migration_directories = f"\n\n {oldBase}\n\nto\n\n {self.base}"
|
||||
|
@ -77,7 +77,8 @@ def on_normal_sync_timer(mw: aqt.main.AnkiQt) -> None:
|
||||
|
||||
assert isinstance(progress.val, NormalSyncProgress)
|
||||
mw.progress.update(
|
||||
label=f"{progress.val.added}\n{progress.val.removed}", process=False,
|
||||
label=f"{progress.val.added}\n{progress.val.removed}",
|
||||
process=False,
|
||||
)
|
||||
mw.progress.set_title(progress.val.stage)
|
||||
|
||||
|
@ -412,7 +412,10 @@ hooks = [
|
||||
),
|
||||
Hook(
|
||||
name="webview_will_set_content",
|
||||
args=["web_content: aqt.webview.WebContent", "context: Optional[Any]",],
|
||||
args=[
|
||||
"web_content: aqt.webview.WebContent",
|
||||
"context: Optional[Any]",
|
||||
],
|
||||
doc="""Used to modify web content before it is rendered.
|
||||
|
||||
Web_content contains the HTML, JS, and CSS the web view will be
|
||||
@ -526,7 +529,8 @@ hooks = [
|
||||
doc="""Executed when the top toolbar is redrawn""",
|
||||
),
|
||||
Hook(
|
||||
name="media_sync_did_progress", args=["entry: aqt.mediasync.LogEntryWithTime"],
|
||||
name="media_sync_did_progress",
|
||||
args=["entry: aqt.mediasync.LogEntryWithTime"],
|
||||
),
|
||||
Hook(name="media_sync_did_start_or_stop", args=["running: bool"]),
|
||||
Hook(
|
||||
@ -541,7 +545,10 @@ hooks = [
|
||||
args=["addcards: aqt.addcards.AddCards", "menu: QMenu"],
|
||||
legacy_hook="AddCards.onHistory",
|
||||
),
|
||||
Hook(name="add_cards_did_init", args=["addcards: aqt.addcards.AddCards"],),
|
||||
Hook(
|
||||
name="add_cards_did_init",
|
||||
args=["addcards: aqt.addcards.AddCards"],
|
||||
),
|
||||
Hook(
|
||||
name="add_cards_did_add_note",
|
||||
args=["note: anki.notes.Note"],
|
||||
@ -623,7 +630,10 @@ hooks = [
|
||||
name="editor_web_view_did_init",
|
||||
args=["editor_web_view: aqt.editor.EditorWebView"],
|
||||
),
|
||||
Hook(name="editor_did_init", args=["editor: aqt.editor.Editor"],),
|
||||
Hook(
|
||||
name="editor_did_init",
|
||||
args=["editor: aqt.editor.Editor"],
|
||||
),
|
||||
Hook(
|
||||
name="editor_will_load_note",
|
||||
args=["js: str", "note: anki.notes.Note", "editor: aqt.editor.Editor"],
|
||||
@ -675,7 +685,10 @@ hooks = [
|
||||
),
|
||||
# Model
|
||||
###################
|
||||
Hook(name="models_advanced_will_show", args=["advanced: QDialog"],),
|
||||
Hook(
|
||||
name="models_advanced_will_show",
|
||||
args=["advanced: QDialog"],
|
||||
),
|
||||
# Stats
|
||||
###################
|
||||
Hook(
|
||||
|
Loading…
Reference in New Issue
Block a user