Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hooks: fix scipy hooks used in zip_include_packages (#1903)
- Loading branch information
1 parent
ff2a551
commit f3cdbfd
Showing
3 changed files
with
82 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Helper functions for hooks.""" | ||
|
||
from __future__ import annotations | ||
|
||
from types import CodeType | ||
|
||
from ..common import code_object_replace_function | ||
from ..module import Module | ||
|
||
|
||
def replace_delvewheel_patch(module: Module) -> None: | ||
"""Replace delvewheel injections of code to not find for module.libs | ||
directory. | ||
""" | ||
code = module.code | ||
if code is None: | ||
return | ||
|
||
delvewheel_func = "_delvewheel_init_patch_" | ||
consts = list(code.co_consts) | ||
for constant in consts: | ||
if isinstance(constant, CodeType): | ||
name = constant.co_name | ||
if name.startswith(delvewheel_func): | ||
source = f"""\ | ||
def {name}(): | ||
import os, sys | ||
libs_path = os.path.join( | ||
sys.frozen_dir, "lib", "{module.name}.libs" | ||
) | ||
try: | ||
os.add_dll_directory(libs_path) | ||
except (OSError, AttributeError): | ||
pass | ||
env_path = os.environ.get("PATH", "").split(os.pathsep) | ||
if libs_path not in env_path: | ||
env_path.insert(0, libs_path) | ||
os.environ["PATH"] = os.pathsep.join(env_path) | ||
""" | ||
code = code_object_replace_function(code, name, source) | ||
break | ||
module.code = code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters