From 6f7ebbb94b85bb086092bc6cfe42f44c33624198 Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Sat, 17 Sep 2022 22:53:56 +0200 Subject: [PATCH 1/2] Add an option to skip loading add-ons when specifying packed or unpacked add-ons to install --- pytest_anki/_launch.py | 6 ++++++ pytest_anki/_patch.py | 4 +++- pytest_anki/plugin.py | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pytest_anki/_launch.py b/pytest_anki/_launch.py index 8592675..c3a0ec7 100644 --- a/pytest_anki/_launch.py +++ b/pytest_anki/_launch.py @@ -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 @@ -156,6 +157,10 @@ def anki_running( web_debugging_port {Optional[int]}: 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] @@ -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 diff --git a/pytest_anki/_patch.py b/pytest_anki/_patch.py index 4c2d12d..0056dc3 100644 --- a/pytest_anki/_patch.py +++ b/pytest_anki/_patch.py @@ -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""" @@ -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 diff --git a/pytest_anki/plugin.py b/pytest_anki/plugin.py index 60c7d36..bf15d60 100644 --- a/pytest_anki/plugin.py +++ b/pytest_anki/plugin.py @@ -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) From 828344a2153e9bf24a9de0bdbbe3b82b1dfb0d4b Mon Sep 17 00:00:00 2001 From: Glutanimate Date: Sat, 17 Sep 2022 22:55:09 +0200 Subject: [PATCH 2/2] Satisfy linters --- pytest_anki/_launch.py | 4 ++-- pytest_anki/_patch.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pytest_anki/_launch.py b/pytest_anki/_launch.py index c3a0ec7..11d4461 100644 --- a/pytest_anki/_launch.py +++ b/pytest_anki/_launch.py @@ -157,7 +157,7 @@ def anki_running( web_debugging_port {Optional[int]}: 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. @@ -183,7 +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 + skip_loading_addons=skip_loading_addons, ) # Apply preset Anki profile and collection.conf storage on profile load diff --git a/pytest_anki/_patch.py b/pytest_anki/_patch.py index 0056dc3..c0ccb5a 100644 --- a/pytest_anki/_patch.py +++ b/pytest_anki/_patch.py @@ -65,7 +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 + skip_loading_addons: bool = False, ): def post_ui_setup_callback(main_window: AnkiQt): """Initialize add-on manager, install add-ons, load add-ons"""