ome / omero-scripts

Core OMERO Scripts
https://pypi.org/project/omero-scripts/
12 stars 32 forks source link

py3 issues #158

Closed will-moore closed 4 years ago

will-moore commented 4 years ago

Batch_ROI_Export failing because of unicode um characters at

 File "./script", line 335, in run_script
    result = batch_roi_export(conn, script_params)
  File "./script", line 280, in batch_roi_export
    file_ann = write_csv(conn, export_data, script_params, symbol)
  File "./script", line 238, in write_csv
    csv_file.write("\n".join(csv_rows))
UnicodeEncodeError: 'ascii' codec can't encode character '\xb5' in position 64: ordinal not in range(128)

Populate_Metadata.py - opening script dialog gives:

omero.ValidationException: exception ::omero::ValidationException
{
    serverStackTrace = 
    serverExceptionClass = 
    message = Can't find params for 266058!
No stdout.
stderr is in file 266442:
---------------------------------
Traceback (most recent call last):
  File "./script", line 43, in <module>
    from omero_metadata.populate import ParsingContext
  File "/opt/omero/server/venv3/lib64/python3.6/site-packages/omero_metadata/populate.py", line 87
    Report bugs to ome-devel@lists.openmicroscopy.org.uk""" % (error, cmd, cmd)
                                                          ^
SyntaxError: invalid syntax
sbesson commented 4 years ago

From the former issue it looks like we need to specify utf-8 encoding wherever appropriate similarly to https://github.com/ome/omero-py/pull/110. Looking at https://python-future.org/compatible_idioms.html#file-io-with-open, it might be possible to have a unified Py2/Py3 idiom:

from io import open
...
    with open(file_name, 'w', encoding='utf-8') as csv_file:
...

The latter issue is related to the fact the omero-metadata plugins needs to be upgraded to Python 3 - see in-progress work in https://github.com/ome/omero-metadata/pull/36

will-moore commented 4 years ago

There was a workaround in https://github.com/ome/omero-scripts/commit/d9119def3237feefe45b7972e024eb159102d98d to only write encoded bytes to csv, because writing unicode to csv fails on the py3-ci server due to lack of UTF-8 encoding as described https://github.com/ome/omero-figure/pull/343#issuecomment-565426063 and https://github.com/ome/omero-figure/pull/351#issuecomment-565392138