grass-svn2git / grass-issues-test

0 stars 0 forks source link

Porting Python Scripting Library to Python 3 #30

Open grass-svn2git opened 5 years ago

grass-svn2git commented 5 years ago

Reported by @petrasovaa on 22 May 2018 01:02 UTC This ticket is created to gather comments and patches to port this library to Python 3 as part of GSoC 2018.

Related pages:

https://trac.osgeo.org/grass/wiki/Python3Support trac wiki page on Python3 porting

https://trac.osgeo.org/grass/wiki/GSoC/2018/FullSupportPython3 GSoC 2018

GRASS GIS version and provenance

svn-trunk

Migrated-From: https://trac.osgeo.org/grass/ticket/3565

grass-svn2git commented 5 years ago

Attachment from @petrasovaa on 22 May 2018 01:05 UTC patch for lib/python/script/utils.py and tests by Sanjeet https://trac.osgeo.org/grass/attachment/ticket/3565/patch_utils_sanjeet.diff

grass-svn2git commented 5 years ago

Attachment from @petrasovaa on 22 May 2018 01:11 UTC encode and decode functions changed to accept only text, otherwise throw error https://trac.osgeo.org/grass/attachment/ticket/3565/patch_utils_encode_decode_only_text.diff

grass-svn2git commented 5 years ago

Attachment from sanjeet on 23 May 2018 05:42 UTC Hi, Here is a quick dirty patch to know if this is what you meant when you said we need to have 'encoding' parameter passed to our functions. For now, I have only added this conversion in the 'run_command()'. I am just using the encoding parameter directly from kwargs instead of passing it as a keyword argument in the functions definiton. It is being popped from the kwargs dictionary so as not to pass it to the next function in line. I thought, in the similar manner we could call the 'make_unicode()' in other functions (read_command, make_command, start_command,...) where they can make use of it if they are called directly from the scripts instead of other functions. Is this correct? https://trac.osgeo.org/grass/attachment/ticket/3565/patch_core_run_command_unicode.diff

grass-svn2git commented 5 years ago

Comment by @petrasovaa on 22 May 2018 01:18 UTC I changed Sanjeet's patch to change the behavior of encode and decode functions in utils.py, so that they don't accept anything else than string or bytes with Python3. Before they could be used with int, floats and None, but it's supposed to do encoding/decoding not converting, that should be done explicitly. To not break existing code, new behavior is only with Python 3.

grass-svn2git commented 5 years ago

Comment by @petrasovaa on 23 May 2018 20:56 UTC Actually what I meant is using the encoding parameter only for stdin, stderr and stdout, the same way as https://docs.python.org/3.6/library/subprocess.html#subprocess.Popen Python Popen class. The arguments are already being encoded in start_command function. BTW, if you submit a patch, it should somehow work, I can see just by looking at it that it can't work. Or call it pseudocode in that case.