mirror of
https://github.com/osm-search/Nominatim.git
synced 2024-10-05 23:17:14 +03:00
make Python frontend default and PHP optional
This commit is contained in:
parent
19360a9552
commit
05fad607ff
@ -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)
|
||||
|
||||
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()
|
||||
|
||||
|
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.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
|
||||
|
@ -214,9 +214,10 @@ 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.
|
||||
"""
|
||||
if phpdir is not None:
|
||||
assert self.loader is not None
|
||||
php_file = self.data_dir / "tokenizer.php"
|
||||
|
||||
|
@ -269,6 +269,7 @@ class LegacyTokenizer(AbstractTokenizer):
|
||||
def _install_php(self, config: Configuration, overwrite: bool = True) -> None:
|
||||
""" Install the php script for the tokenizer.
|
||||
"""
|
||||
if config.lib_dir.php is not None:
|
||||
php_file = self.data_dir / "tokenizer.php"
|
||||
|
||||
if not php_file.exists() or overwrite:
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user