Skip to content

Commit

Permalink
testing: another try
Browse files Browse the repository at this point in the history
  • Loading branch information
leogama committed May 31, 2022
1 parent f8a3459 commit 197de98
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions dill/_dill.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,31 +364,35 @@ def dumps(obj, protocol=None, byref=None, fmode=None, recurse=None, portable=Non
"""
if os.environ.get('CI') and \
getattr(obj, '__qualname__', None) != 'test_getstate.<locals>.<lambda>' and \
not (os.environ.get('TRAVIS') and \
obj.__module__ == 'numpy' if isinstance(obj, type) else any(base.__module__ == 'numpy' for base in type(obj).mro())) and \
__file__ != 'test_session.py':
_test_portable(obj, protocol, byref, fmode, recurse, **kwds)
file = StringIO()
dump(obj, file, protocol, byref, fmode, recurse, portable, **kwds)#, strictio)
return file.getvalue()

_tempd = None
def _test_portable(obj, protocol, byref, fmode, recurse, **kwds):
import dill, subprocess, tempfile, textwrap
import atexit, dill, subprocess, tempfile, textwrap
try:
import pox
python = pox.which_python(version=True, fullpath=False) or 'python'
except ImportError:
python = 'python'

global _tempd
if _tempd is None:
import shutil
from importlib.util import find_spec
_tempd = tempfile.mkdtemp()
atexit.register(shutil.rmtree, _tempd)
os.symlink(os.path.dirname(find_spec('numpy').origin), os.path.join(_tempd, 'numpy'), True)
os.symlink(find_spec('dill._objects').origin, os.path.join(_tempd, '_objects.py'))
temp = tempfile.NamedTemporaryFile()

script = textwrap.dedent(f"""\
import importlib, os, pickle, sys, types
dill_spec = importlib.util.find_spec('dill')
if os.path.exists(os.path.join('dill', '__init__.py')):
sys.path.insert(0, 'dill') # for _objects
sys.path.remove('')
while (spec := importlib.util.find_spec("dill")) is not None:
sys.path.insert(0, os.path.dirname(spec.origin))
sys.path.remove(os.path.dirname(os.path.dirname(spec.origin)))
try:
with open("{temp.name}", "rb") as f: pickle.load(f)
Expand Down Expand Up @@ -417,7 +421,7 @@ def _test_portable(obj, protocol, byref, fmode, recurse, **kwds):
if all('Cannot locate reference' not in str(warn.message) for warn in warns):
temp.file.flush()
dill_path = os.path.dirname(dill.__path__[0])
subprocess.run(python, input=script, check=True)
subprocess.run(python, input=script, cwd=_tempd, check=True)
finally:
warnings.simplefilter('error')
temp.file.close()
Expand Down

0 comments on commit 197de98

Please sign in to comment.