grass icon indicating copy to clipboard operation
grass copied to clipboard

grass.script: Use text=True by default for subprocesses

Open wenzeslaus opened this issue 4 months ago • 5 comments

Unlike in the days of Python 2, Popen has now text mode which makes everything just standard (unicode) strings and newlines just LFs. This PR s trying to switch the default from text=False to text=True deep in grass.script in the Popen class wrapper. The idea is that one can still fallback to bytes and encoding/decoding if needed which is approach taken in grass.script.task for XML. All other places should remove the encoding/decoding code. I adjusted crucial places in grass.script, some tested locally on Linux, some not. Changes in grass.script are hopeful in the sense that there should be no impact to the user code. However, some changes are needed in Python tools, suggesting that there is a risk that user code would have to change. This would prevent us from doing this before next major release (v9), but we can likely adjust the grass.script code to allow for both encoded (bytes) and unicode strings (str) as inputs. Our encode and decode utils functions already work as pass-thru when the input type is the desired output type.

I putting this out for discussion and to see how many tests will fail, and I'm especially intersted to see how this turns out on Windows.

wenzeslaus avatar Jun 12 '25 13:06 wenzeslaus