original_docstring: Initialize system variables to run GRASS modules
  
      This function is for running GRASS GIS without starting it
      explicitly. No GRASS modules shall be called before call of this
      function but any module or user script can be called afterwards
      as if it would be called in an actual GRASS session. GRASS Python
      libraries are usable as well in general but the ones using
      C libraries through ``ctypes`` are not (which is caused by
      library path not being updated for the current process
      which is a common operating system limitation).
  
      To create a (fake) GRASS session a ``gisrc`` file is created.
      Caller is responsible for deleting the ``gisrc`` file.
  
      Basic usage::
  
          # ... setup GISBASE and PYTHON path before import
          import grass.script as gscript
          gisrc = gscript.setup.init("/usr/bin/grass7",
                                     "/home/john/grassdata",
                                     "nc_spm_08", "user1")
          # ... use GRASS modules here
          # remove the session's gisrc file to end the session
          os.remove(gisrc)
  
      :param gisbase: path to GRASS installation
      :param dbase: path to GRASS database (default: '')
      :param location: location name (default: 'demolocation')
      :param mapset: mapset within given location (default: 'PERMANENT')
  
      :returns: path to ``gisrc`` file (to be deleted later)
      
docstring: Initialize system variables to run GRASS modules
  This function is for running GRASS GIS without starting it
  explicitly. No GRASS modules shall be called before call of this
  function but any module or user script can be called afterwards
  as if it would be called in an actual GRASS session. GRASS Python
  libraries are usable as well in general but the ones using
  C libraries through ``ctypes`` are not (which is caused by
  library path not being updated for the current process
  which is a common operating system limitation).
  
  To create a (fake) GRASS session a ``gisrc`` file is created.
  Caller is responsible for deleting the ``gisrc`` file.
  
  Basic usage:.
  
  
docstring_tokens: Initialize system variables to run GRASS modules This function is for running GRASS GIS without starting it explicitly . No GRASS modules shall be called before call of this function but any module or user script can be called afterwards as if it would be called in an actual GRASS session . GRASS Python libraries are usable as well in general but the ones using C libraries through ` ` ctypes ` ` are not ( which is caused by library path not being updated for the current process which is a common operating system limitation ) . To create a ( fake ) GRASS session a ` ` gisrc ` ` file is created . Caller is responsible for deleting the ` ` gisrc ` ` file . Basic usage : .
code: def grass_init(gisbase, gisdb, location, mapset="PERMANENT", env=None, loadlibs=False):
      """Initialize system variables to run GRASS modules
  
      This function is for running GRASS GIS without starting it
      explicitly. No GRASS modules shall be called before call of this
      function but any module or user script can be called afterwards
      as if it would be called in an actual GRASS session. GRASS Python
      libraries are usable as well in general but the ones using
      C libraries through ``ctypes`` are not (which is caused by
      library path not being updated for the current process
      which is a common operating system limitation).
  
      To create a (fake) GRASS session a ``gisrc`` file is created.
      Caller is responsible for deleting the ``gisrc`` file.
  
      Basic usage::
  
          # ... setup GISBASE and PYTHON path before import
          import grass.script as gscript
          gisrc = gscript.setup.init("/usr/bin/grass7",
                                     "/home/john/grassdata",
                                     "nc_spm_08", "user1")
          # ... use GRASS modules here
          # remove the session's gisrc file to end the session
          os.remove(gisrc)
  
      :param gisbase: path to GRASS installation
      :param dbase: path to GRASS database (default: '')
      :param location: location name (default: 'demolocation')
      :param mapset: mapset within given location (default: 'PERMANENT')
  
      :returns: path to ``gisrc`` file (to be deleted later)
      """
      env = os.environ if env is None else env
      if "GISBASE" not in env:
          raise RuntimeError(
              "GRASS paths are not set, `GISBASE` is missing! "
              "Use `set_grass_path` before calling `grass_init`."
              )
      env["GIS_LOCK"] = str(os.getpid())
  
      # Set GISDBASE environment variable
      env["GISDBASE"] = gisdb
      # TODO: should we check if the gisdb, location and mapset are valid?
      # permanent = os.listdir(os.path.join(gisdb, location, "PERMANENT"))
      # mapset = os.listdir(os.path.join(gisdb, location, mapset))
      if loadlibs:
          load_libs(env["GISBASE"])
      env["GISRC"] = write_gisrc(gisdb, location, mapset)
      return env
code_tokens: def grass_init ( gisbase , gisdb , location , mapset = "PERMANENT" , env = None , loadlibs = False ) : env = os . environ if env is None else env if "GISBASE" not in env : raise RuntimeError ( "GRASS paths are not set, `GISBASE` is missing! " "Use `set_grass_path` before calling `grass_init`." ) env [ "GIS_LOCK" ] = str ( os . getpid ( ) ) env [ "GISDBASE" ] = gisdb if loadlibs : load_libs ( env [ "GISBASE" ] ) env [ "GISRC" ] = write_gisrc ( gisdb , location , mapset ) return env
short_docstring: Initialize system variables to run GRASS modules
  This function is for running GRASS GIS without starting it
  explicitly.
short_docstring_tokens: Initialize system variables to run GRASS modules This function is for running GRASS GIS without starting it explicitly .
comment: """Initialize system variables to run GRASS modules
  
      This function is for running GRASS GIS without starting it
      explicitly. No GRASS modules shall be called before call of this
      function but any module or user script can be called afterwards
      as if it would be called in an actual GRASS session. GRASS Python
      libraries are usable as well in general but the ones using
      C libraries through ``ctypes`` are not (which is caused by
      library path not being updated for the current process
      which is a common operating system limitation).
  
      To create a (fake) GRASS session a ``gisrc`` file is created.
      Caller is responsible for deleting the ``gisrc`` file.
  
      Basic usage::
  
          # ... setup GISBASE and PYTHON path before import
          import grass.script as gscript
          gisrc = gscript.setup.init("/usr/bin/grass7",
                                     "/home/john/grassdata",
                                     "nc_spm_08", "user1")
          # ... use GRASS modules here
          # remove the session's gisrc file to end the session
          os.remove(gisrc)
  
      :param gisbase: path to GRASS installation
      :param dbase: path to GRASS database (default: '')
      :param location: location name (default: 'demolocation')
      :param mapset: mapset within given location (default: 'PERMANENT')
  
      :returns: path to ``gisrc`` file (to be deleted later)
      """$SEP$# Set GISDBASE environment variable$SEP$# TODO: should we check if the gisdb, location and mapset are valid?$SEP$# permanent = os.listdir(os.path.join(gisdb, location, "PERMANENT"))$SEP$# mapset = os.listdir(os.path.join(gisdb, location, mapset))