Skip to content

Commit

Permalink
hooks: add hook for cloudpickle
Browse files Browse the repository at this point in the history
Add hook for `cloudpickle` to ensure that `cloudpickle.cloudpickle_fast`
is collected when using `cloudpickle° v3.0.0 or later.
  • Loading branch information
rokm committed Mar 20, 2024
1 parent 5a7c558 commit 38f00c9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions news/716.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add hook for ``cloudpickle`` to ensure that ``cloudpickle.cloudpickle_fast``
is collected when using ``cloudpickle`` v3.0.0 or later.
1 change: 1 addition & 0 deletions requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cassandra-driver==3.29.0
cf-units==3.2.0; sys_platform != 'win32'
cftime==1.6.3
charset_normalizer==3.3.2
cloudpickle==3.0.0
cloudscraper==1.2.71
# compliance-checker requires cf-units, so same constraints apply.
compliance-checker==5.1.0; sys_platform != 'win32'
Expand Down
18 changes: 18 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-cloudpickle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ------------------------------------------------------------------
# Copyright (c) 2024 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------

from PyInstaller.utils.hooks import is_module_satisfies

# cloudpickle to 3.0.0 keeps `cloudpickle_fast` module around for backward compatibility with existing pickled data,
# but does not import it directly anymore. Ensure it is collected nevertheless.
if is_module_satisfies("cloudpickle >= 3.0.0"):
hiddenimports = ["cloudpickle.cloudpickle_fast"]
14 changes: 14 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1934,3 +1934,17 @@ def test_numba_cloudpickle_fast(pyi_builder):
modname = "numba.cloudpickle.cloudpickle_fast"
mod = importlib.import_module(modname)
""")


# Check that `cloudpickle.cloudpickle_fast` is collected even if it is not directly imported anywhere.
@importorskip('cloudpickle')
def test_cloudpickle_fast(pyi_builder):
pyi_builder.test_source("""
# Assume the application or its dependencies import cloudpickle somewhere.
import cloudpickle
# Simulate indirect import of `cloudpickle.cloudpickle_fast`that would happen during data unpickling.
import importlib
modname = "cloudpickle.cloudpickle_fast"
mod = importlib.import_module(modname)
""")

0 comments on commit 38f00c9

Please sign in to comment.