Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion python/grass/script/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,14 @@ def setup_runtime_env(gisbase=None, *, env=None):
RuntimePaths,
)

from grass.script.core import sanitize_mapset_environment

# If environment is not provided, use the global one.
if not env:
env = os.environ

# Remove mapset-specific variables that should not leak into the
# runtime environment being set up.
sanitize_mapset_environment(env)
runtime_paths = RuntimePaths(env=env, prefix=gisbase)
gisbase = runtime_paths.gisbase
if not Path(gisbase).is_dir():
Expand Down
16 changes: 16 additions & 0 deletions python/grass/script/tests/grass_script_setup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,19 @@ def test_grass_path_types_in_setup(tmp_path, path_type):
gs.setup.setup_runtime_env(grass_path, env=env)
# At least before FHS, GISBASE is the way to detect an active runtime.
assert "GISBASE" in env


@pytest.mark.parametrize("variable", ["GRASS_REGION", "WIND_OVERRIDE"])
@pytest.mark.usefixtures("mock_no_session")
def test_init_removes_mapset_variables(tmp_path, variable):
"""Check that init removes mapset-specific variables from the environment.

Variables tied to a specific mapset (such as region overrides) must not
leak from the provided environment into the initialized session.
"""
project = tmp_path / "test"
gs.create_project(project)
env = os.environ.copy()
env[variable] = "value"
with gs.setup.init(project, env=env) as session:
assert variable not in session.env
Loading