Skip to content

Commit

Permalink
fixed some matlab side error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
mccullerlp committed Jan 18, 2018
1 parent 155c3e7 commit f02fd96
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
30 changes: 24 additions & 6 deletions msurrogate/+msurrogate/collectargs.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
%subtract two to also avoid the colon itself
args = {};
kwargs = struct();
idx_kw = numel(args_raw);
idx_kw = numel(args_raw) + 1;
for i = 1:numel(args_raw)
arg = args_raw{i};
switch class(arg)
Expand All @@ -22,12 +22,30 @@
end
end

args
kwargs
idx_kw

i = idx_kw;
while i < numel(args_raw)
field = args_raw{i};
val = args_raw{i + 1};
kwargs.(field) = val;
i = i + 2;
try
while i <= numel(args_raw)
field = args_raw{i};
val = args_raw{i + 1};
kwargs.(field) = val;
i = i + 2;
end
catch ME
switch ME.identifier
case 'MATLAB:badsubscript'
error('Unbalanced keyword arguments. It is also possible that string arguments are not inside a cell array. Calling convention for python objects is ({args...}, kwstruct, "key", value, "key", value...)')
case 'MATLAB:mustBeFieldName'
error('Keyword argument wrong type or unbalanced keyword arguments. It is also possible that arguments are not inside a cell array. Calling convention for python objects is ({args...}, kwstruct, "key", value, "key", value...)')
case 'MATLAB:AddField:InvalidFieldName'
rethrow(ME)
otherwise
disp(ME)
rethrow(ME)
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions msurrogate/+msurrogate/pyrowrap.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function delete(self)
function out = dir(self)
call = py.getattr(self.internal(), 'pyrometa_dir');
val = msurrogate.pyapply(call, {}, struct());
out = msurrogate.py2mat(py.dir(dir), self.handle);
out = msurrogate.py2mat(val, self.handle);
end

function c = repr(self)
Expand All @@ -253,7 +253,7 @@ function delete(self)
end

function out = properties(self)
out = dir(self)
out = dir(self);
end

function val = pyraw(self)
Expand Down
3 changes: 1 addition & 2 deletions msurrogate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@


def matlabpath():
return path.split(__file__)[0]
return path.abspath(path.split(__file__)[0])


from .meta_app import (
SurrogateApp,
cookie_setup,
)


from .subproc_server import (
SurrogateSubprocess,
)
1 change: 1 addition & 0 deletions msurrogate/meta_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def pyrometa_setitem(self, idx, val):
return

def pyrometa_call(self, name, *args, **kwargs):
print(name, args, kwargs)
if name is None:
val = self.obj
else:
Expand Down
2 changes: 1 addition & 1 deletion msurrogate/ping_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
"""
from __future__ import division, print_function, unicode_literals
from msurrogate.meta_app import SurrogateApp
from msurrogate import SurrogateApp


def test_ping(text = ''):
Expand Down
4 changes: 3 additions & 1 deletion msurrogate/subproc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ def __init__(
if module_name is None:
raise RuntimeError("Must specify module_name")

#the -u is for unbuffered output (otherwise code must use flush everywhere)
#-S - and -c - are for the secret to be relayed via stdin and the cookie via stdout.
self.proc = subprocess.Popen(
[python_call, '-m', module_name, '-S', '-', '-c', '-'] + args,
[python_call, '-u', '-m', module_name, '-S', '-', '-c', '-'] + args,
stdout = subprocess.PIPE,
stdin = subprocess.PIPE,
stderr = subprocess.PIPE,
Expand Down

0 comments on commit f02fd96

Please sign in to comment.