Skip to content

Commit

Permalink
Get everything working in 2/3
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Virshup committed May 16, 2017
1 parent 0add734 commit 8ee7c54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
19 changes: 15 additions & 4 deletions pyccc/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def exports(o):
DEFAULT_INTERPRETER = 'python%s.%s' % sys.version_info[:2]
PICKLE_PROTOCOL = 2 # required for 2/3 compatibile pickle objects

if sys.version_info.major == 2:
PYVERSION = 2
import __builtin__ as BUILTINS
else:
assert sys.version_info.major == 3
PYVERSION = 3
import builtins as BUILTINS


@exports
class PythonCall(object):
Expand All @@ -51,12 +59,14 @@ def __init__(self, function, *args, **kwargs):
self.kwargs = kwargs

try:
temp = function.__self__.__class__
cls = function.__self__.__class__
except AttributeError:
self.is_instancemethod = False
else:
self.is_instancemethod = True

if function.__self__ == BUILTINS or function.__self__ is None:
self.is_instancemethod = False
else:
self.is_instancemethod = True

@exports
class PythonJob(job.Job):
Expand Down Expand Up @@ -111,6 +121,7 @@ def _get_python_files(self):
python_files['function.pkl'] = pyccc.BytesContainer(
pickle.dumps(remote_function, protocol=PICKLE_PROTOCOL),
name='function.pkl')
self._remote_function = remote_function

sourcefile = StringContainer(self._get_source(),
name='source.py')
Expand Down Expand Up @@ -238,7 +249,7 @@ class PackagedFunction(native.object):
"""
def __init__(self, function_call):
func = function_call.function
self.is_imethod = getattr(func, '__self__', None) is not None
self.is_imethod = function_call.is_instancemethod
if self.is_imethod:
self.obj = func.__self__
self.imethod_name = func.__name__
Expand Down
12 changes: 6 additions & 6 deletions pyccc/tests/test_job_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

REMOTE_PYTHON_VERSIONS = {2: '2.7', 3: '3.6'}
PYVERSION = REMOTE_PYTHON_VERSIONS[sys.version_info.major]

PYIMAGE = 'python:%s-slim' % PYVERSION


########################
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_sleep_raises_jobstillrunning(fixture, request):
def test_python_function(fixture, request):
engine = request.getfuncargvalue(fixture)
pycall = pyccc.PythonCall(_testfun, 5)
job = engine.launch('python:%s-slim'%PYVERSION, pycall, interpreter=PYVERSION)
job = engine.launch(PYIMAGE, pycall, interpreter=PYVERSION)
job.wait()
assert job.result == 6

Expand All @@ -77,7 +77,7 @@ def test_python_instance_method(fixture, request):
engine = request.getfuncargvalue(fixture)
obj = _TestCls()
pycall = pyccc.PythonCall(obj.increment, by=2)
job = engine.launch('python:%s-slim' % PYVERSION, pycall, interpreter=PYVERSION)
job = engine.launch(PYIMAGE, pycall, interpreter=PYVERSION)
job.wait()

assert job.result == 2
Expand All @@ -88,7 +88,7 @@ def test_python_instance_method(fixture, request):
def test_python_reraises_exception(fixture, request):
engine = request.getfuncargvalue(fixture)
pycall = pyccc.PythonCall(_raise_valueerror, 'this is my message')
job = engine.launch('python:%s-slim' % PYVERSION, pycall, interpreter=PYVERSION)
job = engine.launch(PYIMAGE, pycall, interpreter=PYVERSION)
job.wait()

with pytest.raises(ValueError):
Expand All @@ -100,7 +100,7 @@ def test_builtin_imethod(fixture, request):
engine = request.getfuncargvalue(fixture)
mylist = [3, 2, 1]
fn = pyccc.PythonCall(mylist.sort)
job = engine.launch(image='python:2.7-slim', command=fn, interpreter=PYVERSION)
job = engine.launch(image=PYIMAGE, command=fn, interpreter=PYVERSION)
job.wait()

assert job.result is None # since sort doesn't return anything
Expand All @@ -112,7 +112,7 @@ def test_builtin_function(fixture, request):
engine = request.getfuncargvalue(fixture)
mylist = [3, 2, 1]
fn = pyccc.PythonCall(sorted, mylist)
job = engine.launch(image='python:2.7-slim', command=fn, interpreter=PYVERSION)
job = engine.launch(image=PYIMAGE, command=fn, interpreter=PYVERSION)
job.wait()

assert job.result == [1,2,3]
Expand Down

0 comments on commit 8ee7c54

Please sign in to comment.