remove code for setting osm2pgsql via config.lib_dir

With the internal osm2pgsql gone, configuration of the binary location
via settings is the only option left that makes sense.
This commit is contained in:
Sarah Hoffmann
2025-03-11 08:45:10 +01:00
parent cd08956c61
commit f5755a7a82
12 changed files with 33 additions and 36 deletions

View File

@@ -3,7 +3,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Helper script for development to run nominatim from the source directory. 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 from nominatim_db import cli
exit(cli.nominatim(module_dir=None, osm2pgsql_path=None)) exit(cli.nominatim())

View File

@@ -2,4 +2,4 @@
from nominatim_db import cli from nominatim_db import cli
exit(cli.nominatim(osm2pgsql_path=None)) exit(cli.nominatim())

View File

@@ -2,16 +2,15 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Command-line interface to the Nominatim functions for import, update, Command-line interface to the Nominatim functions for import, update,
database administration and querying. database administration and querying.
""" """
from typing import Optional, Any from typing import Optional, List, Mapping
import importlib import importlib
import logging import logging
import os
import sys import sys
import argparse import argparse
import asyncio import asyncio
@@ -81,13 +80,14 @@ class CommandlineParser:
parser.set_defaults(command=cmd) parser.set_defaults(command=cmd)
cmd.add_args(parser) 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 """ Parse the command line arguments of the program and execute the
appropriate subcommand. appropriate subcommand.
""" """
args = NominatimArgs() args = NominatimArgs()
try: try:
self.parser.parse_args(args=kwargs.get('cli_args'), namespace=args) self.parser.parse_args(args=cli_args, namespace=args)
except SystemExit: except SystemExit:
return 1 return 1
@@ -101,23 +101,19 @@ class CommandlineParser:
args.project_dir = Path(args.project_dir).resolve() args.project_dir = Path(args.project_dir).resolve()
if 'cli_args' not in kwargs: if cli_args is None:
logging.basicConfig(stream=sys.stderr, logging.basicConfig(stream=sys.stderr,
format='%(asctime)s: %(message)s', format='%(asctime)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S', datefmt='%Y-%m-%d %H:%M:%S',
level=max(4 - args.verbose, 1) * 10) level=max(4 - args.verbose, 1) * 10)
args.config = Configuration(args.project_dir, args.config = Configuration(args.project_dir, environ=environ)
environ=kwargs.get('environ', os.environ))
args.config.set_libdirs(osm2pgsql=kwargs['osm2pgsql_path'])
log = logging.getLogger() log = logging.getLogger()
log.warning('Using project directory: %s', str(args.project_dir)) log.warning('Using project directory: %s', str(args.project_dir))
try: try:
ret = args.command.run(args) return args.command.run(args)
return ret
except UsageError as exception: except UsageError as exception:
if log.isEnabledFor(logging.DEBUG): if log.isEnabledFor(logging.DEBUG):
raise # use Python's exception printing raise # use Python's exception printing
@@ -233,9 +229,16 @@ def get_set_parser() -> CommandlineParser:
return parser 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 Command-line tools for importing, updating, administrating and
querying the Nominatim database. 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)

View File

@@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Provides custom functions over command-line arguments. Provides custom functions over command-line arguments.
@@ -186,7 +186,7 @@ class NominatimArgs:
from the command line arguments. The resulting dict can be from the command line arguments. The resulting dict can be
further customized and then used in `run_osm2pgsql()`. 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_cache=self.osm2pgsql_cache or default_cache,
osm2pgsql_style=self.config.get_import_style_file(), osm2pgsql_style=self.config.get_import_style_file(),
osm2pgsql_style_path=self.config.lib_dir.lua, osm2pgsql_style_path=self.config.lib_dir.lua,

View File

@@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Nominatim configuration accessor. Nominatim configuration accessor.
@@ -73,7 +73,6 @@ class Configuration:
self.project_dir = None self.project_dir = None
class _LibDirs: class _LibDirs:
osm2pgsql: Path
sql = paths.SQLLIB_DIR sql = paths.SQLLIB_DIR
lua = paths.LUALIB_DIR lua = paths.LUALIB_DIR
data = paths.DATA_DIR data = paths.DATA_DIR

View File

@@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Helper functions for executing external programs. 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: def _find_osm2pgsql_cmd(cmdline: Optional[str]) -> str:
if cmdline is not None: if cmdline:
return cmdline return cmdline
in_path = shutil.which('osm2pgsql') in_path = shutil.which('osm2pgsql')

View File

@@ -257,8 +257,7 @@ class NominatimEnvironment:
if self.website_dir is not None: if self.website_dir is not None:
cmdline = list(cmdline) + ['--project-dir', self.website_dir.name] cmdline = list(cmdline) + ['--project-dir', self.website_dir.name]
cli.nominatim(osm2pgsql_path=None, cli.nominatim(cli_args=cmdline,
cli_args=cmdline,
environ=self.test_env) environ=self.test_env)
def copy_from_place(self, db): def copy_from_place(self, db):

View File

@@ -16,8 +16,7 @@ import nominatim_db.cli
def run_export(tmp_path, capsys): def run_export(tmp_path, capsys):
def _exec(args): def _exec(args):
cli_args = ['export', '--project-dir', str(tmp_path)] + args cli_args = ['export', '--project-dir', str(tmp_path)] + args
assert 0 == nominatim_db.cli.nominatim(osm2pgsql_path='OSM2PGSQL NOT AVAILABLE', assert 0 == nominatim_db.cli.nominatim(cli_args=cli_args)
cli_args=cli_args)
return capsys.readouterr().out.split('\r\n') return capsys.readouterr().out.split('\r\n')
return _exec return _exec

View File

@@ -29,6 +29,5 @@ def setup_database_with_context(apiobj, table_factory):
@pytest.mark.parametrize('args', [['--search-only'], ['--reverse-only']]) @pytest.mark.parametrize('args', [['--search-only'], ['--reverse-only']])
def test_warm_all(tmp_path, args): def test_warm_all(tmp_path, args):
assert 0 == nominatim_db.cli.nominatim(osm2pgsql_path='OSM2PGSQL NOT AVAILABLE', assert 0 == nominatim_db.cli.nominatim(cli_args=['admin', '--project-dir', str(tmp_path),
cli_args=['admin', '--project-dir', str(tmp_path),
'--warm'] + args) '--warm'] + args)

View File

@@ -69,8 +69,7 @@ def cli_call():
Returns a function that can be called with the desired CLI arguments. Returns a function that can be called with the desired CLI arguments.
""" """
def _call_nominatim(*args): def _call_nominatim(*args):
return nominatim_db.cli.nominatim(osm2pgsql_path='OSM2PGSQL NOT AVAILABLE', return nominatim_db.cli.nominatim(cli_args=args)
cli_args=args)
return _call_nominatim return _call_nominatim

View File

@@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Tests for replication command of command-line interface wrapper. Tests for replication command of command-line interface wrapper.
@@ -100,7 +100,8 @@ class TestCliReplication:
def test_replication_update_continuous_no_index(self): def test_replication_update_continuous_no_index(self):
assert self.call_nominatim('--no-index') == 1 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 self.call_nominatim('--once', '--no-index') == 0
assert str(update_mock.last_args[1]['osm2pgsql']).endswith('OSM2PGSQL NOT AVAILABLE') assert str(update_mock.last_args[1]['osm2pgsql']).endswith('OSM2PGSQL NOT AVAILABLE')

View File

@@ -111,7 +111,6 @@ def table_factory(temp_db_conn):
@pytest.fixture @pytest.fixture
def def_config(): def def_config():
cfg = Configuration(None) cfg = Configuration(None)
cfg.set_libdirs(osm2pgsql=None)
return cfg return cfg
@@ -120,7 +119,6 @@ def project_env(tmp_path):
projdir = tmp_path / 'project' projdir = tmp_path / 'project'
projdir.mkdir() projdir.mkdir()
cfg = Configuration(projdir) cfg = Configuration(projdir)
cfg.set_libdirs(osm2pgsql=None)
return cfg 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): def sql_preprocessor_cfg(tmp_path, table_factory, temp_db_with_extensions):
table_factory('country_name', 'partition INT', ((0, ), (1, ), (2, ))) table_factory('country_name', 'partition INT', ((0, ), (1, ), (2, )))
cfg = Configuration(None) cfg = Configuration(None)
cfg.set_libdirs(osm2pgsql=None, sql=tmp_path) cfg.set_libdirs(sql=tmp_path)
return cfg return cfg