forked from hans/Nominatim
have ADDRESS_LEVEL_CONFIG use load_sub_configuration
This means that relative paths now are looked up in the project directory.
This commit is contained in:
@@ -309,12 +309,15 @@ unset, Nominatim expects the data to be saved in the project directory.
|
|||||||
| -------------- | --------------------------------------------------- |
|
| -------------- | --------------------------------------------------- |
|
||||||
| **Description:** | Configuration file for rank assignments |
|
| **Description:** | Configuration file for rank assignments |
|
||||||
| **Format:** | path |
|
| **Format:** | path |
|
||||||
| **Default:** | _empty_ (use default settings) |
|
| **Default:** | address-levels.json |
|
||||||
|
|
||||||
The _address level config_ configures rank assignments for places. See
|
The _address level configuration_ defines the rank assignments for places. See
|
||||||
[Place Ranking](Ranking.md) for a detailed explanation what rank assignments
|
[Place Ranking](Ranking.md) for a detailed explanation what rank assignments
|
||||||
are and what the configuration file must look like. The default configuration
|
are and what the configuration file must look like.
|
||||||
can be found in the configuration directory as `address-levels.json`.
|
|
||||||
|
When a relative path is given, then the file is searched first relative to the
|
||||||
|
project directory and then in the global settings directory.
|
||||||
|
|
||||||
|
|
||||||
#### NOMINATIM_IMPORT_STYLE
|
#### NOMINATIM_IMPORT_STYLE
|
||||||
|
|
||||||
|
|||||||
@@ -75,10 +75,9 @@ class UpdateRefresh:
|
|||||||
self._get_tokenizer(args.config).update_statistics()
|
self._get_tokenizer(args.config).update_statistics()
|
||||||
|
|
||||||
if args.address_levels:
|
if args.address_levels:
|
||||||
cfg = Path(args.config.ADDRESS_LEVEL_CONFIG)
|
LOG.warning('Updating address levels')
|
||||||
LOG.warning('Updating address levels from %s', cfg)
|
|
||||||
with connect(args.config.get_libpq_dsn()) as conn:
|
with connect(args.config.get_libpq_dsn()) as conn:
|
||||||
refresh.load_address_levels_from_file(conn, cfg)
|
refresh.load_address_levels_from_config(conn, args.config)
|
||||||
|
|
||||||
if args.functions:
|
if args.functions:
|
||||||
LOG.warning('Create functions')
|
LOG.warning('Create functions')
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ class SetupAll:
|
|||||||
refresh.create_functions(conn, config, False, False)
|
refresh.create_functions(conn, config, False, False)
|
||||||
LOG.warning('Create tables')
|
LOG.warning('Create tables')
|
||||||
database_import.create_tables(conn, config, reverse_only=reverse_only)
|
database_import.create_tables(conn, config, reverse_only=reverse_only)
|
||||||
refresh.load_address_levels_from_file(conn, Path(config.ADDRESS_LEVEL_CONFIG))
|
refresh.load_address_levels_from_config(conn, config)
|
||||||
LOG.warning('Create functions (2nd pass)')
|
LOG.warning('Create functions (2nd pass)')
|
||||||
refresh.create_functions(conn, config, False, False)
|
refresh.create_functions(conn, config, False, False)
|
||||||
LOG.warning('Create table triggers')
|
LOG.warning('Create table triggers')
|
||||||
|
|||||||
@@ -56,12 +56,6 @@ class Configuration:
|
|||||||
if project_dir is not None and (project_dir / '.env').is_file():
|
if project_dir is not None and (project_dir / '.env').is_file():
|
||||||
self._config.update(dotenv_values(str((project_dir / '.env').resolve())))
|
self._config.update(dotenv_values(str((project_dir / '.env').resolve())))
|
||||||
|
|
||||||
# Add defaults for variables that are left empty to set the default.
|
|
||||||
# They may still be overwritten by environment variables.
|
|
||||||
if not self._config['NOMINATIM_ADDRESS_LEVEL_CONFIG']:
|
|
||||||
self._config['NOMINATIM_ADDRESS_LEVEL_CONFIG'] = \
|
|
||||||
str(config_dir / 'address-levels.json')
|
|
||||||
|
|
||||||
class _LibDirs:
|
class _LibDirs:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
Functions for bringing auxiliary data in the database up-to-date.
|
Functions for bringing auxiliary data in the database up-to-date.
|
||||||
"""
|
"""
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
@@ -58,12 +57,15 @@ def load_address_levels(conn, table, levels):
|
|||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
def load_address_levels_from_file(conn, config_file):
|
|
||||||
""" Replace the `address_levels` table with the contents of the config
|
def load_address_levels_from_config(conn, config):
|
||||||
file.
|
""" Replace the `address_levels` table with the content as
|
||||||
|
defined in the given configuration. Uses the parameter
|
||||||
|
NOMINATIM_ADDRESS_LEVEL_CONFIG to determine the location of the
|
||||||
|
configuration file.
|
||||||
"""
|
"""
|
||||||
with config_file.open('r') as fdesc:
|
cfg = config.load_sub_configuration('', config='ADDRESS_LEVEL_CONFIG')
|
||||||
load_address_levels(conn, 'address_levels', json.load(fdesc))
|
load_address_levels(conn, 'address_levels', cfg)
|
||||||
|
|
||||||
|
|
||||||
def create_functions(conn, config, enable_diff_updates=True, enable_debug=False):
|
def create_functions(conn, config, enable_diff_updates=True, enable_debug=False):
|
||||||
|
|||||||
@@ -94,9 +94,7 @@ NOMINATIM_WIKIPEDIA_DATA_PATH=
|
|||||||
NOMINATIM_PHRASE_CONFIG=
|
NOMINATIM_PHRASE_CONFIG=
|
||||||
|
|
||||||
# Configuration file for rank assignments.
|
# Configuration file for rank assignments.
|
||||||
# When unset, the internal default settings from 'settings/address-levels.json'
|
NOMINATIM_ADDRESS_LEVEL_CONFIG=address-levels.json
|
||||||
# are used.
|
|
||||||
NOMINATIM_ADDRESS_LEVEL_CONFIG=
|
|
||||||
|
|
||||||
# Configuration file for OSM data import.
|
# Configuration file for OSM data import.
|
||||||
# This may either be the name of one of an internal style or point
|
# This may either be the name of one of an internal style or point
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ class TestCliWithDb:
|
|||||||
mock_func_factory(nominatim.tools.database_import, 'create_partition_tables'),
|
mock_func_factory(nominatim.tools.database_import, 'create_partition_tables'),
|
||||||
mock_func_factory(nominatim.tools.database_import, 'create_search_indices'),
|
mock_func_factory(nominatim.tools.database_import, 'create_search_indices'),
|
||||||
mock_func_factory(nominatim.tools.country_info, 'create_country_names'),
|
mock_func_factory(nominatim.tools.country_info, 'create_country_names'),
|
||||||
mock_func_factory(nominatim.tools.refresh, 'load_address_levels_from_file'),
|
mock_func_factory(nominatim.tools.refresh, 'load_address_levels_from_config'),
|
||||||
mock_func_factory(nominatim.tools.postcodes, 'update_postcodes'),
|
mock_func_factory(nominatim.tools.postcodes, 'update_postcodes'),
|
||||||
mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_full'),
|
mock_func_factory(nominatim.indexer.indexer.Indexer, 'index_full'),
|
||||||
mock_func_factory(nominatim.tools.refresh, 'setup_website'),
|
mock_func_factory(nominatim.tools.refresh, 'setup_website'),
|
||||||
@@ -321,7 +321,7 @@ class TestCliWithDb:
|
|||||||
assert func.called == 1
|
assert func.called == 1
|
||||||
|
|
||||||
@pytest.mark.parametrize("command,func", [
|
@pytest.mark.parametrize("command,func", [
|
||||||
('address-levels', 'load_address_levels_from_file'),
|
('address-levels', 'load_address_levels_from_config'),
|
||||||
('wiki-data', 'import_wikipedia_articles'),
|
('wiki-data', 'import_wikipedia_articles'),
|
||||||
('importance', 'recompute_importance'),
|
('importance', 'recompute_importance'),
|
||||||
('website', 'setup_website'),
|
('website', 'setup_website'),
|
||||||
|
|||||||
@@ -6,28 +6,31 @@ from pathlib import Path
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from nominatim.tools.refresh import load_address_levels, load_address_levels_from_file
|
from nominatim.tools.refresh import load_address_levels, load_address_levels_from_config
|
||||||
|
|
||||||
def test_load_ranks_def_config(temp_db_conn, temp_db_cursor, def_config):
|
def test_load_ranks_def_config(temp_db_conn, temp_db_cursor, def_config):
|
||||||
load_address_levels_from_file(temp_db_conn, Path(def_config.ADDRESS_LEVEL_CONFIG))
|
load_address_levels_from_config(temp_db_conn, def_config)
|
||||||
|
|
||||||
assert temp_db_cursor.table_rows('address_levels') > 0
|
assert temp_db_cursor.table_rows('address_levels') > 0
|
||||||
|
|
||||||
def test_load_ranks_from_file(temp_db_conn, temp_db_cursor, tmp_path):
|
def test_load_ranks_from_project_dir(def_config, temp_db_conn, temp_db_cursor,
|
||||||
test_file = tmp_path / 'test_levels.json'
|
tmp_path):
|
||||||
|
test_file = tmp_path / 'address-levels.json'
|
||||||
test_file.write_text('[{"tags":{"place":{"sea":2}}}]')
|
test_file.write_text('[{"tags":{"place":{"sea":2}}}]')
|
||||||
|
def_config.project_dir = tmp_path
|
||||||
|
|
||||||
load_address_levels_from_file(temp_db_conn, test_file)
|
load_address_levels_from_config(temp_db_conn, def_config)
|
||||||
|
|
||||||
assert temp_db_cursor.table_rows('address_levels') > 0
|
assert temp_db_cursor.table_rows('address_levels') == 1
|
||||||
|
|
||||||
|
|
||||||
def test_load_ranks_from_broken_file(temp_db_conn, tmp_path):
|
def test_load_ranks_from_broken_file(def_config, temp_db_conn, tmp_path):
|
||||||
test_file = tmp_path / 'test_levels.json'
|
test_file = tmp_path / 'address-levels.json'
|
||||||
test_file.write_text('[{"tags":"place":{"sea":2}}}]')
|
test_file.write_text('[{"tags":"place":{"sea":2}}}]')
|
||||||
|
def_config.project_dir = tmp_path
|
||||||
|
|
||||||
with pytest.raises(json.decoder.JSONDecodeError):
|
with pytest.raises(json.decoder.JSONDecodeError):
|
||||||
load_address_levels_from_file(temp_db_conn, test_file)
|
load_address_levels_from_config(temp_db_conn, def_config)
|
||||||
|
|
||||||
|
|
||||||
def test_load_ranks_country(temp_db_conn, temp_db_cursor):
|
def test_load_ranks_country(temp_db_conn, temp_db_cursor):
|
||||||
|
|||||||
Reference in New Issue
Block a user