[GRASS-dev] [GRASS GIS] #2708: Run GRASS with Python3
GRASS GIS
trac at osgeo.org
Mon Jul 20 01:33:37 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:1 glynn]:
> Replying to [ticket:2708 zarch]:
>
> > 3) lib/python/script/* => script.diff
>
> These are wrong. You should be converting str to bytes, not the other
way around.
> A child process' argv, environment, stdin/stdout/stderr are all byte
sequences.
> Converting everything to unicode so that Python can convert it back to
bytes under
> the hood is adding needless failure modes.
I agree with you, actually this was my first attempt, but then I have to
face that the string formatting is available for bytes, only on python
3.5, that it is not stable yet. therefore when I call
make_command/run_command I got:
{{{
In [1]: from grass.script import core as gcore
In [2]: gcore.make_command('g.region', raster='elevation', flags='p')
Out[2]: ['g.region', '-p', "raster=b'elevation'"]
In [3]: gcore.run_command('g.region', raster='elevation', flags='p')
WARNING: Illegal filename <b'elevation'>. Character <'> not allowed.
ERROR: Raster map <b'elevation'> not found
---------------------------------------------------------------------------
CalledModuleError Traceback (most recent call
last)
<ipython-input-5-c7b3927bef11> in <module>()
----> 1 gcore.run_command('g.region', raster='elevation', flags='p')
/home/pietro/docdat/src/gis/grass71/dist.x86_64-unknown-linux-
gnu/etc/python/grass/script/core.py in run_command(*args, **kwargs)
403 ps = start_command(*args, **kwargs)
404 returncode = ps.wait()
--> 405 return handle_errors(returncode, returncode, args, kwargs)
406
407
/home/pietro/docdat/src/gis/grass71/dist.x86_64-unknown-linux-
gnu/etc/python/grass/script/core.py in handle_errors(returncode, result,
args, kwargs)
321 args = make_command(*args, **kwargs)
322 raise CalledModuleError(module=None, code=repr(args),
--> 323 returncode=returncode)
324
325 def start_command(prog, flags="", overwrite=False, quiet=False,
CalledModuleError: Module run None ['g.region', '-p',
"raster=b'elevation'"] ended with error
Process ended with non-zero return code 1. See errors in the (error)
output.
In [4]: "%s=%s" % (b'raster', b'elevation')
Out[4]: "b'raster'=b'elevation'"
In [5]: "%s=%s" % (b'raster'.decode(), b'elevation'.decode())
Out[5]: 'raster=elevation'
}}}
Do you have an idea on how we could/should fix this?
--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2708#comment:2>
GRASS GIS <http://grass.osgeo.org>
More information about the grass-dev
mailing list