make use of nominatim-api in db package optional

This commit is contained in:
Sarah Hoffmann 2024-06-11 20:21:19 +02:00
parent 3a8c5df82d
commit 5d302a03a6
7 changed files with 32 additions and 23 deletions

View File

@ -30,9 +30,8 @@ requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.version]
source = "code"
path = "../../src/nominatim_api/version.py"
expression = "NOMINATIM_API_VERSION"
pattern = "NOMINATIM_API_VERSION = '(?P<version>[^']+)'"
[tool.hatch.build.targets.sdist.force-include]
"../../src/nominatim_db" = "nominatim_api"

View File

@ -30,9 +30,8 @@ requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.version]
source = "code"
path = "../../src/nominatim_core/version.py"
expression = "NOMINATIM_CORE_VERSION"
pattern = "NOMINATIM_CORE_VERSION = '(?P<version>[^']+)'"
[tool.hatch.build.targets.sdist.force-include]
"../../src/nominatim_core" = "nominatim_core"

View File

@ -30,9 +30,8 @@ requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.version]
source = "code"
path = "../../src/nominatim_db/version.py"
expression = "NOMINATIM_VERSION.release_version()"
pattern = "NOMINATIM_VERSION = parse_version.'(?P<version>[^-]+)"
[tool.hatch.build.targets.sdist.force-include]
"../../src/nominatim_db" = "nominatim_db"

View File

@ -207,15 +207,29 @@ def get_set_parser() -> CommandlineParser:
parser.add_subcommand('admin', clicmd.AdminFuncs())
parser.add_subcommand('export', clicmd.QueryExport())
parser.add_subcommand('convert', clicmd.ConvertDB())
parser.add_subcommand('serve', AdminServe())
try:
exportcmd = importlib.import_module('nominatim_db.clicmd.export')
apicmd = importlib.import_module('nominatim_db.clicmd.api')
convertcmd = importlib.import_module('nominatim_db.clicmd.convert')
parser.add_subcommand('export', exportcmd.QueryExport())
parser.add_subcommand('convert', convertcmd.ConvertDB())
parser.add_subcommand('serve', AdminServe())
parser.add_subcommand('search', apicmd.APISearch())
parser.add_subcommand('reverse', apicmd.APIReverse())
parser.add_subcommand('lookup', apicmd.APILookup())
parser.add_subcommand('details', apicmd.APIDetails())
parser.add_subcommand('status', apicmd.APIStatus())
except ModuleNotFoundError as ex:
if not ex.name or 'nominatim_api' not in ex.name: # pylint: disable=E1135
raise ex
parser.parser.epilog = \
'\n\nNominatim API package not found. The following commands are not available:'\
'\n export, convert, serve, search, reverse, lookup, details, status'\
"\n\nRun 'pip install nominatim-api' to install the package."
parser.add_subcommand('search', clicmd.APISearch())
parser.add_subcommand('reverse', clicmd.APIReverse())
parser.add_subcommand('lookup', clicmd.APILookup())
parser.add_subcommand('details', clicmd.APIDetails())
parser.add_subcommand('status', clicmd.APIStatus())
return parser

View File

@ -13,16 +13,9 @@ Subcommand definitions for the command-line tool.
from .setup import SetupAll as SetupAll
from .replication import UpdateReplication as UpdateReplication
from .api import (APISearch as APISearch,
APIReverse as APIReverse,
APILookup as APILookup,
APIDetails as APIDetails,
APIStatus as APIStatus)
from .index import UpdateIndex as UpdateIndex
from .refresh import UpdateRefresh as UpdateRefresh
from .add_data import UpdateAddData as UpdateAddData
from .admin import AdminFuncs as AdminFuncs
from .freeze import SetupFreeze as SetupFreeze
from .special_phrases import ImportSpecialPhrases as ImportSpecialPhrases
from .export import QueryExport as QueryExport
from .convert import ConvertDB as ConvertDB

View File

@ -11,7 +11,7 @@ import logging
import argparse
import random
import nominatim_api as napi
from nominatim_core.errors import UsageError
from nominatim_core.db.connection import connect
from .args import NominatimArgs
@ -95,6 +95,11 @@ class AdminFuncs:
def _warm(self, args: NominatimArgs) -> int:
try:
import nominatim_api as napi
except ModuleNotFoundError as exp:
raise UsageError("Warming requires nominatim API. "
"Install with 'pip install nominatim-api'.") from exp
LOG.warning('Warming database caches')
api = napi.NominatimAPI(args.project_dir)

View File

@ -15,7 +15,7 @@ from typing import Optional
from nominatim_core.version import (NominatimVersion as NominatimVersion,
parse_version as parse_version)
NOMINATIM_VERSION = NominatimVersion(4, 4, 99, 1)
NOMINATIM_VERSION = parse_version('4.4.99-1')
POSTGRESQL_REQUIRED_VERSION = (9, 6)
POSTGIS_REQUIRED_VERSION = (2, 2)