[GRASS-git] [OSGeo/grass] ffb79a: grass.script: Resolve path to mapset in setup.init...

Vaclav Petras noreply at github.com
Sat Oct 2 03:47:08 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/OSGeo/grass
  Commit: ffb79ae031fa6ae970bfbe90c964f8b8b0b3b688
      https://github.com/OSGeo/grass/commit/ffb79ae031fa6ae970bfbe90c964f8b8b0b3b688
  Author: Vaclav Petras <wenzeslaus at gmail.com>
  Date:   2021-10-02 (Sat, 02 Oct 2021)

  Changed paths:
    M doc/notebooks/basic_example.ipynb
    M python/grass/grassdb/manage.py
    A python/grass/grassdb/testsuite/test_manage.py
    M python/grass/jupyter/setup.py
    M python/grass/script/setup.py

  Log Message:
  -----------
  grass.script: Resolve path to mapset in setup.init (#1829)

This replaces the db/loc/mapset defaults in grass.script.setup.init which were for demolocation
by more useful behavior: Basic case is passing all three values as before, but when gisdbase
and location are provided and mapset is not PERMANENT is used. This is actually also the same as
before, but now it fails if location is not provided. Additionally, location and mapset parameters
can be left out if the gisdbase (aka path) parameter points to the mapset or location.
In that case, additional check is done to resolve to see if it is a valid mapset
if not, PERMANENT is used instead. If there is no PERMANENT, the path is left as is.
The grass.jupyter.init uses grass.script.setup.init, so these changes apply there, too.

The gisbase is now automatically detected if possible, but also customizable with new convenient options (see doc).

No more gisbase and gisdbase. Renamed to grass_path and path, respectively. Parameters are also reordered. This will break existing code, but for 7 to 8 switch that's okay.

A possibly breaking change of behavior is that the init function checks for validity of the mapset
and raises an exception if the mapset is invalid (does not exist or fails validity test from grass.grassdb).

Most of the original code from grass.script.setup.init is now in a separate function which sets up the
runtime environment (env vars for libs etc.), but does not do anything with the data (or session file/gisrc).

grass.grassdb now has a new MapsetPath class to simplify path operations around mapset and especially switching between db/loc/mapset and full path to mapset. New function resolve_mapset_path takes care of the path or db/loc/mapset to actual mapset conversion. MapsetPath is reusable and os.PathLike.

GIS_LOCK is moved in the code as it is a part of mapset/data session, not runtime.

Update the basic example notebook for the new API (no gisbase passed, full path to mapset is enough) and correct usage of the old one (no reference to rcfile, finish call added).

Use Path in split_mapset_path and use that in resolve_mapset_path.

Use Path.cwd() / path on Windows if the path does not exist.




More information about the grass-commit mailing list