[GRASS-dev] [GRASS GIS] #2133: g.parser does call the form.py with full path

GRASS GIS trac at osgeo.org
Thu Mar 3 19:11:05 PST 2016

#2133: g.parser does call the form.py with full path
  Reporter:  wenzeslaus  |      Owner:  wenzeslaus
      Type:  defect      |     Status:  new
  Priority:  normal      |  Milestone:  7.1.0
 Component:  Parser      |    Version:  svn-trunk
Resolution:              |   Keywords:  parser, forms, wxGUI
       CPU:  All         |   Platform:  All
Changes (by wenzeslaus):

 * owner:  grass-dev@… => wenzeslaus
 * keywords:  parser => parser, forms, wxGUI
 * milestone:  7.0.0 => 7.1.0


 This is still an issue. Custom Python scripts using
 `grass.script.parser()` won't open a GUI from the command line. You will
 get (tested on a copy of t.list, i.e. something on "on PATH"):

 Unable to fetch interface description for command 't.list2'.

 Details: [Errno 2] No such file or directory

 Try to set up GRASS_ADDON_PATH or GRASS_ADDON_BASE variable.

 But there is no reason for modifying any path variables, you provided full
 (or relative) path, so this should be enough. In GUI Console, you will get
 the GUI dialog/form but running the module will show a run in the dialog's
 Command output tab but `[Errno 2] No such file or directory` in the main
 GUI's Console (I'm not sure what is the exact mechanism in GUI).

 Removing the `G_basename` calls and directory stripping from
 `G_set_program_name()` makes it work both in command line and the GUI.

 Index: lib/gis/parser.c
 --- lib/gis/parser.c    (revision 67989)
 +++ lib/gis/parser.c    (working copy)
 @@ -340,8 +340,6 @@
 -    G_basename(tmp_name, "exe");
 -    st->pgm_name = tmp_name;
 Index: lib/gis/progrm_nme.c
 --- lib/gis/progrm_nme.c        (revision 67989)
 +++ lib/gis/progrm_nme.c        (working copy)
 @@ -44,18 +44,8 @@
 -    i = strlen(s);
 -    while (--i >= 0) {
 -       if (G_is_dirsep(s[i])) {
 -           s += i + 1;
 -           break;
 -       }
 -    }
      /* strip extension from program name */
 -    temp = G_store(s);
 -    G_basename(temp, "exe");
 -    G_basename(temp, "py");
      name = G_store(s);

 Extensions are probably present on MS Windows and we don't want them in
 history (r21674, r62904). But I have no idea why we are stripping the
 directories (blame goes to r9499).

 Is there a occasion when modules are called with full path? Maybe MS
 Windows e.g., without `shell=True` in Python? Or can we just preserve path
 when it is present and leave the extension there as well? (Resulting in
 `G_program_name()` returning whatever was there, putting it into history
 and passing it to GUI.)

 Alternatively, we can add another function which will return the
 originally used path and will be used in `module_gui_wx()` (in `parser.c`)
 instead of `G_program_name()`. This will leave the history behavior intact
 (you will get stripped name although you provided a full path) but the GUI
 will get the full (or relative) path needed to run the script to obtain
 the interface and execute script later.

Ticket URL: <https://trac.osgeo.org/grass/ticket/2133#comment:3>
GRASS GIS <https://grass.osgeo.org>

More information about the grass-dev mailing list