[GRASS-dev] pygrass v.import_() strange error

Hi,
(script below)

I get this error

v.import_(input=adminfile,output=“admin”,quiet=True,superquiet=True)
File “/usr/lib/grass74/etc/python/grass/pygrass/modules/shortcuts.py”, line 47, in getattr
return self.cls(‘%s.%s’ % (self.prefix, name.replace(‘_’, ‘.’)))
File “/usr/lib/grass74/etc/python/grass/pygrass/modules/interface/module.py”, line 530, in init
raise GrassError(str_err % self.name)
grass.exceptions.GrassError: Error running: v.import. --interface-description.

#SCRIPT

from grass_session import Session
from grass.pygrass.modules.shortcuts import vector as v
adminfile=gadm_FR_2_Morbihan.gpkg
with Session(gisdb=“/tmp”, location=“loc”, create_opts=“EPSG:4326”):
v.import_(input=adminfile,output=“admin”,quiet=True,superquiet=True)

* Yann Chemin <dr.yann.chemin@gmail.com> [2018-07-25 09:34:32 +0200]:

Hi,
(script below)
I get this error

v.import_(input=adminfile,output="admin",quiet=True,superquiet=True)
File "/usr/lib/grass74/etc/python/grass/pygrass/modules/shortcuts.py",
line 47, in __getattr__
   return self.cls('%s.%s' % (self.prefix, name.replace('_', '.')))
File
"/usr/lib/grass74/etc/python/grass/pygrass/modules/interface/module.py",
line 530, in __init__
   raise GrassError(str_err % self.name)
grass.exceptions.GrassError: Error running: `v.import.
--interface-description`.

#SCRIPT
from grass_session import Session
from grass.pygrass.modules.shortcuts import vector as v
adminfile=gadm_FR_2_Morbihan.gpkg
with Session(gisdb="/tmp", location="loc", create_opts="EPSG:4326"):
    v.import_(input=adminfile,output="admin",quiet=True,superquiet=True)

Yann,

does the "typical"

grass.run_command('v.import', input=adminfile, output="admin", quiet=True, superquiet=True)

work?

Nikos

On Wed, Jul 25, 2018, 3:34 AM Yann Chemin <dr.yann.chemin@gmail.com> wrote:

Hi,
(script below)

I get this error

v.import_(input=adminfile,output=“admin”,quiet=True,superquiet=True)
File “/usr/lib/grass74/etc/python/grass/pygrass/modules/shortcuts.py”, line 47, in getattr
return self.cls(‘%s.%s’ % (self.prefix, name.replace(‘_’, ‘.’)))
File “/usr/lib/grass74/etc/python/grass/pygrass/modules/interface/module.py”, line 530, in init
raise GrassError(str_err % self.name)
grass.exceptions.GrassError: Error running: v.import. --interface-description.

It seems that PyGRASS does not support the “underscore at the end when Python keyword”. It just does it’s usual thing which is replacing underscores with dots like in r.slope_aspect. So probably a new functionality needs to be added to replace import_ with just import. Something like name.strip(‘_’). Please add a test for it.

Best,
Vaclav

#SCRIPT

from grass_session import Session
from grass.pygrass.modules.shortcuts import vector as v
adminfile=gadm_FR_2_Morbihan.gpkg
with Session(gisdb=“/tmp”, location=“loc”, create_opts=“EPSG:4326”):
v.import_(input=adminfile,output=“admin”,quiet=True,superquiet=True)


grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev

Hi Yann,

···

On Wed, Jul 25, 2018 at 9:34 AM, Yann Chemin <dr.yann.chemin@gmail.com> wrote:

v.import_(input=adminfile,output=“admin”,quiet=True,superquiet=True)

