Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix alfasim plugin library loading #129

Merged
merged 7 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions hookman/hookman_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ 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)
) # 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
alexandrebbruno marked this conversation as resolved.
Show resolved Hide resolved


@contextmanager
Expand Down
4 changes: 3 additions & 1 deletion hookman/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Loading