From: Sarah Hoffmann Date: Thu, 15 Feb 2024 18:44:04 +0000 (+0100) Subject: make Python frontend default and PHP optional X-Git-Tag: v4.4.0~14^2~6 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/05fad607ffe61ff08b4f44bfd869a40ca04d1932 make Python frontend default and PHP optional --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 536b21bc..6bd99967 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,13 +82,14 @@ endif() # 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) find_program (PHP_BIN php) endif() # sanity check if PHP binary exists 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() message (STATUS "Using PHP binary " ${PHP_BIN}) endif() @@ -226,7 +227,11 @@ if (BUILD_IMPORTER) PATTERN "paths.py" 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 DESTINATION ${NOMINATIM_LIBDIR}/lib-python/nominatim RENAME paths.py) @@ -254,7 +259,7 @@ if (BUILD_MODULE) DESTINATION ${NOMINATIM_LIBDIR}/module) endif() -if (BUILD_API) +if (BUILD_API AND EXISTS ${PHP_BIN}) install(DIRECTORY lib-php DESTINATION ${NOMINATIM_LIBDIR}) endif() diff --git a/cmake/paths-py-no-php.tmpl b/cmake/paths-py-no-php.tmpl new file mode 100644 index 00000000..36856bf3 --- /dev/null +++ b/cmake/paths-py-no-php.tmpl @@ -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() diff --git a/nominatim/cli.py b/nominatim/cli.py index 88a60782..720a8ece 100644 --- a/nominatim/cli.py +++ b/nominatim/cli.py @@ -159,13 +159,15 @@ class AdminServe: group = parser.add_argument_group('Server arguments') group.add_argument('--server', default='127.0.0.1:8088', help='The address the server will listen to.') - group.add_argument('--engine', default='php', + group.add_argument('--engine', default='falcon', choices=('php', 'falcon', 'starlette'), - help='Webserver framework to run. (default: php)') + help='Webserver framework to run. (default: falcon)') def run(self, args: NominatimArgs) -> int: 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') else: import uvicorn # pylint: disable=import-outside-toplevel diff --git a/nominatim/tokenizer/icu_tokenizer.py b/nominatim/tokenizer/icu_tokenizer.py index 5a90edf5..84b4b924 100644 --- a/nominatim/tokenizer/icu_tokenizer.py +++ b/nominatim/tokenizer/icu_tokenizer.py @@ -214,19 +214,20 @@ class ICUTokenizer(AbstractTokenizer): 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. """ - assert self.loader is not None - php_file = self.data_dir / "tokenizer.php" - - if not php_file.exists() or overwrite: - php_file.write_text(dedent(f"""\ - None: diff --git a/nominatim/tokenizer/legacy_tokenizer.py b/nominatim/tokenizer/legacy_tokenizer.py index 2d28a8b2..f3a00839 100644 --- a/nominatim/tokenizer/legacy_tokenizer.py +++ b/nominatim/tokenizer/legacy_tokenizer.py @@ -269,15 +269,16 @@ class LegacyTokenizer(AbstractTokenizer): def _install_php(self, config: Configuration, overwrite: bool = True) -> None: """ Install the php script for the tokenizer. """ - php_file = self.data_dir / "tokenizer.php" - - if not php_file.exists() or overwrite: - php_file.write_text(dedent(f"""\ - None: diff --git a/nominatim/tools/refresh.py b/nominatim/tools/refresh.py index 43e5b1eb..008fc714 100644 --- a/nominatim/tools/refresh.py +++ b/nominatim/tools/refresh.py @@ -213,6 +213,10 @@ def _quote_php_variable(var_type: Type[Any], config: Configuration, def setup_website(basedir: Path, config: Configuration, conn: Connection) -> None: """ 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(): LOG.info('Creating website directory.') basedir.mkdir() diff --git a/test/bdd/environment.py b/test/bdd/environment.py index 664b5ac7..460f3569 100644 --- a/test/bdd/environment.py +++ b/test/bdd/environment.py @@ -28,7 +28,7 @@ userconfig = { 'SERVER_MODULE_PATH' : None, 'TOKENIZER' : None, # Test with a custom tokenizer 'STYLE' : 'extratags', - 'API_ENGINE': 'php', + 'API_ENGINE': 'falcon', 'PHPCOV' : False, # set to output directory to enable code coverage }