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: Recompile the numpy.core.overrides module to limit optimization #2358

Merged
merged 1 commit into from
Apr 25, 2024
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
14 changes: 14 additions & 0 deletions cx_Freeze/hooks/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ def load_numpy_core__add_newdocs(
finder.include_module("numpy.core._multiarray_tests")


def load_numpy_core_overrides(finder: ModuleFinder, module: Module) -> None:
"""Recompile the numpy.core.overrides module to limit optimization by
avoiding removing docstrings, which are required for this module.
"""
code_string = module.file.read_text(encoding="utf_8")
module.code = compile(
code_string.replace("dispatcher.__doc__", "dispatcher.__doc__ or ''"),
os.fspath(module.file),
"exec",
dont_inherit=True,
optimize=min(finder.optimize, 1),
)


def load_numpy__distributor_init(finder: ModuleFinder, module: Module) -> None:
"""Fix the location of dependent files in Windows and macOS."""
if IS_LINUX or IS_MINGW:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_hooks_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@pytest.mark.datafiles(SAMPLES_DIR / "pandas")
def test_pandas(datafiles: Path) -> None:
"""Test that the pandas/numpy is working correctly."""
output = run_command(datafiles)
output = run_command(datafiles, "python setup.py build_exe -O2")
executable = datafiles / BUILD_EXE_DIR / f"test_pandas{SUFFIX}"
assert executable.is_file()

Expand Down