[GRASS-git] [OSGeo/grass] c810f6: init: Output value for sys.path in config (#1835)

Vaclav Petras noreply at github.com
Tue Nov 30 14:14:33 PST 2021

  Branch: refs/heads/main
  Home:   https://github.com/OSGeo/grass
  Commit: c810f67ab21e94f17c0ad9cfa40312f40d5f4ac1
  Author: Vaclav Petras <wenzeslaus at gmail.com>
  Date:   2021-11-30 (Tue, 30 Nov 2021)

  Changed paths:
    M doc/notebooks/basic_example.ipynb
    M doc/notebooks/basic_example_grass_jupyter.ipynb
    M doc/notebooks/grass_jupyter.ipynb
    M doc/notebooks/hydrology.ipynb
    M doc/notebooks/solar_potential.ipynb
    M doc/notebooks/viewshed_analysis.ipynb
    M lib/init/grass.py
    M python/grass/script/setup.py

  Log Message:
  init: Output value for sys.path in config (#1835)

With this addition, running grass --config python_path outputs the value needed for sys.path. This is useful in Python
where sys.path needs to be set up correctly before the grass package can be imported.

Instead of having to hardcode the etc/python part of the path, user can (optionally) obtain the full path from the new
parameter resulting in a more general code which requires just passing a result of call stripped from the white spaces.

This is especially interesting in combination with #1838 after which GISBASE environmental variable does not have to be
set up before for importing grass.script package, so setting up sys.path is the only step user needs to do before that.
Additionally, with #1829 (and #1979) the installation path (GISBASE) can be determined automatically from the path
to the grass.script.setup module (file), the executable (if it is called grass), or from a user-provided executable which
was be called (by the user) to obtain python_path.

The new setup method is now used in the notebooks.

This simplifoes usage documentaion in setup.py module. No GISBASE is needed. No explicit error checking
(errors are printed and/or raised automatically). sys.path now needs to be str/unicode.

More information about the grass-commit mailing list