Why are you interested to execute “v.import_(” instead of “v.import(”, what is it the purpose of this extra underscore in this case?
It is quite easy to fix this issue but actually I’m not conviced should be fixed.

Best regards

Pietro

On Wed, Aug 1, 2018 at 11:03 AM, Pietro <peter.zamb@gmail.com> wrote:

Hi Yann,

On Wed, Jul 25, 2018 at 9:34 AM, Yann Chemin <dr.yann.chemin@gmail.com>
wrote:

v.import_(input=adminfile,output="admin",quiet=True,superquiet=True)

Why are you interested to execute "v.import_(" instead of "v.import(",
what is it the purpose of this extra underscore in this case?
It is quite easy to fix this issue but actually I'm not conviced should be
fixed.

I think Yann is using shortcuts, not execution by providing module name as
a string, so than "import" is really a keyword:

a = 1
a.real

1

a.xxx

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'xxx'

a.import()

  File "<stdin>", line 1
    a.import()
           ^
SyntaxError: invalid syntax

Yes I used shortcuts, the Python keyword replacement is forcing pyGRASS to make v.import_ instead of v.import. However the same “" scheme is also a replacement of triple dot separated grass modules 9i.e. r.out.gdal=> r.out_gdal) and the replacement scheme in running modules assumes that "” has to be replaced by a “.” … Thus the error ideed

yes this is the problem indeed

On Wed, 25 Jul 2018 at 13:21, Vaclav Petras <wenzeslaus@gmail.com> wrote:

On Wed, Jul 25, 2018, 3:34 AM Yann Chemin <dr.yann.chemin@gmail.com> wrote:

Hi,
(script below)

I get this error

v.import_(input=adminfile,output=“admin”,quiet=True,superquiet=True)
File “/usr/lib/grass74/etc/python/grass/pygrass/modules/shortcuts.py”, line 47, in getattr
return self.cls(‘%s.%s’ % (self.prefix, name.replace(‘_’, ‘.’)))
File “/usr/lib/grass74/etc/python/grass/pygrass/modules/interface/module.py”, line 530, in init
raise GrassError(str_err % self.name)
grass.exceptions.GrassError: Error running: v.import. --interface-description.

It seems that PyGRASS does not support the “underscore at the end when Python keyword”. It just does it’s usual thing which is replacing underscores with dots like in r.slope_aspect. So probably a new functionality needs to be added to replace import_ with just import. Something like name.strip(‘_’). Please add a test for it.

Best,
Vaclav

#SCRIPT

from grass_session import Session
from grass.pygrass.modules.shortcuts import vector as v
adminfile=gadm_FR_2_Morbihan.gpkg
with Session(gisdb=“/tmp”, location=“loc”, create_opts=“EPSG:4326”):
v.import_(input=adminfile,output=“admin”,quiet=True,superquiet=True)


grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev

yes in the meantime I am running it with parse_command I believe

#code######################################################

from grass_session import Session
from grass.script import core as gcore
#from grass.pygrass.modules.shortcuts import vector as v

with Session(gisdb=“/tmp”, location=“loc”, create_opts=“EPSG:4326”):
#v.import_(input=adminfile,output=“admin”,quiet=True,superquiet=True)
gcore.parse_command(“v.import”,input=adminfile,output=“admin”,quiet=True)

On Wed, 25 Jul 2018 at 11:05, Nikos Alexandris <nik@nikosalexandris.net> wrote:

Hi,
(script below)
I get this error

v.import_(input=adminfile,output=“admin”,quiet=True,superquiet=True)
File “/usr/lib/grass74/etc/python/grass/pygrass/modules/shortcuts.py”,
line 47, in getattr
return self.cls(‘%s.%s’ % (self.prefix, name.replace(‘_’, ‘.’)))
File
“/usr/lib/grass74/etc/python/grass/pygrass/modules/interface/module.py”,
line 530, in init
raise GrassError(str_err % self.name)
grass.exceptions.GrassError: Error running: v.import. --interface-description.

#SCRIPT
from grass_session import Session
from grass.pygrass.modules.shortcuts import vector as v
adminfile=gadm_FR_2_Morbihan.gpkg
with Session(gisdb=“/tmp”, location=“loc”, create_opts=“EPSG:4326”):
v.import_(input=adminfile,output=“admin”,quiet=True,superquiet=True)

Yann,

does the “typical”

grass.run_command(‘v.import’, input=adminfile, output=“admin”, quiet=True, superquiet=True)

work?

Nikos

Thank you Yann and Vaclav, I was not aware of this issue:

···

On Thu, Aug 2, 2018 at 5:06 AM, Vaclav Petras <wenzeslaus@gmail.com> wrote:

I’ve fixed the the code to support the use of underscore for python reserved words and add two doctests in r73029.

Best regards

pietro

a.import()
File “”, line 1
a.import()
^
SyntaxError: invalid syntax

Great, thanks a lot Pietro !

···

On Thu, Aug 2, 2018 at 5:06 AM, Vaclav Petras <wenzeslaus@gmail.com> wrote:

I’ve fixed the the code to support the use of underscore for python reserved words and add two doctests in r73029.

Best regards

pietro

a.import()
File “”, line 1
a.import()
^
SyntaxError: invalid syntax

On Fri, Aug 3, 2018 at 7:55 AM, Pietro <peter.zamb@gmail.com> wrote:

Thank you Yann and Vaclav, I was not aware of this issue:

On Thu, Aug 2, 2018 at 5:06 AM, Vaclav Petras <wenzeslaus@gmail.com> wrote:

>>> a.import()
  File "<stdin>", line 1
    a.import()
           ^
SyntaxError: invalid syntax

I've fixed the the code to support the use of underscore for python reserved
words and add two doctests in r73029.

Great, thanks! Any objections to backport this?

Markus