-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python API: general improvements #30
Comments
watch out, Makefile.am in resources/runtime/python/ has a typo line 6 ( + = instead of +=) JH: corrected, thanks |
TODO: in ocarina.py, add some warning to the user if a module cannot be imported, instead of catching ImportError and discarding it |
Fixes regression for properties like Transmission_Time For issue #30
Issue in function analyze: the return values are not understood (and wrong): this: def analyze ():
'''Analyze models'''
info = io.BytesIO()
error = io.BytesIO()
raisedError = []
res = ''
with std_redirector(info,error):
try:
res = libocarina_python.analyze ()
except:
raisedError.append(getErrorMessage())
stderrMsg = sortStderrMessages(error.getvalue().decode('utf-8'))
if stderrMsg[1]!=[]:
raisedError.append(stderrMsg[1])
return [ res , info.getvalue().decode('utf-8'), stderrMsg[0] ,
raisedError ] returns this:
The first value (res) is OK - General output status Thanks |
Not sure what you are doing with stderr in the std_redirector context manager, but this messes up the logging functionality from stdlib and it becomes impossible to use it after calling an ocarina function:
This is probably due to the sys.stderr.close() that you do (in |
The return value of the instantiate function seems wrong:
The first return value (called success here) was expected to be a boolean, but it is a empty string. |
Regarding the output of the API functions, here is a part of the to be published design report:
In stderr, everything that is not considered as warning is considered an error. Regarding the context manager, in order to get stderr and stdout, both channels are redirected to two new python streams. Seems that I forget to replug stdout/err to the old channels after the function is called. Will look at it. Regarding the type of the result, it has not been defined to be a boolean. I just forward the result gived by Ocarina as a string. If the awaited result is false when error occurs and true in other cases, just let me know. |
Regarding the logging functionnality of the libc, in the std_redirector, the stdout/err are repluged to the original channels at the end of the ocarina function call. |
In the example shown above, "analyse" seems to return a boolean, not a string ( |
But this is not what is actually sent.
and NOT set(list, list, list, list) # {} is for set , [] is for list in your above interface
|
Maybe I used a wrong style, I really wanted to say the result is a list of four elements which are:
Regarding the warnings, I mentionned the problem of the signature of the warning message four comments above. JH: what do you mean by signature ? all warning messages should be prefixed by "warning", if not open a ticket |
Regarding the first item of the result list of the API function.
As such, this item cannot be considered neither as a boolean nor as a string. Its type is context dependant. |
(Topic: First returned item) OK to be context-dependent. In the case of JH: not a problem to return a boolean, you asked it also for analyze in the past (see the history). This is now implemented, but not tested. There might be trivial bug to solve |
I am not sure how the logging function is implemented, but I think it is something like that. log = logging.getLogger(__name__)
console = logging.StreamHandler(sys.__stdout__)
console.setFormatter(ColorFormatter())
log.addHandler(console) And there anywhere in your application you can do:
So I guess that if you close stdout and stderr in the middle of the application, the logging cannot recover the channel... |
Logging: I found a workaround, by using a StringIO in the logger, and print it at the end of the application: Initialization of the logger: log = logging.getLogger(__name__)
stream = StringIO.StringIO()
console = logging.StreamHandler(stream)
console.setFormatter(ColorFormatter())
log.addHandler(console) and before the application exits: print stream.getvalue()
stream.flush()
stream.close() |
(Topic: signature of error/warning) I found two signatures for warning messages:
I change my code to take the two versions. But if you confirm that it is a bug, I will create a ticket. JH: It is not, in some occasion we do not have access to the line number. But I guess there is still a minor bug: for the second occurrence, there should also be "warning" printed. Can you open a ticket with an example ? Thanks |
@yoogx : the "Warning" is printed, as seen in example above: |
Closing this old ticket |
This issue is to track request for improvements: which function should return something?
others?
The text was updated successfully, but these errors were encountered: