diff --git a/hookman/hookman_utils.py b/hookman/hookman_utils.py index e919b64..d09819e 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"): + # 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 try: yield finally: os.environ["PATH"] = old_path + if handle is not None: + handle.close() # pragma: no cover @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