[GRASS-git] [OSGeo/grass] 94b8ec: grass.script.setup: Add return context manager fro...

Alberto Paradís Llop noreply at github.com
Sun Feb 27 17:38:25 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/OSGeo/grass
  Commit: 94b8ec6dfc13b912991e21aa282e62c4dcd55edc
      https://github.com/OSGeo/grass/commit/94b8ec6dfc13b912991e21aa282e62c4dcd55edc
  Author: Alberto Paradís Llop <albertoparadisllop at gmail.com>
  Date:   2022-02-27 (Sun, 27 Feb 2022)

  Changed paths:
    M python/grass/script/setup.py
    A python/grass/script/tests/grass_script_setup_test.py

  Log Message:
  -----------
  grass.script.setup: Add return context manager from init (#1912)

The grass.script.setup.init function now returns a SessionHandle handle object which is a context manager (a class with __enter__ and __exit__ methods).

Works as the Python open function which can be used without a context manager. This also makes it compatible with the current usage of init.

Supports cases when session object is used to do finish and when reference to the session object is not assigned to variable. Use of global finish is still supported. Multiple calls of finish on session raises exception. Multiple sessions in parallel are not supported (the underlying global finish function does not currently support that). Cleaning is not enforced. However, the context manager makes it easier to do that right.

A simple test using pytest of context manager API uses private (protected) function from grass.script.core (for now).

Co-authored-by: Vaclav Petras <wenzeslaus at gmail.com>




More information about the grass-commit mailing list