forked from hans/Nominatim
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:
@@ -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())
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
from nominatim_db import cli
|
||||
|
||||
exit(cli.nominatim(osm2pgsql_path=None))
|
||||
exit(cli.nominatim())
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user