Open luisponti opened 3 years ago
I usually refactor this into a dictionary / mapping, but more elegant.
Do you mean something like this?
Btw you can use the platform
module:
>>> import platform
>>> platform.machine()
'x86_64'
Then for the mapping
binaries = {
"x86_64": "grass7bin_lin",
"win": "grass7bin_win",
...
}
my_os = platform.machine()
default = "x86_64"
binary = binaries.get(my_os, default)
Ah we already have this issue for the mapping refactoring, good.
Instead of machine()
I would actually use system()
:
https://docs.python.org/3/library/platform.html#platform.system
Here are the common return values:
Some relevant comments I removed from code:
""" GRASS enviornment
https://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly
See also issue #15 https://github.com/luisponti/casas-gis/issues/15
# List of variables that GRASS modules need to run without starting
# the main GRASS program
export GISBASE=/Applications/GRASS-8.0.app/Contents/Resources
export GISRC="$HOME.grass8"
export PATH="$GISBASE/bin:$GISBASE/scripts:$PATH"
export PYTHONPATH="$GISBASE/etc/python:$PYTHONPATH"
export DYLD_LIBRARY_PATH="$GISBASE/lib:$DYLD_LIBRARY_PATH"
export LD_LIBRARY_PATH="$GISBASE/lib:$LD_LIBRARY_PATH"
export MANPATH="$MANPATH:$GISBASE/man"
export GRASS_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
export GRASS_LD_LIBRARY_PATH="$DYLD_LIBRARY_PATH"
If the GRASS libraries are shared libraries, the loader needs to be able
to find them. This normally means that LD_LIBRARY_PATH (Linux, Solaris),
DYLD_LIBRARY_PATH (MacOSX) or PATH (Windows) need to contain $GISBASE/lib
"""
FWIW, this has been greatly simplified in GRASS GIS 8.4+.
See for example: https://github.com/OSGeo/grass/blob/main/docker/testdata/test_grass_session.py
Develop a module that sets up GRASS environment based on platform (e.g., Linux, Mac, Windows), before GRASS starts up.
See for example the following coode: