[GRASS-git] [OSGeo/grass] 956485: grass.script: Allow init to modify only specified ...

Vaclav Petras noreply at github.com
Wed Jun 19 05:28:57 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/OSGeo/grass
  Commit: 9564852ce5274e529006579e5d926387ff639f9b
      https://github.com/OSGeo/grass/commit/9564852ce5274e529006579e5d926387ff639f9b
  Author: Vaclav Petras <wenzeslaus at gmail.com>
  Date:   2024-06-19 (Wed, 19 Jun 2024)

  Changed paths:
    M python/grass/experimental/tests/conftest.py
    M python/grass/experimental/tests/grass_script_mapset_session_test.py
    M python/grass/script/setup.py
    M python/grass/script/tests/grass_script_core_location_test.py
    M python/grass/script/tests/grass_script_setup_test.py
    M scripts/v.db.univar/tests/conftest.py
    M scripts/v.db.univar/tests/v_db_univar_test.py
    M scripts/v.dissolve/tests/conftest.py
    M scripts/v.dissolve/tests/v_dissolve_aggregate_test.py
    M scripts/v.dissolve/tests/v_dissolve_geometry_test.py
    M scripts/v.dissolve/tests/v_dissolve_layers_test.py
    M scripts/v.dissolve/tests/v_dissolve_test.py
    M temporal/t.rast.list/tests/conftest.py
    M temporal/t.rast.list/tests/t_rast_list_test.py
    M vector/v.fill.holes/tests/conftest.py
    M vector/v.fill.holes/tests/v_fill_holes_test.py

  Log Message:
  -----------
  grass.script: Allow init to modify only specified environment (#3438)

The _grass.script.setup.init_ function modifies os.environ. While os.environ is fit for many, if not most, cases, usage in tests and parallel processing is limited and in all cases, os.environ stays partially modified even after session is finished (we don't destroy the runtime environment, i.e., variables such as GISBASE). With this change, _init_ takes _env_ parameter specifying the environment to modify and it modifies that environment. When no _env_ is provided, it still modifies os.environ, so the default behavior is not changed.

This required only few changes to the initialization code, but more changes were needed for the cleanup code. A lot of tests can now take advantage of this functionality and this PR updates some of them. I plan to update all where it is applicable, but will leave as is some others, namely those which use ctypes (situation is more complex there) and _grass.jupyter_ (_env_ parameter is not implemented for most of them).

There is plenty of tests covering it, but the cleanup part which needed most changes does not have any coverage. I don't think there is much concern in terms of API because _env_ parameters is what we now have in many functions. The only uncertainty with that is whether it should create its own copy or modify the provided environment. I go with modify because that makes the copy explicit in the call which is more clear (caller or reader is sure a copy is created) and it is consistent with how os.environ is modified.



To unsubscribe from these emails, change your notification settings at https://github.com/OSGeo/grass/settings/notifications


More information about the grass-commit mailing list