<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 17, 2017 at 12:36 AM, Pietro <span dir="ltr"><<a href="mailto:peter.zamb@gmail.com" target="_blank">peter.zamb@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div class="gmail_extra"><br><div class="gmail_quote"><span class="gmail-">On Fri, Jul 14, 2017 at 6:00 PM, Vaclav Petras <span dir="ltr"><<a href="mailto:wenzeslaus@gmail.com" target="_blank">wenzeslaus@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>This is exactly what I had in my mind when doing the last major changes in the grass.py file. <br></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">I generally like the layout you suggested. It seems to me that choosing a good name for the whole module will be a bit tricky. </div></blockquote></span><div><br>This is intended as a proof of concept to see the feasibility.<br></div><div>I've try to found a better name but didn't come up to my mind...<br></div><div>Perhaps: <span style="font-family:monospace,monospace">session</span> instead of <span style="font-family:monospace,monospace">init</span>?<br><br></div><div>My final objective is to be able to do something like:<br></div></div></div></div></div></blockquote><div><br></div><div>That makes sense. In fact, that's very similar to a file I drafted some time ago splitting the data initialization and runtime in grass.script.setup and adding Session (see the attached file). Another example, for a different case, is here:<br><br><a href="https://github.com/wenzeslaus/g.remote/blob/master/grasssession.py">https://github.com/wenzeslaus/g.remote/blob/master/grasssession.py</a><br><span style="font-family:monospace,monospace"></span></div><div><span style="font-family:monospace,monospace"><br></span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace"><b># Perhaps in GRASS8 we will be able to skip this! ;-)</b><br></span></div><div><span style="font-family:monospace,monospace">sys.append(os.environ.get('<wbr>GISBASE', '/home/pietro/my/gisbase'))<br></span></div></div></div></div></div></blockquote><div><br></div><div>Added to the list, but how to do it remains unclear (many different discussions in Trac and ML):<br></div><div><br><a href="https://trac.osgeo.org/grass/wiki/Grass8Planning">https://trac.osgeo.org/grass/wiki/Grass8Planning</a><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace">from grass.init import Session<br><br></span></div><div><span style="font-family:monospace,monospace"># open - close mode<br></span></div><div><span style="font-family:monospace,monospace">session = Session('mygisdbase/location/<wbr>mapset')<br></span></div><div><span style="font-family:monospace,monospace">session.open()<br></span></div><div><span style="font-family:monospace,monospace"># do my stuff here...<br></span></div><div><span style="font-family:monospace,monospace">session.close()<br><br></span></div><div><span style="font-family:monospace,monospace"># with statement<br></span></div><div><span style="font-family:monospace,monospace">with Session('mygisdbase/location/<wbr>mapset') as session:<br></span></div><div><span style="font-family:monospace,monospace">    # do my stuff here<br>```</span><br></div><div> <br></div></div></div></div></div></blockquote><div><br></div><div>Unfortunately, here is where the trouble begins. The above leads to the following:<br><br></div><div>with Session as session:<br></div><div>    session.run_command(...)<br><br></div><div>which fits with API which already exists for Ruby:<br><br><a href="https://github.com/jgoizueta/grassgis/">https://github.com/jgoizueta/grassgis/</a><br></div><div>






<p>
GrassGis.session configuration do+<br>    <a href="http://r.info">r.info</a> 'slope'<br>    g.region '-p'<br>
end
</p>



</div><div>The trouble is that session (at least in Python) needs to depend on the rest of the library because it is the interface for the rest (on demand imports may help here).<br><br></div><div>So perhaps having grass.init or grass.setup with the low level functions and then a separate grass.session with a nice interface which may depend on all other modules may be a better way. (Although having each function from the library as a method of Session calls for more thinking about grass.session.Session.</div></div><br></div><div class="gmail_extra">Just to be clear: I definitively think this should be done. I'm just not sure what is the right way.<br><br></div><div class="gmail_extra">Vaclav<br></div></div>