Try2Code / cdo-bindings

Ruby/Python bindings for CDO

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getOperators() doesn't work with Python from within Cygwin on Windows

andreas-h opened this issue · comments

For Windows there are Cygwin64 CDO binaries available. When trying to use these I have the problem that the getOperators() function doesn't work properly. The culprit seems to be that the output of cdo --operators is being split at os.linesep (see, e.g., https://github.com/Try2Code/cdo-bindings/blob/master/python/cdo.py#L305). However, os.linesep on Windows is \r\n, while the output of the cdo --operators call is only separated by \n.

I guess it should be possible to use something like (pseudo-code)

if on_cygwin:
    cdosep = '\n'
else:
    cdosep = os.linesep

and then use cdosep instead of os.linesep.

Would you be open to a PR implementing this?

Hi!
I (hopefully) fixed this with the latest release 1.3.4? Could you give it a try?

thx in advance

Thanks for your quick reply! I Installed the 1.3.4 package from Anaconda (btw, the cdo.py still reads 1.3.3), but it doesn't work properly:

In [1]: from cdo import Cdo
Could not load xarray
In [2]: cdo = Cdo()
In [3]: cdo.operators
Out[3]: ['abs']
In [4]: cdo.__version__()
Out[4]: '1.3.3'
In [5]: cdo.version()
Out[5]: '1.8.2'

The same is true for the 1.9.0 binary.

Ah, now I see. I though you would use the latest release, which has other problems concerning the operator listing.

I guess, the problem does not occur if you hard-code the separator to '\n'. the listing given by CDO itself does not make use of '\r\n' at all. I think the use of 'os.linesep' might have been a really bad type of optimization.
I do not check on cygwin regularly - so it would be nice you could test it for me ;-)

Some recent testing of the current release 1.4.0 did not reveal this behavior - so I think the ticket can be closed. @andreas-h