Skip to content

Commit

Permalink
hooks: Recompile the numpy.core.overrides module to limit optimization (
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotduarte committed Apr 25, 2024
1 parent de2888d commit aa89bd0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit aa89bd0

Please sign in to comment.