From 507fdd4f40ea9a7fe77b90847d8e6e90a3cbbbd0 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Fri, 22 Oct 2021 16:49:57 +0200 Subject: [PATCH] switch IMPORT_STYLE to use generic file search Allows relative paths wrt project directory. --- docs/customize/Settings.md | 10 +++++++--- nominatim/config.py | 2 +- test/python/test_config.py | 19 +++++++++++++++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/customize/Settings.md b/docs/customize/Settings.md index a71b2e1b..3a45e8fe 100644 --- a/docs/customize/Settings.md +++ b/docs/customize/Settings.md @@ -328,9 +328,13 @@ project directory and then in the global settings directory. | **Default:** | extratags | The _style configuration_ describes which OSM objects and tags are taken -into consideration for the search database. This setting may either -be a string pointing to one of the internal styles or it may be a path -pointing to a custom style. +into consideration for the search database. Nominatim comes with a set +of pre-configured styles, that may be configured here. + +You can also write your own custom style and point the setting to the file +with the style. When a relative path is given, then the style file is searched +first relative to the project directory and then in the global settings +directory. See [Import Styles](Import-Styles.md) for more information on the available internal styles and the format of the diff --git a/nominatim/config.py b/nominatim/config.py index 28f2fcc3..66375f6c 100644 --- a/nominatim/config.py +++ b/nominatim/config.py @@ -123,7 +123,7 @@ class Configuration: if style in ('admin', 'street', 'address', 'full', 'extratags'): return self.config_dir / 'import-{}.style'.format(style) - return Path(style) + return self.find_config_file('', 'IMPORT_STYLE') def get_os_env(self): diff --git a/test/python/test_config.py b/test/python/test_config.py index 8b5cb11b..de7b9301 100644 --- a/test/python/test_config.py +++ b/test/python/test_config.py @@ -176,13 +176,24 @@ def test_get_import_style_intern(make_config, src_dir, monkeypatch): assert config.get_import_style_file() == expected -@pytest.mark.parametrize("value", ['custom', '/foo/bar.stye']) -def test_get_import_style_extern(make_config, monkeypatch, value): +def test_get_import_style_extern_relative(make_config_path, monkeypatch): + config = make_config_path() + (config.project_dir / 'custom.style').write_text('x') + + monkeypatch.setenv('NOMINATIM_IMPORT_STYLE', 'custom.style') + + assert str(config.get_import_style_file()) == str(config.project_dir / 'custom.style') + + +def test_get_import_style_extern_absolute(make_config, tmp_path, monkeypatch): config = make_config() + cfgfile = tmp_path / 'test.style' + + cfgfile.write_text('x') - monkeypatch.setenv('NOMINATIM_IMPORT_STYLE', value) + monkeypatch.setenv('NOMINATIM_IMPORT_STYLE', str(cfgfile)) - assert str(config.get_import_style_file()) == value + assert str(config.get_import_style_file()) == str(cfgfile) def test_load_subconf_from_project_dir(make_config_path): -- 2.39.5