mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-15 02:47:59 +00:00
cli: import python modules for commands on demand
Given that only one command will be executed in the end, it is not necessary to import what amounts to the whole library. This becomes in particular important for update functions that have a dependency on pyosmium. The dependency can remain optional for people not using updates.
This commit is contained in:
@@ -11,8 +11,6 @@ from pathlib import Path
|
||||
from .config import Configuration
|
||||
from .tools.exec_utils import run_legacy_script, run_api_script
|
||||
|
||||
from .indexer.indexer import Indexer
|
||||
|
||||
def _num_system_cpus():
|
||||
try:
|
||||
cpus = len(os.sched_getaffinity(0))
|
||||
@@ -320,6 +318,8 @@ class UpdateIndex:
|
||||
|
||||
@staticmethod
|
||||
def run(args):
|
||||
from .indexer.indexer import Indexer
|
||||
|
||||
indexer = Indexer(args.config.get_libpq_dsn(),
|
||||
args.threads or _num_system_cpus() or 1)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import psycopg2
|
||||
import pytest
|
||||
|
||||
import nominatim.cli
|
||||
import nominatim.indexer.indexer
|
||||
|
||||
def call_nominatim(*args):
|
||||
return nominatim.cli.nominatim(module_dir='build/module',
|
||||
@@ -87,9 +88,9 @@ def test_index_command(monkeypatch, temp_db, params, do_bnds, do_ranks):
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("CREATE TABLE import_status (indexed bool)")
|
||||
bnd_mock = MockParamCapture()
|
||||
monkeypatch.setattr(nominatim.cli.Indexer, 'index_boundaries', bnd_mock)
|
||||
monkeypatch.setattr(nominatim.indexer.indexer.Indexer, 'index_boundaries', bnd_mock)
|
||||
rank_mock = MockParamCapture()
|
||||
monkeypatch.setattr(nominatim.cli.Indexer, 'index_by_rank', rank_mock)
|
||||
monkeypatch.setattr(nominatim.indexer.indexer.Indexer, 'index_by_rank', rank_mock)
|
||||
|
||||
assert 0 == call_nominatim('index', *params)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user