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

hooks: move sklearn hook to a submodule #1954

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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")