Skip to content

grass.app.runtime: Do not add the same paths again on repeated setup - #7840

Open
Pranav-error wants to merge 2 commits into
OSGeo:mainfrom
Pranav-error:fix-runtime-path-growth
Open

grass.app.runtime: Do not add the same paths again on repeated setup#7840
Pranav-error wants to merge 2 commits into
OSGeo:mainfrom
Pranav-error:fix-runtime-path-growth

Conversation

@Pranav-error

Copy link
Copy Markdown
Contributor

Fixes #7738.

set_executable_paths(), set_dynamic_library_path() and set_python_path_variable() added their entries unconditionally, so calling the setup repeatedly on one environment grew PATH, PYTHONPATH and the library path variable without bound. That happens in a pytest run and in a Jupyter kernel, where gs.setup.init() is called many times on os.environ.

All three now skip an entry that is already present, which is the fix suggested in the issue. First call behaviour is unchanged, and paths from another installation are still added in front of the existing ones, so switching installations keeps working. I did not route init() through ensure_runtime_env(), since runtime_env_is_active() only checks that GISBASE appears in PATH and would skip a re-setup that is actually needed.

set_dynamic_library_path() also assigned "" before appending when the variable was unset, leaving a leading separator. An empty entry in a library path means the current directory, so it now assigns the path directly in that case.

Tests

Seven tests in python/grass/app/tests/grass_app_runtime_test.py, covering, for each setter, that a second call changes nothing, and that an existing value is preserved. Two more cover the empty-entry case and that a second installation's paths still come first.

Checked against the unfixed module first: the four idempotency and empty-entry tests fail there and pass with the change. The 41 existing tests in that file still pass.

I used an AI assistant while preparing this. I understand the change and can explain it.

set_executable_paths(), set_dynamic_library_path() and
set_python_path_variable() added their entries unconditionally, so calling
the setup repeatedly on one environment, as a pytest run or a Jupyter
kernel does, grew PATH, PYTHONPATH and the library path variable without
bound. Skip entries that are already present.

First call behaviour is unchanged, and paths from another installation are
still added in front of the existing ones, so switching installations keeps
working.

set_dynamic_library_path() also assigned an empty value before appending
when the variable was unset, which left a leading separator, and an empty
entry in a library path means the current directory. It now assigns the
path directly in that case.

Fixes OSGeo#7738
Copilot AI lite review requested due to automatic review settings August 22, 2026 22:46

This comment was marked as off-topic.

@github-actions github-actions Bot added Python Related code is in Python libraries tests Related to Test Suite labels Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] grass.script.setup: Repeated init() on the same environment grows PATH, PYTHONPATH, and the library path variable

3 participants