[GRASS-dev] Python handling in winGRASS7 [was: Re: GRASS GIS 7 tech-preview release preparations]
Moritz Lennert
mlennert at club.worldonline.be
Mon Jul 29 07:43:32 PDT 2013
On 27/07/13 20:08, Glynn Clements wrote:
>
> Helmut Kudrnovsky wrote:
>
>> Python Launcher for Windows is a interesting concept for switching between
>> python versions or for pointing to a specific python interpreter.
>>
>> shebang + py.ini seems to work (see tests in the ticket).
>>
>> IIUC, by this concept a WinGrass-python script would have to be invoked by
>> py.exe (Python Launcher for Windows)?
>
> The idea is that you associate the .py extension with py.exe, and it
> figures out which python.exe to use for a given script.
>
>> - could this be integrated in WinGrass?
>
> Maybe, but it has many of the same issues as any other approach which
> affects system-wide configuration.
>
>> - would this help to type only r.xxxx in the WinGrass7-windows-console
>> without the .py-extension to start a grass-python-script?
>
> Invoking scripts without an extension requires that the extension is
> present in PATHEXT.
Just installing the launcher did the trick for me, even though I did not
see anything related to Python in PATHEXT.
>
>> - would this help to call a python-script within a python-script?
>> - would this help for http://trac.osgeo.org/grass/ticket/2015?
>
> The bottom line is that the .py extension has to be associated with a
> Python interpreter, or something which invokes one (e.g. py.exe).
>
> There are multiple valid solutions, and GRASS cannot impose a
> particular one.
But it seems that the launcher is more or less transparent to an
existing python installation, i.e. if the user has Python installed (and
Python is registered in the registry and the relevant path is in PATH),
the launching python on the command line will still call that installed
python and double-clicking on a .py file will still launch the file with
the installed Python. Only if you use specific shebangs or set up an
.ini file, it will call another python. It thus seems the least invasive
way of making GRASS use its embedded python. We can then add to the
documentation that users need to add a specific shebang to their GRASS
python scripts.
Another interesting hint concerning the launcher (from [1]):
"Customised commands allow the launcher to operate as a very flexible
shebang line processor, not limited to launching Python scripts. For
example, you can launch Perl, Ruby or Haskell scripts using the launcher
(as long as the file type associations are set up for the corresponding
.pl, .rb and .hs extensions to point to the launcher, and that the
launcher’s configuration allows it to map perl, ruby and runhaskell
progname values to the paths of the corresponding executables). Of
course, those programs already set the registry up to point to their
launchers: but using the customisability of the Python launcher, you
could (for example) cause ‘perl’ in a shebang line to invoke the Perl
interpreter with useful default arguments such as –w (which enables many
useful warnings and is recommended)."
Moritz
[1]
http://pymolurus.blogspot.be/2012/07/python-launcher-brings-shebang-line.html
More information about the grass-dev
mailing list