From 9390f08262132030441318c80433041ca792bc93 Mon Sep 17 00:00:00 2001 From: Alexandre Barbosa Bruno Date: Fri, 16 Feb 2024 16:44:39 -0300 Subject: [PATCH 1/6] fix plugin loading --- hookman/hookman_utils.py | 5 +++++ hookman/hooks.py | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/hookman/hookman_utils.py b/hookman/hookman_utils.py index e919b64..aa0545b 100644 --- a/hookman/hookman_utils.py +++ b/hookman/hookman_utils.py @@ -40,12 +40,17 @@ def change_path_env(shared_lib_path: str): Change PATH environment adding the shared library path to it. """ old_path = os.environ["PATH"] + handle = None if sys.platform.startswith("win"): os.environ["PATH"] = old_path + os.pathsep + os.path.dirname(shared_lib_path) + handle = os.add_dll_directory(os.path.dirname(shared_lib_path)) try: yield finally: os.environ["PATH"] = old_path + if handle is not None: + handle.close() + @contextmanager diff --git a/hookman/hooks.py b/hookman/hooks.py index b49cb7e..41a67b9 100644 --- a/hookman/hooks.py +++ b/hookman/hooks.py @@ -10,6 +10,7 @@ from hookman import hookman_utils from hookman.exceptions import InvalidDestinationPathError from hookman.exceptions import PluginAlreadyInstalledError +from hookman.hookman_utils import change_path_env from hookman.plugin_config import PluginInfo @@ -206,5 +207,6 @@ def get_hook_caller(self, ignored_plugins: Sequence[str] = ()): _hookman = __import__(self.specs.pyd_name) hook_caller = _hookman.HookCaller() for plugin in self.get_plugins_available(ignored_plugins): - hook_caller.load_impls_from_library(str(plugin.shared_lib_path), plugin.id) + with change_path_env(str(plugin.shared_lib_path)): + hook_caller.load_impls_from_library(str(plugin.shared_lib_path), plugin.id) return hook_caller From 2f5a7cec511f3a9bbb498e8f00b051a096febd67 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 20 Feb 2024 12:08:09 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- hookman/hookman_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/hookman/hookman_utils.py b/hookman/hookman_utils.py index aa0545b..f0774aa 100644 --- a/hookman/hookman_utils.py +++ b/hookman/hookman_utils.py @@ -52,7 +52,6 @@ def change_path_env(shared_lib_path: str): handle.close() - @contextmanager def load_shared_lib(shared_lib_path: str) -> ctypes.CDLL: """ From a9ab559d14ae1e620a8a87d879f34068c57d3a36 Mon Sep 17 00:00:00 2001 From: Alexandre Barbosa Bruno Date: Tue, 20 Feb 2024 10:18:38 -0300 Subject: [PATCH 3/6] add pragma no cover --- hookman/hookman_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hookman/hookman_utils.py b/hookman/hookman_utils.py index aa0545b..facb003 100644 --- a/hookman/hookman_utils.py +++ b/hookman/hookman_utils.py @@ -43,13 +43,13 @@ def change_path_env(shared_lib_path: str): handle = None if sys.platform.startswith("win"): os.environ["PATH"] = old_path + os.pathsep + os.path.dirname(shared_lib_path) - handle = os.add_dll_directory(os.path.dirname(shared_lib_path)) + handle = os.add_dll_directory(os.path.dirname(shared_lib_path)) # pragma: no cover - team decided that was hard make a test capable of getting this try: yield finally: os.environ["PATH"] = old_path if handle is not None: - handle.close() + handle.close() # pragma: no cover - team decided that was hard make a test capable of getting this From be896ce7dad80360d5165b17b513a72fa4801c0c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 20 Feb 2024 13:19:55 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- hookman/hookman_utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hookman/hookman_utils.py b/hookman/hookman_utils.py index fb6eb15..3b5ad5f 100644 --- a/hookman/hookman_utils.py +++ b/hookman/hookman_utils.py @@ -43,13 +43,15 @@ def change_path_env(shared_lib_path: str): handle = None if sys.platform.startswith("win"): os.environ["PATH"] = old_path + os.pathsep + os.path.dirname(shared_lib_path) - handle = os.add_dll_directory(os.path.dirname(shared_lib_path)) # pragma: no cover - team decided that was hard make a test capable of getting this + handle = os.add_dll_directory( + os.path.dirname(shared_lib_path) + ) # pragma: no cover - team decided that was hard make a test capable of getting this try: yield finally: os.environ["PATH"] = old_path if handle is not None: - handle.close() # pragma: no cover - team decided that was hard make a test capable of getting this + handle.close() # pragma: no cover - team decided that was hard make a test capable of getting this @contextmanager From ef9ca8e8acb413c07b389a422a78706445fd9afa Mon Sep 17 00:00:00 2001 From: Alexandre Barbosa Bruno Date: Fri, 23 Feb 2024 09:48:50 -0300 Subject: [PATCH 5/6] Update hookman/hookman_utils.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Martin PrĂ¼sse --- hookman/hookman_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hookman/hookman_utils.py b/hookman/hookman_utils.py index 3b5ad5f..b56272f 100644 --- a/hookman/hookman_utils.py +++ b/hookman/hookman_utils.py @@ -42,16 +42,17 @@ def change_path_env(shared_lib_path: str): old_path = os.environ["PATH"] handle = None if sys.platform.startswith("win"): + # We explict opted to not cover this on windows. os.environ["PATH"] = old_path + os.pathsep + os.path.dirname(shared_lib_path) handle = os.add_dll_directory( os.path.dirname(shared_lib_path) - ) # pragma: no cover - team decided that was hard make a test capable of getting this + ) # pragma: no cover try: yield finally: os.environ["PATH"] = old_path if handle is not None: - handle.close() # pragma: no cover - team decided that was hard make a test capable of getting this + handle.close() # pragma: no cover @contextmanager From c692abf60adc5ecdfa74b10693186ff7f3f68d33 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:48:55 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- hookman/hookman_utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hookman/hookman_utils.py b/hookman/hookman_utils.py index b56272f..d09819e 100644 --- a/hookman/hookman_utils.py +++ b/hookman/hookman_utils.py @@ -44,9 +44,7 @@ def change_path_env(shared_lib_path: str): if sys.platform.startswith("win"): # We explict opted to not cover this on windows. os.environ["PATH"] = old_path + os.pathsep + os.path.dirname(shared_lib_path) - handle = os.add_dll_directory( - os.path.dirname(shared_lib_path) - ) # pragma: no cover + handle = os.add_dll_directory(os.path.dirname(shared_lib_path)) # pragma: no cover try: yield finally: