[GRASS-dev] does GRASS need HOME to be defined?

as a follow up of:

https://lists.osgeo.org/pipermail/grass-dev/2016-November/083125.html

[snip]

what happens if we don't set it in grass.py? I can't try now.

tested in winGRASS7.0.5 by commenting out following line:

# set HOME
#if windows and not os.getenv('HOME'):
# os.environ['HOME'] = os.path.join(os.getenv('HOMEDRIVE'),
# os.getenv('HOMEPATH'))

in C:\Program Files\GRASS GIS 7.0.5\etc\grass70.py

the wxGUI starts, displaying raster and vector works, tested some
modules,
all worked.

but no idea if there may be some more side effect; further no idea if
there
is probably more to do for the OSGeo4W-version.

anyone more insight, if %HOME% is needed in winGRASS?

Done by Glynn in:
https://trac.osgeo.org/grass/changeset/37873

does GRASS need HOME to be defined?

any hints?

-----
best regards
Helmut
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/does-GRASS-need-HOME-to-be-defined-tp5296669.html
Sent from the Grass - Dev mailing list archive at Nabble.com.

Helmut Kudrnovsky wrote:

>> anyone more insight, if %HOME% is needed in winGRASS?
>
>Done by Glynn in:
>https://trac.osgeo.org/grass/changeset/37873

does GRASS need HOME to be defined?

any hints?

It's used G__home() on Unix (and as a fallback on Windows) and it's
used for G_rc_path() on Windows (for some reason, the Unix version
uses getpwuid(), which is probably incorrect in this context).

It may also be used implicitly by library functions or external
programs looking for configuration files.

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

Glynn Clements wrote

Helmut Kudrnovsky wrote:

>> anyone more insight, if %HOME% is needed in winGRASS?
>
>Done by Glynn in:
>https://trac.osgeo.org/grass/changeset/37873

does GRASS need HOME to be defined?

any hints?

It's used G__home() on Unix (and as a fallback on Windows) and it's
used for G_rc_path() on Windows (for some reason, the Unix version
uses getpwuid(), which is probably incorrect in this context).

It may also be used implicitly by library functions or external
programs looking for configuration files.

thanks for the insight.

a quick look into the trunk source:

D:\software_source\grass_trunk\lib\init\grass.py

def get_grass_config_dir():
    """Get configuration directory

    Determines path of GRASS GIS user configuration directory and creates
    it if it does not exist.

    Configuration directory is for example used for grass env file
    (the one which caries mapset settings from session to session).
    """
    if sys.platform == 'win32':
        grass_config_dirname = "GRASS7"
        win_conf_path = os.getenv('APPDATA')
        # this can happen with some strange settings
        if not win_conf_path:
            fatal(_("The APPDATA variable is not set, ask your operating"
                    " system support"))
        if not os.path.exists(win_conf_path):
            fatal(_("The APPDATA variable points to directory which does"
                    " not exist, ask your operating system support"))
        directory = os.path.join(win_conf_path, grass_config_dirname)
    else:
        grass_config_dirname = ".grass7"
        directory = os.path.join(os.getenv('HOME'), grass_config_dirname)
    if not os.path.exists(directory):
        os.mkdir(directory)
    return directory

def ensure_home():
    """Set HOME if not set on MS Windows"""
    if windows and not os.getenv('HOME'):
        os.environ['HOME'] = os.path.join(os.getenv('HOMEDRIVE'),
                                          os.getenv('HOMEPATH'))

regarding windows, the configuration directory is defined by the %APPDATA%
variable; HOME is defined by %HOMEDRIVE% and %HOMEPATH%.

it expands to:

import os
os.getenv('HOME')

'C:\\Users\\yourusername'

os.getenv('APPDATA')

'C:\\Users\\yourusername\\AppData\\Roaming'

would it harm if %HOME% would be extended from _C:\Users\yourusername\_ to
_C:\Users\yourusername\Documents_ in windows?

as mentioned in
https://lists.osgeo.org/pipermail/grass-dev/2016-November/083122.html: the
winGRASS defined %HOME% (C:\Users\yourusername\) interferes with HOME as it
is expected by R (i.e. C:\Users\yourusername\Documents).

-----
best regards
Helmut
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/does-GRASS-need-HOME-to-be-defined-tp5296669p5297176.html
Sent from the Grass - Dev mailing list archive at Nabble.com.

Helmut Kudrnovsky wrote:

regarding windows, the configuration directory is defined by the %APPDATA%
variable; HOME is defined by %HOMEDRIVE% and %HOMEPATH%.

it expands to:

>>> import os
>>> os.getenv('HOME')
'C:\\Users\\yourusername'
>>> os.getenv('APPDATA')
'C:\\Users\\yourusername\\AppData\\Roaming'

would it harm if %HOME% would be extended from _C:\Users\yourusername\_ to
_C:\Users\yourusername\Documents_ in windows?

Note that:

1. %HOMEPATH% isn't guaranteed to be Users\<username>.

2. The preferred way of referencing that directory is %USERPROFILE%.

3. While %USERPROFILE%\Documents is created automatically, that isn't
guaranteed to be the location of the user's "My Documents" folder (it
can be changed, and in networked environments is typically located on
a file server).

FWIW, the "My Documents" location can be obtained by querying the
registry key

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal

then expanding the result; the default value is "%USERPROFILE\Documents".

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

Glynn Clements wrote

Helmut Kudrnovsky wrote:

regarding windows, the configuration directory is defined by the
%APPDATA%
variable; HOME is defined by %HOMEDRIVE% and %HOMEPATH%.

it expands to:

>>> import os
>>> os.getenv('HOME')
'C:\\Users\\yourusername'
>>> os.getenv('APPDATA')
'C:\\Users\\yourusername\\AppData\\Roaming'

would it harm if %HOME% would be extended from _C:\Users\yourusername\_
to
_C:\Users\yourusername\Documents_ in windows?

Note that:

1. %HOMEPATH% isn't guaranteed to be Users\
<username>
.

2. The preferred way of referencing that directory is %USERPROFILE%.

3. While %USERPROFILE%\Documents is created automatically, that isn't
guaranteed to be the location of the user's "My Documents" folder (it
can be changed, and in networked environments is typically located on
a file server).

FWIW, the "My Documents" location can be obtained by querying the
registry key

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User
Shell Folders\Personal

then expanding the result; the default value is "%USERPROFILE\Documents".

thanks for your reply.

I've let it untouched; solved it here by:

https://lists.osgeo.org/pipermail/grass-commit/2016-November/040769.html
set R_USER if %USERPROFILE%\Documents\R\ exists to catch most common cases
of private R libraries in windows

-----
best regards
Helmut
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/does-GRASS-need-HOME-to-be-defined-tp5296669p5299180.html
Sent from the Grass - Dev mailing list archive at Nabble.com.