[GRASS-dev] [GRASS-SVN] r61051 - grass/trunk/lib/init

Martin,

Please explain why we need this change. It breaks custom PS1 and aliases in $HOME/.grass7/bashrc.

Thank you.
Huidae

···

On Sun, Jun 29, 2014 at 6:22 AM, <svn_grass@osgeo.org> wrote:

Author: martinl
Date: 2014-06-29 03:22:23 -0700 (Sun, 29 Jun 2014)
New Revision: 61051

Modified:
grass/trunk/lib/init/grass.py
Log:
grass.py: do not override already set GRASS environmental variables

Modified: grass/trunk/lib/init/grass.py

— grass/trunk/lib/init/grass.py 2014-06-29 10:07:13 UTC (rev 61050)
+++ grass/trunk/lib/init/grass.py 2014-06-29 10:22:23 UTC (rev 61051)
@@ -746,7 +746,17 @@
k, v = map(lambda x: x.strip(), line.strip().split(’ ‘, 1)[1].split(’=', 1))
except:
continue

  • os.environ[k] = v
  • evalue = os.getenv(k)
  • if evalue:
  • if k == ‘GRASS_ADDON_PATH’:
  • os.environ[k] = evalue + os.pathsep + v
  • else:
  • warning(_(“Environmental variable ‘%s’ already set, ignoring value ‘%s’”) % \
  • (k, v))
  • else:
  • os.environ[k] = v

Allow for mixed ISIS-GRASS Environment

if os.getenv(‘ISISROOT’):
isis = os.getenv(‘ISISROOT’)
@@ -1131,8 +1141,14 @@
path = os.path.join(userhome, “.grass.bashrc”) # left for backward compatibility
if os.access(path, os.R_OK):
f.write(readfile(path) + ‘\n’)

  • if os.access(grass_env_file, os.R_OK):
  • f.write(readfile(grass_env_file) + ‘\n’)
  • for env in os.environ.keys():
  • if env.startswith(‘GRASS’):
  • val = os.environ[env]
  • if ’ ’ in val:
  • val = ‘“%s”’ % val
  • f.write(‘export %s=%s\n’ % (env, val))
  • if os.access(grass_env_file, os.R_OK):

  • f.write(readfile(grass_env_file) + ‘\n’)

f.write(“export PATH="%s"\n” % os.getenv(‘PATH’))
f.write(“export HOME="%s"\n” % userhome) # restore user home path


grass-commit mailing list
grass-commit@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-commit

Also, csh_startup() still overrides already set environment variables.

if os.access(grass_env_file, os.R_OK):
f.write(readfile(grass_env_file) + ‘\n’)

So we have $LOCATION/.bashrc, ~/.grass7/bashrc, and ~/.grass.bashrc. Do they all have different purposes and are they documented clearly somewhere?

···

On Fri, Jul 4, 2014 at 3:02 PM, Huidae Cho <grass4u@gmail.com> wrote:

Martin,

Please explain why we need this change. It breaks custom PS1 and aliases in $HOME/.grass7/bashrc.

Thank you.

Huidae

On Sun, Jun 29, 2014 at 6:22 AM, <svn_grass@osgeo.org> wrote:

Author: martinl
Date: 2014-06-29 03:22:23 -0700 (Sun, 29 Jun 2014)
New Revision: 61051

Modified:
grass/trunk/lib/init/grass.py
Log:
grass.py: do not override already set GRASS environmental variables

Modified: grass/trunk/lib/init/grass.py

— grass/trunk/lib/init/grass.py 2014-06-29 10:07:13 UTC (rev 61050)
+++ grass/trunk/lib/init/grass.py 2014-06-29 10:22:23 UTC (rev 61051)
@@ -746,7 +746,17 @@
k, v = map(lambda x: x.strip(), line.strip().split(’ ‘, 1)[1].split(’=', 1))
except:
continue

  • os.environ[k] = v
  • evalue = os.getenv(k)
  • if evalue:
  • if k == ‘GRASS_ADDON_PATH’:
  • os.environ[k] = evalue + os.pathsep + v
  • else:
  • warning(_(“Environmental variable ‘%s’ already set, ignoring value ‘%s’”) % \
  • (k, v))
  • else:
  • os.environ[k] = v

Allow for mixed ISIS-GRASS Environment

if os.getenv(‘ISISROOT’):
isis = os.getenv(‘ISISROOT’)
@@ -1131,8 +1141,14 @@
path = os.path.join(userhome, “.grass.bashrc”) # left for backward compatibility
if os.access(path, os.R_OK):
f.write(readfile(path) + ‘\n’)

  • if os.access(grass_env_file, os.R_OK):
  • f.write(readfile(grass_env_file) + ‘\n’)
  • for env in os.environ.keys():
  • if env.startswith(‘GRASS’):
  • val = os.environ[env]
  • if ’ ’ in val:
  • val = ‘“%s”’ % val
  • f.write(‘export %s=%s\n’ % (env, val))
  • if os.access(grass_env_file, os.R_OK):

  • f.write(readfile(grass_env_file) + ‘\n’)

f.write(“export PATH="%s"\n” % os.getenv(‘PATH’))
f.write(“export HOME="%s"\n” % userhome) # restore user home path


grass-commit mailing list
grass-commit@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-commit

Hi,

2014-07-04 21:02 GMT+02:00 Huidae Cho <grass4u@gmail.com>:

Please explain why we need this change. It breaks custom PS1 and aliases in
$HOME/.grass7/bashrc.

sorry for late answer, the original reason was:

1) you have defined GRASS_ADDON_PATH in $HOME/.grass7/bashrc
2) you launch GRASS with $ GRASS_ADDON_PATH=~/bin/md-iso grass71

GRASS_ADDON_PATH points just to the path from `$HOME/.grass7/bashrc`.
The patch enables to merge paths from $HOME/.grass7/bashrc together
with `~/bin/md-iso`. I was not aware of aliases, you are absolutely
right, I will fix it ASAP. Martin

--
Martin Landa * http://geo.fsv.cvut.cz/gwiki/Landa

Hi,

2014-07-04 21:07 GMT+02:00 Huidae Cho <grass4u@gmail.com>:

So we have $LOCATION/.bashrc, ~/.grass7/bashrc, and ~/.grass.bashrc. Do they
all have different purposes and are they documented clearly somewhere?

`.grass.bashrc` is related to GRASS 6. GRASS 7 stores environmental
variables in `~/.grass7/bashrc`. The init script in GRASS 7 also reads
`.grass.bashrc` for backward compatibility. Martin

--
Martin Landa * http://geo.fsv.cvut.cz/gwiki/Landa

2014-07-04 21:02 GMT+02:00 Huidae Cho <grass4u@gmail.com>:

Please explain why we need this change. It breaks custom PS1 and aliases in
$HOME/.grass7/bashrc.

hopefully fixed in r61216. Martin

--
Martin Landa * http://geo.fsv.cvut.cz/gwiki/Landa

Hi,

If that’s the only reason for this change, I would keep the previous version and let the user decide where to append GRASS_ADDON_PATH in ~/.grass7/bashrc.

  1. It’s breaking “export NEW_VAR=$HOME/grassdata” because $HOME doesn’t get expanded by bash.

  2. It’s inconsistent to append (“keep”) GRASS_ADDON_PATH and ignore other environment variables in ~/.grass7/bashrc.

  3. We should “not” simply ignore any environment variables in ~/.grass7/bashrc even if they already exist outside a GRASS session.

  4. grass.py is appending GRASS_ADDON_PATH in ~/.grass7/bashrc only “after” existing GRASS_ADDON_PATH. What if they want to append their path “before” the one in ~/.grass7/bashrc?

As to my original concern, even r61216 doesn’t allow overwriting PS1 initially created by grass.py. As a side effect of startswith(‘export’), I can work around it by appending whitespaces before export PS1=, but I would say that’s a bug, not a feature.

Anyway, my point is we can address the original issue by adding the following line in ~/.grass7/bashrc:

export GRASS_ADDON_PATH=“$GRASS_ADDON_PATH:~/grass-addon/bin”

This is more flexible and doesn’t impose “appending” of GRASS_ADDON_PATH and ignoring other variables in ~/.grass7/bashrc. In fact, like I said above in 1, the new version “breaks” this feature:

export NEW_VAR=$HOME/grassdata

doesn’t expand to /home/user/grassdata.

IMHO, it should be the user’s responsibility and rights to overwrite or not overwrite anything available outside a GRASS session and that should happen in ~/.grass7/bashrc.

Best,
Huidae

···

On Wed, Jul 9, 2014 at 7:44 AM, Martin Landa <landa.martin@gmail.com> wrote:

Hi,

2014-07-04 21:02 GMT+02:00 Huidae Cho <grass4u@gmail.com>:

Please explain why we need this change. It breaks custom PS1 and aliases in
$HOME/.grass7/bashrc.

sorry for late answer, the original reason was:

  1. you have defined GRASS_ADDON_PATH in $HOME/.grass7/bashrc
  2. you launch GRASS with $ GRASS_ADDON_PATH=~/bin/md-iso grass71

GRASS_ADDON_PATH points just to the path from $HOME/.grass7/bashrc.
The patch enables to merge paths from $HOME/.grass7/bashrc together
with ~/bin/md-iso. I was not aware of aliases, you are absolutely
right, I will fix it ASAP. Martin


Martin Landa * http://geo.fsv.cvut.cz/gwiki/Landa

On Wed, Jul 9, 2014 at 11:44 AM, Huidae Cho <grass4u@gmail.com> wrote:

Anyway, my point is we can address the original issue by adding the
following line in ~/.grass7/bashrc:

export GRASS_ADDON_PATH="$GRASS_ADDON_PATH:~/grass-addon/bin"

I'm not following the discussion but this is the way how to work with

"PATH" variables. There is some equivalent in Python, I believe, with some
"path sep".

This is more flexible and doesn't impose "appending" of GRASS_ADDON_PATH
and ignoring other variables in ~/.grass7/bashrc. In fact, like I said
above in 1, the new version "breaks" this feature:

export NEW_VAR=$HOME/grassdata

doesn't expand to /home/user/grassdata.

IMHO, it should be the user's responsibility and rights to overwrite or
not overwrite anything available outside a GRASS session and that should
happen in ~/.grass7/bashrc.

I'm not sure if this is related but note that bash aliases and perhaps some
other things are not available in GRASS session and it is not considered as
an issue.

[GRASS-dev] Bash aliases in GRASS
http://lists.osgeo.org/pipermail/grass-dev/2013-February/061837.html
http://osgeo-org.1560.x6.nabble.com/Bash-aliases-in-GRASS-td5032707.html

[GRASS-user] loss of bash aliases
http://lists.osgeo.org/pipermail/grass-user/2008-March/043806.html

Hi,

2014-07-09 17:44 GMT+02:00 Huidae Cho <grass4u@gmail.com>:

If that's the only reason for this change, I would keep the previous version
and let the user decide where to append GRASS_ADDON_PATH in
~/.grass7/bashrc.

you are probably right, reverted in r61273. Martin

--
Martin Landa * http://geo.fsv.cvut.cz/gwiki/Landa