]> git.openstreetmap.org Git - nominatim.git/commitdiff
remove code for setting osm2pgsql via config.lib_dir
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 11 Mar 2025 07:45:10 +0000 (08:45 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 11 Mar 2025 08:04:05 +0000 (09:04 +0100)
With the internal osm2pgsql gone, configuration of the binary location
via settings is the only option left that makes sense.

12 files changed:
nominatim-cli.py
packaging/nominatim-db/scripts/nominatim
src/nominatim_db/cli.py
src/nominatim_db/clicmd/args.py
src/nominatim_db/config.py
src/nominatim_db/tools/exec_utils.py
test/bdd/steps/nominatim_environment.py
test/python/api/test_export.py
test/python/api/test_warm.py
test/python/cli/conftest.py
test/python/cli/test_cmd_replication.py
test/python/conftest.py

index 1f3c1210f7b20e08c66507623ea54a633aa45b4b..7a1aadb84677c8e090819acfc18429298ac8a3e9 100755 (executable)
@@ -3,7 +3,7 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2024 by the Nominatim developer community.
+# Copyright (C) 2025 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Helper script for development to run nominatim from the source directory.
@@ -15,4 +15,4 @@ sys.path.insert(1, str((Path(__file__) / '..' / 'src').resolve()))
 
 from nominatim_db import cli
 
-exit(cli.nominatim(module_dir=None, osm2pgsql_path=None))
+exit(cli.nominatim())
index 184ab4c6cd42e6a924623cd70c74ad2f630b75a7..bc384b023c227706db3559a2abeb130f000a82a9 100755 (executable)
@@ -2,4 +2,4 @@
 
 from nominatim_db import cli
 
-exit(cli.nominatim(osm2pgsql_path=None))
+exit(cli.nominatim())
index f5f74208d3c7ba64eb01d5ed367e17738d6d63db..8d4585c67b36028f875a6b71bf01566750ec42a2 100644 (file)
@@ -2,16 +2,15 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2024 by the Nominatim developer community.
+# Copyright (C) 2025 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Command-line interface to the Nominatim functions for import, update,
 database administration and querying.
 """
-from typing import Optional, Any
+from typing import Optional, List, Mapping
 import importlib
 import logging
-import os
 import sys
 import argparse
 import asyncio
@@ -81,13 +80,14 @@ class CommandlineParser:
         parser.set_defaults(command=cmd)
         cmd.add_args(parser)
 
-    def run(self, **kwargs: Any) -> int:
+    def run(self, cli_args: Optional[List[str]],
+            environ: Optional[Mapping[str, str]]) -> int:
         """ Parse the command line arguments of the program and execute the
             appropriate subcommand.
         """
         args = NominatimArgs()
         try:
-            self.parser.parse_args(args=kwargs.get('cli_args'), namespace=args)
+            self.parser.parse_args(args=cli_args, namespace=args)
         except SystemExit:
             return 1
 
@@ -101,23 +101,19 @@ class CommandlineParser:
 
         args.project_dir = Path(args.project_dir).resolve()
 
-        if 'cli_args' not in kwargs:
+        if cli_args is None:
             logging.basicConfig(stream=sys.stderr,
                                 format='%(asctime)s: %(message)s',
                                 datefmt='%Y-%m-%d %H:%M:%S',
                                 level=max(4 - args.verbose, 1) * 10)
 
-        args.config = Configuration(args.project_dir,
-                                    environ=kwargs.get('environ', os.environ))
-        args.config.set_libdirs(osm2pgsql=kwargs['osm2pgsql_path'])
+        args.config = Configuration(args.project_dir, environ=environ)
 
         log = logging.getLogger()
         log.warning('Using project directory: %s', str(args.project_dir))
 
         try:
-            ret = args.command.run(args)
-
-            return ret
+            return args.command.run(args)
         except UsageError as exception:
             if log.isEnabledFor(logging.DEBUG):
                 raise  # use Python's exception printing
@@ -233,9 +229,16 @@ def get_set_parser() -> CommandlineParser:
     return parser
 
 
-def nominatim(**kwargs: Any) -> int:
+def nominatim(cli_args: Optional[List[str]] = None,
+              environ: Optional[Mapping[str, str]] = None) -> int:
     """\
     Command-line tools for importing, updating, administrating and
     querying the Nominatim database.
+
+    'cli_args' is a list of parameters for the command to run. If not given,
+    sys.args will be used.
+
+    'environ' is the dictionary of environment variables containing the
+    Nominatim configuration. When None, the os.environ is inherited.
     """
-    return get_set_parser().run(**kwargs)
+    return get_set_parser().run(cli_args=cli_args, environ=environ)
index a8ff210a261a90ea52f10ae1547ba73eb92bd57b..45df9b7ca0d7d97cd44860999421bce27ae7effa 100644 (file)
@@ -2,7 +2,7 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2024 by the Nominatim developer community.
+# Copyright (C) 2025 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Provides custom functions over command-line arguments.
@@ -186,7 +186,7 @@ class NominatimArgs:
             from the command line arguments. The resulting dict can be
             further customized and then used in `run_osm2pgsql()`.
         """
-        return dict(osm2pgsql=self.config.OSM2PGSQL_BINARY or self.config.lib_dir.osm2pgsql,
+        return dict(osm2pgsql=self.config.OSM2PGSQL_BINARY,
                     osm2pgsql_cache=self.osm2pgsql_cache or default_cache,
                     osm2pgsql_style=self.config.get_import_style_file(),
                     osm2pgsql_style_path=self.config.lib_dir.lua,
index ae59cfd363857e55d76a888b00b09d6792a4adf7..ba80412266f8f78b3f6a021d2a9ece2e8df2e898 100644 (file)
@@ -2,7 +2,7 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2024 by the Nominatim developer community.
+# Copyright (C) 2025 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Nominatim configuration accessor.
@@ -73,7 +73,6 @@ class Configuration:
             self.project_dir = None
 
         class _LibDirs:
-            osm2pgsql: Path
             sql = paths.SQLLIB_DIR
             lua = paths.LUALIB_DIR
             data = paths.DATA_DIR
index 7629e2a2b0a15442214230b8b77ebabc7b259c97..2d048bcb7bdfbc502f6178e557a832ffa042acf0 100644 (file)
@@ -2,7 +2,7 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2024 by the Nominatim developer community.
+# Copyright (C) 2025 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Helper functions for executing external programs.
@@ -85,7 +85,7 @@ def _mk_tablespace_options(ttype: str, options: Mapping[str, Any]) -> List[str]:
 
 
 def _find_osm2pgsql_cmd(cmdline: Optional[str]) -> str:
-    if cmdline is not None:
+    if cmdline:
         return cmdline
 
     in_path = shutil.which('osm2pgsql')
index 45d42307737e22647ff82f28bdf6b3abaa01de4e..22908480197b793ffd33355f7cd344452f0f4954 100644 (file)
@@ -257,8 +257,7 @@ class NominatimEnvironment:
         if self.website_dir is not None:
             cmdline = list(cmdline) + ['--project-dir', self.website_dir.name]
 
-        cli.nominatim(osm2pgsql_path=None,
-                      cli_args=cmdline,
+        cli.nominatim(cli_args=cmdline,
                       environ=self.test_env)
 
     def copy_from_place(self, db):
index c94cb7fb57624b82ceeb4e07ad9929d3848544fd..7a4c6883533568d8e7b60673972a897e02f46d9d 100644 (file)
@@ -16,8 +16,7 @@ import nominatim_db.cli
 def run_export(tmp_path, capsys):
     def _exec(args):
         cli_args = ['export', '--project-dir', str(tmp_path)] + args
-        assert 0 == nominatim_db.cli.nominatim(osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
-                                               cli_args=cli_args)
+        assert 0 == nominatim_db.cli.nominatim(cli_args=cli_args)
         return capsys.readouterr().out.split('\r\n')
 
     return _exec
index 94081d00051ff5df17695b2168dc058795d6e459..02ca0766ce8d09b17362a4906e67419d69c4368d 100644 (file)
@@ -29,6 +29,5 @@ def setup_database_with_context(apiobj, table_factory):
 
 @pytest.mark.parametrize('args', [['--search-only'], ['--reverse-only']])
 def test_warm_all(tmp_path, args):
-    assert 0 == nominatim_db.cli.nominatim(osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
-                                           cli_args=['admin', '--project-dir', str(tmp_path),
+    assert 0 == nominatim_db.cli.nominatim(cli_args=['admin', '--project-dir', str(tmp_path),
                                                      '--warm'] + args)
index 921a3a322949bcec14d876a8895c6f4b2473c363..0c61b29ea607577d1d8af1d9b18d1b07f34bd348 100644 (file)
@@ -69,8 +69,7 @@ def cli_call():
         Returns a function that can be called with the desired CLI arguments.
     """
     def _call_nominatim(*args):
-        return nominatim_db.cli.nominatim(osm2pgsql_path='OSM2PGSQL NOT AVAILABLE',
-                                          cli_args=args)
+        return nominatim_db.cli.nominatim(cli_args=args)
 
     return _call_nominatim
 
index 34aafa3ab1cae1453174e0018a07739c16b1449c..8ec17eaa9b2fb5ed25798583530f355de5781a0d 100644 (file)
@@ -2,7 +2,7 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2023 by the Nominatim developer community.
+# Copyright (C) 2025 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Tests for replication command of command-line interface wrapper.
@@ -100,7 +100,8 @@ class TestCliReplication:
     def test_replication_update_continuous_no_index(self):
         assert self.call_nominatim('--no-index') == 1
 
-    def test_replication_update_once_no_index(self, update_mock):
+    def test_replication_update_once_no_index(self, update_mock, monkeypatch):
+        monkeypatch.setenv('NOMINATIM_OSM2PGSQL_BINARY', 'OSM2PGSQL NOT AVAILABLE')
         assert self.call_nominatim('--once', '--no-index') == 0
 
         assert str(update_mock.last_args[1]['osm2pgsql']).endswith('OSM2PGSQL NOT AVAILABLE')
index f95da39e4411fd68e8155ebef11643e0308bea4f..b2ab99ed3514b4ebe3370bae8a6816928ef6eb14 100644 (file)
@@ -111,7 +111,6 @@ def table_factory(temp_db_conn):
 @pytest.fixture
 def def_config():
     cfg = Configuration(None)
-    cfg.set_libdirs(osm2pgsql=None)
     return cfg
 
 
@@ -120,7 +119,6 @@ def project_env(tmp_path):
     projdir = tmp_path / 'project'
     projdir.mkdir()
     cfg = Configuration(projdir)
-    cfg.set_libdirs(osm2pgsql=None)
     return cfg
 
 
@@ -211,7 +209,7 @@ def osmline_table(temp_db_with_extensions, table_factory):
 def sql_preprocessor_cfg(tmp_path, table_factory, temp_db_with_extensions):
     table_factory('country_name', 'partition INT', ((0, ), (1, ), (2, )))
     cfg = Configuration(None)
-    cfg.set_libdirs(osm2pgsql=None, sql=tmp_path)
+    cfg.set_libdirs(sql=tmp_path)
     return cfg