From 44d5148e5fb203ec88fbf56433a6cb93c4b1d209 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 9 Jun 2024 16:22:53 +0200 Subject: [PATCH] fix merge issues --- src/nominatim_db/tools/exec_utils.py | 19 ++++++++++++------- test/python/cli/test_cmd_refresh.py | 2 +- test/python/tools/test_refresh_wiki_data.py | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/nominatim_db/tools/exec_utils.py b/src/nominatim_db/tools/exec_utils.py index 5450c43b..467347f8 100644 --- a/src/nominatim_db/tools/exec_utils.py +++ b/src/nominatim_db/tools/exec_utils.py @@ -30,13 +30,7 @@ def run_osm2pgsql(options: Mapping[str, Any]) -> None: """ env = get_pg_env(options['dsn']) - osm2pgsql_cmd = options['osm2pgsql'] - if osm2pgsql_cmd is None: - osm2pgsql_cmd = shutil.which('osm2pgsql') - if osm2pgsql_cmd is None: - raise RuntimeError('osm2pgsql executable not found. Please install osm2pgsql first.') - - cmd = [str(osm2pgsql_cmd), + cmd = [_find_osm2pgsql_cmd(options['osm2pgsql']), '--slim', '--log-progress', 'true', '--number-processes', '1' if options['append'] else str(options['threads']), @@ -82,3 +76,14 @@ def run_osm2pgsql(options: Mapping[str, Any]) -> None: subprocess.run(cmd, cwd=options.get('cwd', '.'), input=options.get('import_data'), env=env, check=True) + + +def _find_osm2pgsql_cmd(cmdline: str) -> str: + if cmdline is not None: + return cmdline + + in_path = shutil.which('osm2pgsql') + if in_path is None: + raise RuntimeError('osm2pgsql executable not found. Please install osm2pgsql first.') + + return str(in_path) diff --git a/test/python/cli/test_cmd_refresh.py b/test/python/cli/test_cmd_refresh.py index 01b1f6e0..39396817 100644 --- a/test/python/cli/test_cmd_refresh.py +++ b/test/python/cli/test_cmd_refresh.py @@ -92,7 +92,7 @@ class TestRefresh: lambda *args, **kwargs: calls.append('import') or 0) monkeypatch.setattr(nominatim_db.tools.refresh, 'recompute_importance', lambda *args, **kwargs: calls.append('update')) - func_mock = mock_func_factory(nominatim.tools.refresh, 'create_functions') + func_mock = mock_func_factory(nominatim_db.tools.refresh, 'create_functions') assert self.call_nominatim('refresh', '--importance', '--wiki-data') == 0 diff --git a/test/python/tools/test_refresh_wiki_data.py b/test/python/tools/test_refresh_wiki_data.py index c10a7757..997ba04d 100644 --- a/test/python/tools/test_refresh_wiki_data.py +++ b/test/python/tools/test_refresh_wiki_data.py @@ -12,7 +12,7 @@ import csv import pytest -from nominatim.tools.refresh import import_wikipedia_articles, recompute_importance, create_functions +from nominatim_db.tools.refresh import import_wikipedia_articles, recompute_importance, create_functions @pytest.fixture def wiki_csv(tmp_path, sql_preprocessor): -- 2.39.5