Skip to content

Commit

Permalink
Merge pull request #28 from glutanimate/add-skip-addon-loading-option
Browse files Browse the repository at this point in the history
Add option to skip add-on loading
  • Loading branch information
glutanimate authored Jan 16, 2023
2 parents f961497 + 828344a commit 02f83a2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pytest_anki/_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def anki_running(
unpacked_addons: Optional[List[Tuple[str, PathLike]]] = None,
addon_configs: Optional[List[Tuple[str, Dict[str, Any]]]] = None,
enable_web_debugging: bool = True,
skip_loading_addons: bool = False,
) -> Iterator[AnkiSession]:
"""Context manager that safely launches an Anki session, cleaning up after itself
Expand Down Expand Up @@ -157,6 +158,10 @@ def anki_running(
If specified, launches Anki with QTWEBENGINE_REMOTE_DEBUGGING set, allowing
you to remotely debug Qt web engine views.
skip_loading_addons {bool}:
If set to True, will skip loading packed and unpacked add-ons, giving the
caller full control over the add-on import time.
Returns:
Iterator[AnkiSession] -- [description]
Expand All @@ -178,6 +183,7 @@ def anki_running(
unpacked_addons=unpacked_addons,
addon_configs=addon_configs,
preset_anki_state=preset_anki_state,
skip_loading_addons=skip_loading_addons,
)

# Apply preset Anki profile and collection.conf storage on profile load
Expand Down
4 changes: 3 additions & 1 deletion pytest_anki/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def post_ui_setup_callback_factory(
unpacked_addons: Optional[List[Tuple[str, PathLike]]] = None,
addon_configs: Optional[List[Tuple[str, Dict[str, Any]]]] = None,
preset_anki_state: Optional[AnkiStateUpdate] = None,
skip_loading_addons: bool = False,
):
def post_ui_setup_callback(main_window: AnkiQt):
"""Initialize add-on manager, install add-ons, load add-ons"""
Expand Down Expand Up @@ -97,7 +98,8 @@ def post_ui_setup_callback(main_window: AnkiQt):
main_window=main_window, anki_state_update=preset_anki_state
)

main_window.addonManager.loadAddons()
if not skip_loading_addons:
main_window.addonManager.loadAddons()

return post_ui_setup_callback

Expand Down
3 changes: 3 additions & 0 deletions pytest_anki/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def anki_session(request: "FixtureRequest", qtbot: "QtBot") -> Iterator[AnkiSess
If specified, launches Anki with QTWEBENGINE_REMOTE_DEBUGGING set, allowing
you to remotely debug Qt web engine views.
skip_loading_addons {bool}:
If set to True, will skip loading packed and unpacked add-ons, giving the
caller full control over the add-on import time.
"""

indirect_parameters: Optional[Dict[str, Any]] = getattr(request, "param", None)
Expand Down

0 comments on commit 02f83a2

Please sign in to comment.