From 4760e8341b85df3d2b6f8e62b561cf343dbce352 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 5 Dec 2024 15:19:36 +0100 Subject: [PATCH] move lua scripts into a separate directory --- .github/workflows/ci-tests.yml | 5 +---- {settings => lib-lua}/flex-base.lua | 0 {settings => lib-lua}/import-address.lua | 0 {settings => lib-lua}/import-admin.lua | 0 {settings => lib-lua}/import-extratags.lua | 0 {settings => lib-lua}/import-full.lua | 0 {settings => lib-lua}/import-street.lua | 0 {settings => lib-lua}/taginfo.lua | 3 ++- packaging/nominatim-api/extra_src/paths.py | 1 + packaging/nominatim-db/extra_src/nominatim_db/paths.py | 1 + packaging/nominatim-db/lib-lua | 1 + packaging/nominatim-db/pyproject.toml | 2 ++ src/nominatim_db/clicmd/args.py | 2 +- src/nominatim_db/config.py | 3 ++- src/nominatim_db/paths.py | 1 + test/bdd/steps/steps_osm_data.py | 2 +- test/python/config/test_config.py | 2 +- 17 files changed, 14 insertions(+), 9 deletions(-) rename {settings => lib-lua}/flex-base.lua (100%) rename {settings => lib-lua}/import-address.lua (100%) rename {settings => lib-lua}/import-admin.lua (100%) rename {settings => lib-lua}/import-extratags.lua (100%) rename {settings => lib-lua}/import-full.lua (100%) rename {settings => lib-lua}/import-street.lua (100%) rename {settings => lib-lua}/taginfo.lua (95%) create mode 120000 packaging/nominatim-db/lib-lua diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 8b38d3dc..f453aefb 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -185,9 +185,6 @@ jobs: - name: Prepare import environment run: | mv Nominatim/test/testdb/apidb-test-data.pbf test.pbf - mv Nominatim/settings/flex-base.lua flex-base.lua - mv Nominatim/settings/import-extratags.lua import-extratags.lua - mv Nominatim/settings/taginfo.lua taginfo.lua rm -rf Nominatim mkdir data-env-reverse working-directory: /home/nominatim @@ -205,7 +202,7 @@ jobs: working-directory: /home/nominatim/nominatim-project - name: Print taginfo - run: lua taginfo.lua + run: lua ./nominatim-venv/lib/*/site-packages/nominatim_db/resources/lib-lua/taginfo.lua working-directory: /home/nominatim - name: Collect host OS information diff --git a/settings/flex-base.lua b/lib-lua/flex-base.lua similarity index 100% rename from settings/flex-base.lua rename to lib-lua/flex-base.lua diff --git a/settings/import-address.lua b/lib-lua/import-address.lua similarity index 100% rename from settings/import-address.lua rename to lib-lua/import-address.lua diff --git a/settings/import-admin.lua b/lib-lua/import-admin.lua similarity index 100% rename from settings/import-admin.lua rename to lib-lua/import-admin.lua diff --git a/settings/import-extratags.lua b/lib-lua/import-extratags.lua similarity index 100% rename from settings/import-extratags.lua rename to lib-lua/import-extratags.lua diff --git a/settings/import-full.lua b/lib-lua/import-full.lua similarity index 100% rename from settings/import-full.lua rename to lib-lua/import-full.lua diff --git a/settings/import-street.lua b/lib-lua/import-street.lua similarity index 100% rename from settings/import-street.lua rename to lib-lua/import-street.lua diff --git a/settings/taginfo.lua b/lib-lua/taginfo.lua similarity index 95% rename from settings/taginfo.lua rename to lib-lua/taginfo.lua index ef2ad2a6..fddaf298 100644 --- a/settings/taginfo.lua +++ b/lib-lua/taginfo.lua @@ -6,7 +6,8 @@ osm2pgsql = {} function osm2pgsql.define_table(...) end -- provide path to flex-style lua file -flex = require('import-extratags') +package.path = arg[0]:match("(.*/)") .. "?.lua;" .. package.path +local flex = require('import-extratags') local json = require ('dkjson') diff --git a/packaging/nominatim-api/extra_src/paths.py b/packaging/nominatim-api/extra_src/paths.py index 797acbb5..7d186da1 100644 --- a/packaging/nominatim-api/extra_src/paths.py +++ b/packaging/nominatim-api/extra_src/paths.py @@ -11,4 +11,5 @@ from pathlib import Path DATA_DIR = None SQLLIB_DIR = None +LUALIB_DIR = None CONFIG_DIR = (Path(__file__) / '..' / 'resources' / 'settings').resolve() diff --git a/packaging/nominatim-db/extra_src/nominatim_db/paths.py b/packaging/nominatim-db/extra_src/nominatim_db/paths.py index 796ff08b..02df5047 100644 --- a/packaging/nominatim-db/extra_src/nominatim_db/paths.py +++ b/packaging/nominatim-db/extra_src/nominatim_db/paths.py @@ -11,4 +11,5 @@ from pathlib import Path DATA_DIR = (Path(__file__) / '..' / 'resources').resolve() SQLLIB_DIR = (DATA_DIR / 'lib-sql') +LUALIB_DIR = (DATA_DIR / 'lib-lua') CONFIG_DIR = (DATA_DIR / 'settings') diff --git a/packaging/nominatim-db/lib-lua b/packaging/nominatim-db/lib-lua new file mode 120000 index 00000000..e4e1bd04 --- /dev/null +++ b/packaging/nominatim-db/lib-lua @@ -0,0 +1 @@ +../../lib-lua \ No newline at end of file diff --git a/packaging/nominatim-db/pyproject.toml b/packaging/nominatim-db/pyproject.toml index 841845f0..c34ce937 100644 --- a/packaging/nominatim-db/pyproject.toml +++ b/packaging/nominatim-db/pyproject.toml @@ -44,6 +44,7 @@ include = [ "src/nominatim_db", "scripts", "lib-sql/**/*.sql", + "lib-lua/**/*.lua", "settings", "data/words.sql", "extra_src/nominatim_db/paths.py" @@ -65,6 +66,7 @@ packages = ["src/nominatim_db"] [tool.hatch.build.targets.wheel.force-include] "lib-sql" = "nominatim_db/resources/lib-sql" +"lib-lua" = "nominatim_db/resources/lib-lua" "settings" = "nominatim_db/resources/settings" "data/country_osm_grid.sql.gz" = "nominatim_db/resources/country_osm_grid.sql.gz" "data/words.sql" = "nominatim_db/resources/words.sql" diff --git a/src/nominatim_db/clicmd/args.py b/src/nominatim_db/clicmd/args.py index 488ecd18..a8ff210a 100644 --- a/src/nominatim_db/clicmd/args.py +++ b/src/nominatim_db/clicmd/args.py @@ -189,7 +189,7 @@ class NominatimArgs: return dict(osm2pgsql=self.config.OSM2PGSQL_BINARY or self.config.lib_dir.osm2pgsql, osm2pgsql_cache=self.osm2pgsql_cache or default_cache, osm2pgsql_style=self.config.get_import_style_file(), - osm2pgsql_style_path=self.config.config_dir, + osm2pgsql_style_path=self.config.lib_dir.lua, threads=self.threads or default_threads, dsn=self.config.get_libpq_dsn(), flatnode_file=str(self.config.get_path('FLATNODE_FILE') or ''), diff --git a/src/nominatim_db/config.py b/src/nominatim_db/config.py index ad54ab3d..ae59cfd3 100644 --- a/src/nominatim_db/config.py +++ b/src/nominatim_db/config.py @@ -75,6 +75,7 @@ class Configuration: class _LibDirs: osm2pgsql: Path sql = paths.SQLLIB_DIR + lua = paths.LUALIB_DIR data = paths.DATA_DIR self.lib_dir = _LibDirs() @@ -207,7 +208,7 @@ class Configuration: style = getattr(self, 'IMPORT_STYLE') if style in ('admin', 'street', 'address', 'full', 'extratags'): - return self.config_dir / f'import-{style}.lua' + return self.lib_dir.lua / f'import-{style}.lua' return self.find_config_file('', 'IMPORT_STYLE') diff --git a/src/nominatim_db/paths.py b/src/nominatim_db/paths.py index 2614fa14..ab34e4c0 100644 --- a/src/nominatim_db/paths.py +++ b/src/nominatim_db/paths.py @@ -10,5 +10,6 @@ Path settings for extra data used by Nominatim. from pathlib import Path SQLLIB_DIR = (Path(__file__) / '..' / '..' / '..' / 'lib-sql').resolve() +LUALIB_DIR = (Path(__file__) / '..' / '..' / '..' / 'lib-lua').resolve() DATA_DIR = (Path(__file__) / '..' / '..' / '..' / 'data').resolve() CONFIG_DIR = (Path(__file__) / '..' / '..' / '..' / 'settings').resolve() diff --git a/test/bdd/steps/steps_osm_data.py b/test/bdd/steps/steps_osm_data.py index 4cee75f7..70cf1515 100644 --- a/test/bdd/steps/steps_osm_data.py +++ b/test/bdd/steps/steps_osm_data.py @@ -19,7 +19,7 @@ def get_osm2pgsql_options(nominatim_env, fname, append): osm2pgsql='osm2pgsql', osm2pgsql_cache=50, osm2pgsql_style=str(nominatim_env.get_test_config().get_import_style_file()), - osm2pgsql_style_path=nominatim_env.get_test_config().config_dir, + osm2pgsql_style_path=nominatim_env.get_test_config().lib_dir.lua, threads=1, dsn=nominatim_env.get_libpq_dsn(), flatnode_file='', diff --git a/test/python/config/test_config.py b/test/python/config/test_config.py index 8f90b5da..9f68fcb9 100644 --- a/test/python/config/test_config.py +++ b/test/python/config/test_config.py @@ -222,7 +222,7 @@ def test_get_import_style_intern(make_config, src_dir, monkeypatch): monkeypatch.setenv('NOMINATIM_IMPORT_STYLE', 'street') - expected = src_dir / 'settings' / 'import-street.lua' + expected = src_dir / 'lib-lua' / 'import-street.lua' assert config.get_import_style_file() == expected -- 2.39.5