[GRASS-dev] grass and python

Glynn Clements glynn at gclements.plus.com
Sat Aug 12 20:08:58 EDT 2006


William Kyngesburye wrote:

> > It is quite possible to initialize and run grass without Bash. I  
> > have a simi-working python script that fires up GRASS using IPython  
> > as it's shell. In fact, since Python abstracts os calls such as  
> > creating temp files, setting environment variables, etc, it is  
> > actually much easier to write a cross-platform initialization  
> > script in Python than in Bash. HOWEVER (and this is big), if you do  
> > not have a traditional unix shell running grass, none of the nearly  
> > 100 or so scripts that are distributed with GRASS---and that depend  
> > on bash---will work.
> 
> But, as long as the Python app sets up and maintains that shell  
> environment, shouldn't the shell scripts work, if run from the Python  
> environment? something like (pardon, just getting started with python):

I think that he was suggesting eliminating the need for a Bourne shell
(e.g. bash) altogether. Running Bourne-shell scripts from Python is
entirely feasible, provided that you actually have a Bourne shell
interpreter to run them with.

> > Many standard GRASS commands are really shell scripts. Every single  
> > one of them will need to be ported to your new shell if this isn't  
> > compatible with Bash. I stopped working on this when I realized how  
> > disruptive this was going to be (and how unlikely this would be  
> > supported by the core GRASS community). I don't think the vast  
> > majority of GRASS developers want to move to a Python environment  
> > (or Ruby or Perl or cmd.exe, etc). So, basically, this is an idea  
> > dead-on-arrival. It would amount to a fork of GRASS and new users  
> > would have a terrible time figuring out which shell they were  
> > supposed to be using for each script.
> >
> > I think that GRASS is intimately tied to a Posix-compliant shell.  
> > There needs to be a standard macro-language for scripting and Bash  
> > seems as good as any.
> 
> Coming from a more object-oriented programming perspective, I find  
> unix shell scripting to be a nightmare.
> 
> If the wxpython GUI takes off as the main GRASS GUI, there will  
> probably be less resistance to moving to Python for all or most GRASS  
> scripting.

The main issue there is that scripting and interactive command-line
use are very different. Shells (Bourne shell, csh) were designed
primarily for interactive use, and tend to suck as programming
languages. OTOH, Python (and Perl etc) are decent programming
languages but aren't necessarily suitable as interactive shells.

Re-writing scripts in e.g. Python is fine, so long as it can be done
in such a way that the scripts can be run from an interactive shell. 
This is where Windows becomes problematic, due to its lack of support
for extension-less scripts. Windows ports of bash usually get around
this by having the shell itself identify scripts and process the #! 
syntax.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list