Skip to content

Commit

Permalink
hooks: move sklearn hook to a submodule (#1954)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotduarte committed Jul 10, 2023
1 parent e906c03 commit d1aaf0e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
16 changes: 0 additions & 16 deletions cx_Freeze/hooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,22 +466,6 @@ def load_sentry(finder: ModuleFinder, module: Module) -> None:
finder.include_module("sentry_sdk.integrations.threading")


def load_sklearn__distributor_init(
finder: ModuleFinder, module: Module
) -> None:
"""On Windows the sklearn/.libs directory is not copied."""
source_dir = module.parent.path[0] / ".libs"
if source_dir.exists():
# msvcp140 and vcomp140 dlls should be copied
finder.include_files(source_dir, "lib")
# patch the code to search the correct directory
code_string = module.file.read_text(encoding="utf-8")
code_string = code_string.replace(
"libs_path =", "libs_path = __import__('sys').frozen_dir #"
)
module.code = compile(code_string, os.fspath(module.file), "exec")


def load_setuptools(finder: ModuleFinder, module: Module) -> None:
"""The setuptools must be loaded as a package, to prevent it to break in
the future.
Expand Down
26 changes: 26 additions & 0 deletions cx_Freeze/hooks/sklearn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""A collection of functions which are triggered automatically by finder when
scipy package is included.
"""

from __future__ import annotations

import os

from ..finder import ModuleFinder
from ..module import Module


def load_sklearn__distributor_init(
finder: ModuleFinder, module: Module
) -> None:
"""Fix the location of dependent files in Windows."""
source_dir = module.parent.path[0] / ".libs"
if source_dir.exists():
# msvcp140 and vcomp140 dlls should be copied
finder.include_files(source_dir, "lib")
# patch the code to search the correct directory
code_string = module.file.read_text(encoding="utf-8")
code_string = code_string.replace(
"libs_path =", "libs_path = __import__('sys').frozen_dir #"
)
module.code = compile(code_string, os.fspath(module.file), "exec")

0 comments on commit d1aaf0e

Please sign in to comment.