Refactor and simplify the startup procedure used by initGRASS - #109
Open
stevenpawley wants to merge 24 commits into
Open
Refactor and simplify the startup procedure used by initGRASS#109stevenpawley wants to merge 24 commits into
initGRASS#109stevenpawley wants to merge 24 commits into
Conversation
…inor and patch versioning
…that defines and updates GRASS_ADDON_BASE
…ntime setup into its own function - setup_runtime_env_unix
…on GRASS env vars on windows into the standalone function setup_runtime_env_windows
…S(). When R starts inside an existing GRASS location, initGRASS() isn’t called, so temporary output paths became /file….
…tu is missing proper SSL/TLS certificates needed to verify GitHub's server certificate when cloning the repository over HTTPS.
…no longer available in the Ubuntu package repositories. The current version of Pandoc in the Ubuntu repositories already handles citations natively.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors and simplifies the startup procedure used by
initGRASS()to broadly match the process used withingrass.script.setup.init().The original procedure performed all operations inline, within a single function. In this PR, the platform-specific setup and session initialization code has been extracted into separate internal helper functions. This should make
initGRASS()easier to follow, test, and maintain, without any other user-facing changes.Overview of GRASS startup procedure
Original startup procedure using in rgrass
Configures temporary-file handling via
RGRASS_TEMPDIRChecks for existing GRASS state:
GISRCenvironment variable identifies an existing active session;GIS_LOCKenvironment variable is set;Creates the pid and validates the initGRASS main arguments
Determines the GRASS installation directory:
gisBaseargument when supplied;GRASS_INSTALLATIONenvironment variable;grass --config path.Checks that
gisBaseexists and containsbinandscriptsfoldersReads the GRASS major version
Enters a large inline, platform-specific branch:
On Windows:
GISBASEandHOMEenvironment variablesaddon_baseargument or%APPDATA%\GRASS8\addonsOSGEO4W_ROOTand uses it to define PROJ coordinate-transformation library location:GRASS_PROJSHAREto <OSGEO4W_ROOT>/share/proj for OSGEO4WGRASS_PROJSHAREto /share/proj for standalone GRASSPATH,PYTHONPATH, and, where applicable,PYTHONHOME;GISRCpath (decides where to create the temporary session configuration file)GISRC=C:/path/to/the/session-fileGISRCalready existed at that location and decides what to dobased on the
overrideargumentwith a file in
RGRASS_TEMPDIR.GISRCcontaining:getwd()g.dirseps.exeto convert the GISRC path windows/unix styleand replaces the GISRC environment variable with that converted path
addEXE);gisDbase; optionally callsg.dirseps.exeto convertits path.
On Unix:
GISBASEand resolves thehomevalue;PATH,LD_LIBRARY_PATH, andPYTHONPATH;gisDbase;GISDBASE: the selected or temporary database path;LOCATION_NAME:;MAPSET:.Sets
GIS_LOCKand records the session and cleanup state in.GRASS_CACHE.Calls
g.gisenvinitially to setGISDBASE.Determines and creates the final session directory structure:
PERMANENT.Calls
g.gisenvrepeatedly to set the final:GISDBASE;LOCATION_NAME;MAPSET;GRASS_GUI=text.Sets
GISBASE,GISDBASE,LOCATION_NAME, andMAPSET.Checks GRASS compatibility (
g.version, check compatibility)Selects the Python executable (OSGeo4W python3.exe or python.exe; or python3/python based on the GRASS version)
Creates
DEFAULT_WINDand the mapsetWINDfiles, then configures theregion and optional projection supplied through
SG.Return session metadata (returns output from
gmeta())New startup procedure
gisBase <- search_grass())validate_gisbase(gisBase))gv <- grass_version(gisBase))home <- set_home_path(home))session <- create_session_directories(...)setup_runtime_env_windows(...)setup_runtime_env_unix(...)GISBASE, add-on paths, executable paths, library paths, Python paths, Windows OSGeo4W checks and PROJ configurationwrite_gisrc(...))set_grass_python(...))write_wind(...))gmeta())Key differences
The old process was incremental. It first wrote a partial GISRC containing
GISDBASEand blankLOCATION_NAMEandMAPSETvalues. This gaveg.gisenvenough configuration to run. It then used GRASS itself to setGISDBASE,LOCATION_NAME,MAPSET, andGRASS_GUI=textin the GISRC, after creating the location and mapset directories. On Windows, it also usedg.dirseps.exeto normalize paths.The new process prepares the complete session details in R first, then writes one final GISRC with the actual database, location, and mapset values.
The GISRC file is now written with the final session values directly:
GISDBASELOCATION_NAMEMAPSETGRASS_GUIThis removes the need to initialize the file with placeholder values and subsequently update it through multiple
g.gisenvcalls.Windows startup paths are now normalized using R instead of invoking
g.dirseps.exe. This simplifies startup because the old executable-based conversion required a preliminary GISRC file. The existinguse_g.dirseps.exeargument is retained for compatibility, although normalization is now performed by R rather than by the executable. I'd like to deprecate this argument in later versions.Specific changes
Testing
The following initGRASS scenarios were tested successfully:
Review considerations
Review would be helpful for:
initGRASSuse_g.dirseps.exeshould remain as a compatibility argument or be deprecated in a future release.