-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into FIX_pytest_warns_None
- Loading branch information
Showing
11 changed files
with
198 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
""" | ||
Small shim of loky's cloudpickle_wrapper to avoid failure when | ||
multiprocessing is not available. | ||
""" | ||
|
||
|
||
from ._multiprocessing_helpers import mp | ||
|
||
|
||
def my_wrap_non_picklable_objects(obj, keep_wrapper=True): | ||
return obj | ||
|
||
|
||
if mp is None: | ||
wrap_non_picklable_objects = my_wrap_non_picklable_objects | ||
else: | ||
from .externals.loky import wrap_non_picklable_objects # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Test that our implementation of wrap_non_picklable_objects mimics | ||
properly the loky implementation. | ||
""" | ||
|
||
from .._cloudpickle_wrapper import wrap_non_picklable_objects | ||
from .._cloudpickle_wrapper import my_wrap_non_picklable_objects | ||
|
||
|
||
def a_function(x): | ||
return x | ||
|
||
|
||
class AClass(object): | ||
|
||
def __call__(self, x): | ||
return x | ||
|
||
|
||
def test_wrap_non_picklable_objects(): | ||
# Mostly a smoke test: test that we can use callable in the same way | ||
# with both our implementation of wrap_non_picklable_objects and the | ||
# upstream one | ||
for obj in (a_function, AClass()): | ||
wrapped_obj = wrap_non_picklable_objects(obj) | ||
my_wrapped_obj = my_wrap_non_picklable_objects(obj) | ||
assert wrapped_obj(1) == my_wrapped_obj(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Pyodide and other single-threaded Python builds will be missing the | ||
_multiprocessing module. Test that joblib still works in this environment. | ||
""" | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
|
||
|
||
def test_missing_multiprocessing(tmp_path): | ||
""" | ||
Test that import joblib works even if _multiprocessing is missing. | ||
pytest has already imported everything from joblib. The most reasonable way | ||
to test importing joblib with modified environment is to invoke a separate | ||
Python process. This also ensures that we don't break other tests by | ||
importing a bad `_multiprocessing` module. | ||
""" | ||
(tmp_path / "_multiprocessing.py").write_text( | ||
'raise ImportError("No _multiprocessing module!")' | ||
) | ||
env = dict(os.environ) | ||
# For subprocess, use current sys.path with our custom version of | ||
# multiprocessing inserted. | ||
env["PYTHONPATH"] = ":".join([str(tmp_path)] + sys.path) | ||
subprocess.check_call( | ||
[sys.executable, "-c", | ||
"import joblib, math; " | ||
"joblib.Parallel(n_jobs=1)(" | ||
"joblib.delayed(math.sqrt)(i**2) for i in range(10))" | ||
], env=env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.