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: update numba hook for compatibility with upcoming v0.61 #857

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 27 additions & 0 deletions _pyinstaller_hooks_contrib/stdhooks/hook-numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,30 @@
# around for backward compatibility with existing pickled data, but does not import it directly anymore.
if is_module_satisfies("numba >= 0.59.0"):
hiddenimports += ["numba.cloudpickle.cloudpickle_fast"]

# numba 0.61 introduced new type system with several dynamic redirects using `numba.core.utils._RedirectSubpackage`;
# depending on the run-time value of `numba.config.USE_LEGACY_TYPE_SYSTEM`, either "old" or "new" module variant is
# loaded. All of these seem to be loaded when `numba` is imported, so there is no need for finer granularity. Also,
# as the config value might be manipulated at run-time (e.g., via environment variable), we need to collect both old
# and new module variants.
if is_module_satisfies("numba >= 0.61.0rc1"):
# NOTE: `numba.core.typing` is also referenced indirectly via `_RedirectSubpackage`, but we do not need a
# hidden import entry for it, because we have entries for its submodules.
modules_old = [
'numba.core.datamodel.old_models',
'numba.core.old_boxing',
'numba.core.types.old_scalars',
'numba.core.typing.old_builtins',
'numba.core.typing.old_cmathdecl',
'numba.core.typing.old_mathdecl',
'numba.cpython.old_builtins',
'numba.cpython.old_hashing',
'numba.cpython.old_mathimpl',
'numba.cpython.old_numbers',
'numba.cpython.old_tupleobj',
'numba.np.old_arraymath',
'numba.np.random.old_distributions',
'numba.np.random.old_random_methods',
]
modules_new = [name.replace('.old_', '.new_') for name in modules_old]
hiddenimports += modules_old + modules_new
2 changes: 2 additions & 0 deletions news/857.update.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Update ``numba`` hook for compatibility with upcoming 0.61 release (based
on 0.61.0rc2).
27 changes: 27 additions & 0 deletions tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1993,6 +1993,33 @@ def test_iso639(pyi_builder):
""")


# Basic JIT test with numba
@importorskip('numba')
def test_numba_jit(pyi_builder):
pyi_builder.test_source("""
import numba

@numba.jit
def f(x, y):
return x + y

assert f(1, 2) == 3
""")


# Basic import test with new type system enabled (numba >= 0.61).
# Ideally, we would repeat the above `test_numba_jit`, but at the time of writing (numba 0.61.0rc2) it does not seem to
# work even when unfrozen.
@importorskip('numba')
@pytest.mark.skipif(not is_module_satisfies('numba >= 0.61.0rc1'), reason="Requires numba >= 0.61.0.")
def test_numba_new_type_system(pyi_builder):
pyi_builder.test_source("""
import os
os.environ['NUMBA_USE_LEGACY_TYPE_SYSTEM'] = '0'
import numba
""")


# Check that `numba.cloudpickle.cloudpickle_fast` is collected even if it is not directly imported anywhere.
@importorskip('numba')
def test_numba_cloudpickle_fast(pyi_builder):
Expand Down
Loading