[GRASS-dev] [GRASS GIS] #2708: Run GRASS with Python3

GRASS GIS trac at osgeo.org
Wed Jul 22 00:34:14 PDT 2015


#2708: Run GRASS with Python3
--------------------------+-------------------------
  Reporter:  zarch        |      Owner:  grass-dev@…
      Type:  defect       |     Status:  new
  Priority:  normal       |  Milestone:  7.0.1
 Component:  Default      |    Version:  unspecified
Resolution:               |   Keywords:
       CPU:  Unspecified  |   Platform:  Unspecified
--------------------------+-------------------------

Comment (by zarch):

 Replying to [comment:3 glynn]:
 > {{{
 > args.append(opt.encode('ascii') + b'=' + _make_val(val)
 > }}}
 >
 > To be honest, converting grass.script to Python 3 isn't going to be much
 fun,
 > as a scripting library fundamentally revolves around dealing with byte
 > strings (command-line arguments, environment variables, stdin/stdout),
 > while Python 3 tries to pretend that byte strings are some kind of low-
 level
 > implementation detail in a world where everything is Unicode.

 ok, I've followed your approach, now the make_command it is working only
 with bytes and return a list of bytes.
 Do you think that I could commit these changes in trunk? Other things that
 should be change before?

 I've also started fixing several GRASS scripts to be parsed also with
 python3.

 However I don't know how to fix the ctypes binding of GRASS, at the moment
 I get:

 {{{
 In [1]: from grass.lib import gis
 ---------------------------------------------------------------------------
 ImportError                               Traceback (most recent call
 last)
 <ipython-input-1-9c20dc5e4f67> in <module>()
 ----> 1 from grass.lib import gis

 /home/pietro/docdat/src/gis/grass71/dist.x86_64-unknown-linux-
 gnu/etc/python/grass/lib/gis.py in <module>()
      13 _libdirs = []
      14
 ---> 15 from ctypes_preamble import *
      16 from ctypes_preamble import _variadic_function
      17 from ctypes_loader import *

 ImportError: No module named 'ctypes_preamble'
 }}}

 the problem here is that the gis.py file should start with:

 {{{
 from __future__ import absolute_import

 ...

 from .ctypes_preamble import *
 from .ctypes_preamble import _variadic_function
 from .ctypes_loader import *

 }}}

 But these files are generated with make and I don't understand where
 should I change the code. Any hint?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2708#comment:4>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list