mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
make Python frontend default and PHP optional
This commit is contained in:
@@ -82,13 +82,14 @@ endif()
|
|||||||
|
|
||||||
# Setting PHP binary variable as to command line (prevailing) or auto detect
|
# Setting PHP binary variable as to command line (prevailing) or auto detect
|
||||||
|
|
||||||
if (BUILD_API OR BUILD_IMPORTER)
|
if (BUILD_API)
|
||||||
if (NOT PHP_BIN)
|
if (NOT PHP_BIN)
|
||||||
find_program (PHP_BIN php)
|
find_program (PHP_BIN php)
|
||||||
endif()
|
endif()
|
||||||
# sanity check if PHP binary exists
|
# sanity check if PHP binary exists
|
||||||
if (NOT EXISTS ${PHP_BIN})
|
if (NOT EXISTS ${PHP_BIN})
|
||||||
message(FATAL_ERROR "PHP binary not found. Install php or provide location with -DPHP_BIN=/path/php ")
|
message(WARNING "PHP binary not found. Only Python frontend can be used.")
|
||||||
|
set(PHP_BIN "")
|
||||||
else()
|
else()
|
||||||
message (STATUS "Using PHP binary " ${PHP_BIN})
|
message (STATUS "Using PHP binary " ${PHP_BIN})
|
||||||
endif()
|
endif()
|
||||||
@@ -226,7 +227,11 @@ if (BUILD_IMPORTER)
|
|||||||
PATTERN "paths.py" EXCLUDE
|
PATTERN "paths.py" EXCLUDE
|
||||||
PATTERN __pycache__ EXCLUDE)
|
PATTERN __pycache__ EXCLUDE)
|
||||||
|
|
||||||
configure_file(${PROJECT_SOURCE_DIR}/cmake/paths-py.tmpl paths-py.installed)
|
if (EXISTS ${PHP_BIN})
|
||||||
|
configure_file(${PROJECT_SOURCE_DIR}/cmake/paths-py.tmpl paths-py.installed)
|
||||||
|
else()
|
||||||
|
configure_file(${PROJECT_SOURCE_DIR}/cmake/paths-py-no-php.tmpl paths-py.installed)
|
||||||
|
endif()
|
||||||
install(FILES ${PROJECT_BINARY_DIR}/paths-py.installed
|
install(FILES ${PROJECT_BINARY_DIR}/paths-py.installed
|
||||||
DESTINATION ${NOMINATIM_LIBDIR}/lib-python/nominatim
|
DESTINATION ${NOMINATIM_LIBDIR}/lib-python/nominatim
|
||||||
RENAME paths.py)
|
RENAME paths.py)
|
||||||
@@ -254,7 +259,7 @@ if (BUILD_MODULE)
|
|||||||
DESTINATION ${NOMINATIM_LIBDIR}/module)
|
DESTINATION ${NOMINATIM_LIBDIR}/module)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (BUILD_API)
|
if (BUILD_API AND EXISTS ${PHP_BIN})
|
||||||
install(DIRECTORY lib-php DESTINATION ${NOMINATIM_LIBDIR})
|
install(DIRECTORY lib-php DESTINATION ${NOMINATIM_LIBDIR})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
15
cmake/paths-py-no-php.tmpl
Normal file
15
cmake/paths-py-no-php.tmpl
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
#
|
||||||
|
# This file is part of Nominatim. (https://nominatim.org)
|
||||||
|
#
|
||||||
|
# Copyright (C) 2022 by the Nominatim developer community.
|
||||||
|
# For a full list of authors see the git log.
|
||||||
|
"""
|
||||||
|
Path settings for extra data used by Nominatim (installed version).
|
||||||
|
"""
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
PHPLIB_DIR = None
|
||||||
|
SQLLIB_DIR = (Path('@NOMINATIM_LIBDIR@') / 'lib-sql').resolve()
|
||||||
|
DATA_DIR = Path('@NOMINATIM_DATADIR@').resolve()
|
||||||
|
CONFIG_DIR = Path('@NOMINATIM_CONFIGDIR@').resolve()
|
||||||
@@ -159,13 +159,15 @@ class AdminServe:
|
|||||||
group = parser.add_argument_group('Server arguments')
|
group = parser.add_argument_group('Server arguments')
|
||||||
group.add_argument('--server', default='127.0.0.1:8088',
|
group.add_argument('--server', default='127.0.0.1:8088',
|
||||||
help='The address the server will listen to.')
|
help='The address the server will listen to.')
|
||||||
group.add_argument('--engine', default='php',
|
group.add_argument('--engine', default='falcon',
|
||||||
choices=('php', 'falcon', 'starlette'),
|
choices=('php', 'falcon', 'starlette'),
|
||||||
help='Webserver framework to run. (default: php)')
|
help='Webserver framework to run. (default: falcon)')
|
||||||
|
|
||||||
|
|
||||||
def run(self, args: NominatimArgs) -> int:
|
def run(self, args: NominatimArgs) -> int:
|
||||||
if args.engine == 'php':
|
if args.engine == 'php':
|
||||||
|
if args.config.lib_dir.php is None:
|
||||||
|
raise UsageError("PHP frontend not configured.")
|
||||||
run_php_server(args.server, args.project_dir / 'website')
|
run_php_server(args.server, args.project_dir / 'website')
|
||||||
else:
|
else:
|
||||||
import uvicorn # pylint: disable=import-outside-toplevel
|
import uvicorn # pylint: disable=import-outside-toplevel
|
||||||
|
|||||||
@@ -214,19 +214,20 @@ class ICUTokenizer(AbstractTokenizer):
|
|||||||
return list(s[0].split('@')[0] for s in cur)
|
return list(s[0].split('@')[0] for s in cur)
|
||||||
|
|
||||||
|
|
||||||
def _install_php(self, phpdir: Path, overwrite: bool = True) -> None:
|
def _install_php(self, phpdir: Optional[Path], overwrite: bool = True) -> None:
|
||||||
""" Install the php script for the tokenizer.
|
""" Install the php script for the tokenizer.
|
||||||
"""
|
"""
|
||||||
assert self.loader is not None
|
if phpdir is not None:
|
||||||
php_file = self.data_dir / "tokenizer.php"
|
assert self.loader is not None
|
||||||
|
php_file = self.data_dir / "tokenizer.php"
|
||||||
|
|
||||||
if not php_file.exists() or overwrite:
|
if not php_file.exists() or overwrite:
|
||||||
php_file.write_text(dedent(f"""\
|
php_file.write_text(dedent(f"""\
|
||||||
<?php
|
<?php
|
||||||
@define('CONST_Max_Word_Frequency', 10000000);
|
@define('CONST_Max_Word_Frequency', 10000000);
|
||||||
@define('CONST_Term_Normalization_Rules', "{self.loader.normalization_rules}");
|
@define('CONST_Term_Normalization_Rules', "{self.loader.normalization_rules}");
|
||||||
@define('CONST_Transliteration', "{self.loader.get_search_rules()}");
|
@define('CONST_Transliteration', "{self.loader.get_search_rules()}");
|
||||||
require_once('{phpdir}/tokenizer/icu_tokenizer.php');"""), encoding='utf-8')
|
require_once('{phpdir}/tokenizer/icu_tokenizer.php');"""), encoding='utf-8')
|
||||||
|
|
||||||
|
|
||||||
def _save_config(self) -> None:
|
def _save_config(self) -> None:
|
||||||
|
|||||||
@@ -269,15 +269,16 @@ class LegacyTokenizer(AbstractTokenizer):
|
|||||||
def _install_php(self, config: Configuration, overwrite: bool = True) -> None:
|
def _install_php(self, config: Configuration, overwrite: bool = True) -> None:
|
||||||
""" Install the php script for the tokenizer.
|
""" Install the php script for the tokenizer.
|
||||||
"""
|
"""
|
||||||
php_file = self.data_dir / "tokenizer.php"
|
if config.lib_dir.php is not None:
|
||||||
|
php_file = self.data_dir / "tokenizer.php"
|
||||||
|
|
||||||
if not php_file.exists() or overwrite:
|
if not php_file.exists() or overwrite:
|
||||||
php_file.write_text(dedent(f"""\
|
php_file.write_text(dedent(f"""\
|
||||||
<?php
|
<?php
|
||||||
@define('CONST_Max_Word_Frequency', {config.MAX_WORD_FREQUENCY});
|
@define('CONST_Max_Word_Frequency', {config.MAX_WORD_FREQUENCY});
|
||||||
@define('CONST_Term_Normalization_Rules', "{config.TERM_NORMALIZATION}");
|
@define('CONST_Term_Normalization_Rules', "{config.TERM_NORMALIZATION}");
|
||||||
require_once('{config.lib_dir.php}/tokenizer/legacy_tokenizer.php');
|
require_once('{config.lib_dir.php}/tokenizer/legacy_tokenizer.php');
|
||||||
"""), encoding='utf-8')
|
"""), encoding='utf-8')
|
||||||
|
|
||||||
|
|
||||||
def _init_db_tables(self, config: Configuration) -> None:
|
def _init_db_tables(self, config: Configuration) -> None:
|
||||||
|
|||||||
@@ -213,6 +213,10 @@ def _quote_php_variable(var_type: Type[Any], config: Configuration,
|
|||||||
def setup_website(basedir: Path, config: Configuration, conn: Connection) -> None:
|
def setup_website(basedir: Path, config: Configuration, conn: Connection) -> None:
|
||||||
""" Create the website script stubs.
|
""" Create the website script stubs.
|
||||||
"""
|
"""
|
||||||
|
if config.lib_dir.php is None:
|
||||||
|
LOG.info("Python frontend does not require website setup. Skipping.")
|
||||||
|
return
|
||||||
|
|
||||||
if not basedir.exists():
|
if not basedir.exists():
|
||||||
LOG.info('Creating website directory.')
|
LOG.info('Creating website directory.')
|
||||||
basedir.mkdir()
|
basedir.mkdir()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ userconfig = {
|
|||||||
'SERVER_MODULE_PATH' : None,
|
'SERVER_MODULE_PATH' : None,
|
||||||
'TOKENIZER' : None, # Test with a custom tokenizer
|
'TOKENIZER' : None, # Test with a custom tokenizer
|
||||||
'STYLE' : 'extratags',
|
'STYLE' : 'extratags',
|
||||||
'API_ENGINE': 'php',
|
'API_ENGINE': 'falcon',
|
||||||
'PHPCOV' : False, # set to output directory to enable code coverage
|
'PHPCOV' : False, # set to output directory to enable code coverage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user