"""
import logging
import importlib
+from pathlib import Path
from ..errors import UsageError
from ..db import properties
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):
from nominatim.db import connection
from nominatim.db.sql_preprocessor import SQLPreprocessor
from nominatim.db import properties
+import nominatim.tokenizer.factory
import dummy_tokenizer
import mocks
def _import_dummy(module, *args, **kwargs):
return dummy_tokenizer
- monkeypatch.setattr(importlib, "import_module", _import_dummy)
+ monkeypatch.setattr(nominatim.tokenizer.factory, "_import_tokenizer", _import_dummy)
properties.set_property(temp_db_conn, 'tokenizer', 'dummy')
def _create_tokenizer():