Skip to content

Commit 197de98

Browse files
committed
testing: another try
1 parent f8a3459 commit 197de98

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

dill/_dill.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -364,31 +364,35 @@ def dumps(obj, protocol=None, byref=None, fmode=None, recurse=None, portable=Non
364364
"""
365365
if os.environ.get('CI') and \
366366
getattr(obj, '__qualname__', None) != 'test_getstate.<locals>.<lambda>' and \
367-
not (os.environ.get('TRAVIS') and \
368-
obj.__module__ == 'numpy' if isinstance(obj, type) else any(base.__module__ == 'numpy' for base in type(obj).mro())) and \
369367
__file__ != 'test_session.py':
370368
_test_portable(obj, protocol, byref, fmode, recurse, **kwds)
371369
file = StringIO()
372370
dump(obj, file, protocol, byref, fmode, recurse, portable, **kwds)#, strictio)
373371
return file.getvalue()
374372

373+
_tempd = None
375374
def _test_portable(obj, protocol, byref, fmode, recurse, **kwds):
376-
import dill, subprocess, tempfile, textwrap
375+
import atexit, dill, subprocess, tempfile, textwrap
377376
try:
378377
import pox
379378
python = pox.which_python(version=True, fullpath=False) or 'python'
380379
except ImportError:
381380
python = 'python'
382381

382+
global _tempd
383+
if _tempd is None:
384+
import shutil
385+
from importlib.util import find_spec
386+
_tempd = tempfile.mkdtemp()
387+
atexit.register(shutil.rmtree, _tempd)
388+
os.symlink(os.path.dirname(find_spec('numpy').origin), os.path.join(_tempd, 'numpy'), True)
389+
os.symlink(find_spec('dill._objects').origin, os.path.join(_tempd, '_objects.py'))
383390
temp = tempfile.NamedTemporaryFile()
391+
384392
script = textwrap.dedent(f"""\
385393
import importlib, os, pickle, sys, types
386394
dill_spec = importlib.util.find_spec('dill')
387-
if os.path.exists(os.path.join('dill', '__init__.py')):
388-
sys.path.insert(0, 'dill') # for _objects
389-
sys.path.remove('')
390395
while (spec := importlib.util.find_spec("dill")) is not None:
391-
sys.path.insert(0, os.path.dirname(spec.origin))
392396
sys.path.remove(os.path.dirname(os.path.dirname(spec.origin)))
393397
try:
394398
with open("{temp.name}", "rb") as f: pickle.load(f)
@@ -417,7 +421,7 @@ def _test_portable(obj, protocol, byref, fmode, recurse, **kwds):
417421
if all('Cannot locate reference' not in str(warn.message) for warn in warns):
418422
temp.file.flush()
419423
dill_path = os.path.dirname(dill.__path__[0])
420-
subprocess.run(python, input=script, check=True)
424+
subprocess.run(python, input=script, cwd=_tempd, check=True)
421425
finally:
422426
warnings.simplefilter('error')
423427
temp.file.close()

0 commit comments

Comments
 (0)