Skip to content

Commit e6e1024

Browse files
authored
grass.app: Always set path to script addons (#6639)
For relevant platforms (currently all except Windows), add the scripts directory for addons to path even if the directory does not exist. When installing into a fresh install, the directory may not exist, so it is not added and the addon tool does not run. The new test fails for the Python tool with the old code, but works with the new code.
1 parent 122fd23 commit e6e1024

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

python/grass/app/runtime.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,12 @@ def append_left_addon_paths(paths, config_dir, env):
200200
addon_base = os.path.join(config_dir, name)
201201
env["GRASS_ADDON_BASE"] = addon_base
202202

203+
# Adding the paths is platform-dependent, but we add them regardless of their
204+
# existence, because they might be created later after the setup is done
205+
# when installing addons.
203206
if not WINDOWS:
204207
script_path = os.path.join(addon_base, "scripts")
205-
if Path(script_path).exists():
206-
paths.appendleft(script_path)
208+
paths.appendleft(script_path)
207209
paths.appendleft(os.path.join(addon_base, "bin"))
208210

209211
# addons (path)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Test g.extension"""
2+
3+
import os
4+
5+
import pytest
6+
7+
import grass.script as gs
8+
from grass.tools import Tools
9+
10+
11+
# Using module-scoped fixture to avoid overhead of downloading addons repo.
12+
@pytest.fixture(scope="module")
13+
def tools(tmp_path_factory):
14+
"""Tools with modified addon base directory (scope: module)"""
15+
tmp_path = tmp_path_factory.mktemp("g_extension_tests")
16+
gs.create_project(tmp_path / "test")
17+
env = os.environ.copy()
18+
env["GRASS_ADDON_BASE"] = str(tmp_path / "addons")
19+
with (
20+
gs.setup.init(tmp_path / "test", env=env) as session,
21+
Tools(session=session, consistent_return_value=True) as tools,
22+
):
23+
yield tools
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Test g.extension"""
2+
3+
import pytest
4+
5+
6+
# This should cover both C and Python tools.
7+
@pytest.mark.parametrize("name", ["r.stream.distance", "r.lake.series"])
8+
def test_install(tools, name):
9+
"""Test that a tools installs and gives help message"""
10+
tools.g_extension(extension=name)
11+
assert tools.call_cmd([name, "--help"]).stderr

0 commit comments

Comments
 (0)