]> git.openstreetmap.org Git - nominatim.git/commitdiff
add Python package configuration
authorSarah Hoffmann <lonvia@denofr.de>
Mon, 13 May 2024 22:05:36 +0000 (00:05 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Wed, 26 Jun 2024 09:52:47 +0000 (11:52 +0200)
The global configuration builds one large package.

.gitignore
nominatim/__main__.py [new file with mode: 0644]
nominatim/config.py
nominatim/tools/exec_utils.py
nominatim/version.py
pyproject.toml [new file with mode: 0644]
wheel_build/nominatim/paths.py [new file with mode: 0644]
wheel_build/shared/scripts/nominatim [new file with mode: 0755]

index b7e77f54c2b3b5442b43f42dfafa8ea60a2ebe45..0b0d2c45eaff6487422a8faaa83272ccf64a8bc9 100644 (file)
@@ -4,6 +4,8 @@
 docs/develop/*.png
 
 build
 docs/develop/*.png
 
 build
+dist
+.coverage
 
 .vagrant
 data/country_osm_grid.sql.gz
 
 .vagrant
 data/country_osm_grid.sql.gz
diff --git a/nominatim/__main__.py b/nominatim/__main__.py
new file mode 100644 (file)
index 0000000..b211afa
--- /dev/null
@@ -0,0 +1,4 @@
+if __name__ == '__main__':
+    from nominatim import cli
+
+    exit(cli.nominatim(module_dir=None, osm2pgsql_path=None))
index 3344a425a5667d58f6e2cd79e916f0b9bbb8c839..6bfc6076a89fe799170af016cd42e8894edb5c8f 100644 (file)
@@ -83,7 +83,7 @@ class Configuration:
         """ Set paths to library functions and data.
         """
         for key, value in kwargs.items():
         """ Set paths to library functions and data.
         """
         for key, value in kwargs.items():
-            setattr(self.lib_dir, key, Path(value))
+            setattr(self.lib_dir, key, None if value is None else Path(value))
 
 
     def __getattr__(self, name: str) -> str:
 
 
     def __getattr__(self, name: str) -> str:
index db89c38947d35a17f6e75a0964ea3b48a5aaa4ce..9bf28a03c3f924ee58e801803d40f527bafc1f74 100644 (file)
@@ -11,6 +11,7 @@ from typing import Any, Mapping, IO
 import logging
 import os
 import subprocess
 import logging
 import os
 import subprocess
+import shutil
 import urllib.request as urlrequest
 
 from nominatim.typing import StrPath
 import urllib.request as urlrequest
 
 from nominatim.typing import StrPath
@@ -30,7 +31,14 @@ def run_osm2pgsql(options: Mapping[str, Any]) -> None:
     """ Run osm2pgsql with the given options.
     """
     env = get_pg_env(options['dsn'])
     """ Run osm2pgsql with the given options.
     """
     env = get_pg_env(options['dsn'])
-    cmd = [str(options['osm2pgsql']),
+
+    osm2pgsql_cmd = options['osm2pgsql']
+    if osm2pgsql_cmd is None:
+        osm2pgsql_cmd = shutil.which('osm2pgsql')
+        if osm2pgsql_cmd is None:
+            raise RuntimeError('osm2pgsql executable not found. Please install osm2pgsql first.')
+
+    cmd = [str(osm2pgsql_cmd),
            '--slim',
            '--log-progress', 'true',
            '--number-processes', '1' if options['append'] else str(options['threads']),
            '--slim',
            '--log-progress', 'true',
            '--number-processes', '1' if options['append'] else str(options['threads']),
index 9ef22a8792426a18abea2c5cab5c83047051ad84..2ece2d795ab90112f64b9c4ad3dc7a4999b4cb7d 100644 (file)
@@ -33,6 +33,12 @@ class NominatimVersion(NamedTuple):
     def __str__(self) -> str:
         return f"{self.major}.{self.minor}.{self.patch_level}-{self.db_patch_level}"
 
     def __str__(self) -> str:
         return f"{self.major}.{self.minor}.{self.patch_level}-{self.db_patch_level}"
 
+    def release_version(self) -> str:
+        """ Return the release version in semantic versioning format.
+
+            The release version does not include the database patch version.
+        """
+        return f"{self.major}.{self.minor}.{self.patch_level}"
 
 NOMINATIM_VERSION = NominatimVersion(4, 4, 99, 1)
 
 
 NOMINATIM_VERSION = NominatimVersion(4, 4, 99, 1)
 
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644 (file)
index 0000000..3433f69
--- /dev/null
@@ -0,0 +1,61 @@
+[project]
+name = "nominatim"
+description = "A tool for building a database of OpenStreetMap for geocoding and for searching the database."
+readme = "README.md"
+requires-python = ">=3.7"
+license = 'GPL-3.0-or-later'
+maintainers = [
+  { name = "Sarah Hoffmann", email = "lonvia@denofr.de" }
+]
+keywords = [ "geocoding", "OpenStreetMap", "search" ]
+classifiers = [
+    "Programming Language :: Python :: 3",
+    "License :: OSI Approved :: GNU General Public License (GPL)",
+    "Operating System :: OS Independent",
+]
+dependencies = [
+    "psycopg2",
+    "python-dotenv",
+    "psutil",
+    "jinja2",
+    "SQLAlchemy>=1.4.31",
+    "asyncpg>=0.8",
+    "PyICU",
+    "pyYAML>=5.1",
+    "datrie"
+]
+dynamic = ["version"]
+
+[project.urls]
+Homepage = "https://nominatim.org"
+Issues = "https://github.com/osm-search/Nominatim/issues"
+
+[build-system]
+requires = ["hatchling"]
+build-backend = "hatchling.build"
+
+[tool.hatch.version]
+source = "code"
+path = "nominatim/version.py"
+expression = "NOMINATIM_VERSION.release_version()"
+
+[tool.hatch.build.targets.sdist]
+only-include = ["nominatim", "lib-sql", "settings",
+                "docs", "man", "data", "munin",
+                "test/python", "test/bdd", "test/testdata", "test/testdb"]
+artifacts = ["data/country_osm_grid.sql.gz"]
+
+[tool.hatch.build.targets.wheel]
+only-include = ["nominatim", "lib-sql", "settings",
+                "data/words.sql", "data/country_osm_grid.sql.gz",
+                "wheel_build/nominatim"]
+exclude = ["nominatim/paths.py"]
+
+[tool.hatch.build.targets.wheel.shared-scripts]
+"wheel_build/shared/scripts" = "/"
+
+[tool.hatch.build.targets.wheel.sources]
+"wheel_build/nominatim" = "nominatim"
+"lib-sql" = "nominatim/resources/lib-sql"
+"settings" = "nominatim/resources/settings"
+"data" = "nominatim/resources"
diff --git a/wheel_build/nominatim/paths.py b/wheel_build/nominatim/paths.py
new file mode 100644 (file)
index 0000000..2294834
--- /dev/null
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of Nominatim. (https://nominatim.org)
+#
+# Copyright (C) 2024 by the Nominatim developer community.
+# For a full list of authors see the git log.
+"""
+Path settings for extra data used by Nominatim.
+"""
+from pathlib import Path
+
+PHPLIB_DIR = None
+DATA_DIR = (Path(__file__) / '..' / 'resources').resolve()
+SQLLIB_DIR = (DATA_DIR / 'lib-sql')
+CONFIG_DIR = (DATA_DIR / 'settings')
diff --git a/wheel_build/shared/scripts/nominatim b/wheel_build/shared/scripts/nominatim
new file mode 100755 (executable)
index 0000000..e12f77d
--- /dev/null
@@ -0,0 +1,5 @@
+#!python3
+
+from nominatim import cli
+
+exit(cli.nominatim(module_dir=None, osm2pgsql_path=None))