X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/cb70a2fde33e9c2455ea1cfb37ee430b00058b82..554d25e2e508c57fe763cee95b574b8e7c66eb0b:/nominatim/tokenizer/factory.py?ds=sidebyside diff --git a/nominatim/tokenizer/factory.py b/nominatim/tokenizer/factory.py index e0c06293..dc3e7411 100644 --- a/nominatim/tokenizer/factory.py +++ b/nominatim/tokenizer/factory.py @@ -15,6 +15,7 @@ normalizer module is installed, when the tokenizer is created. """ import logging import importlib +from pathlib import Path from ..errors import UsageError from ..db import properties @@ -25,12 +26,13 @@ LOG = logging.getLogger() def _import_tokenizer(name): """ Load the tokenizer.py module from project directory. """ - try: - return importlib.import_module('nominatim.tokenizer.' + name + '_tokenizer') - except ModuleNotFoundError as exp: + src_file = Path(__file__).parent / (name + '_tokenizer.py') + if not src_file.is_file(): LOG.fatal("No tokenizer named '%s' available. " "Check the setting of NOMINATIM_TOKENIZER.", name) - raise UsageError('Tokenizer not found') from exp + raise UsageError('Tokenizer not found') + + return importlib.import_module('nominatim.tokenizer.' + name + '_tokenizer') def create_tokenizer(config, init_db=True, module_name=None): @@ -83,6 +85,6 @@ def get_tokenizer_for_db(config): tokenizer_module = _import_tokenizer(name) tokenizer = tokenizer_module.create(config.get_libpq_dsn(), basedir) - tokenizer.init_from_project() + tokenizer.init_from_project(config) return tokenizer