]> git.openstreetmap.org Git - nominatim.git/commitdiff
reorganize api submodule
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 24 Jan 2023 12:28:04 +0000 (13:28 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 24 Jan 2023 12:28:04 +0000 (13:28 +0100)
Use a directory for the submodule where the __init__ file contains
the public API. This makes it easier to separate public interface
from the internal implementation.

nominatim/api/__init__.py [new file with mode: 0644]
nominatim/api/core.py [moved from nominatim/api.py with 98% similarity]
nominatim/api/status.py [moved from nominatim/apicmd/status.py with 100% similarity]
nominatim/apicmd/__init__.py [deleted file]
nominatim/clicmd/api.py
nominatim/result_formatter/v1.py
nominatim/server/falcon/server.py
nominatim/server/sanic/server.py
nominatim/server/starlette/server.py
test/python/cli/test_cmd_api.py
test/python/result_formatter/test_v1.py

diff --git a/nominatim/api/__init__.py b/nominatim/api/__init__.py
new file mode 100644 (file)
index 0000000..f418e66
--- /dev/null
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of Nominatim. (https://nominatim.org)
+#
+# Copyright (C) 2023 by the Nominatim developer community.
+# For a full list of authors see the git log.
+"""
+The public interface of the Nominatim library.
+
+Classes and functions defined in this file are considered stable. Always
+import from this file, not from the source files directly.
+"""
+
+# See also https://github.com/PyCQA/pylint/issues/6006
+# pylint: disable=useless-import-alias
+
+from nominatim.api.core import (NominatimAPI as NominatimAPI,
+                                NominatimAPIAsync as NominatimAPIAsync)
+from nominatim.api.status import (StatusResult as StatusResult)
similarity index 98%
rename from nominatim/api.py
rename to nominatim/api/core.py
index 4ce89595994637dc6d74fc0984b31100948cea5e..159229dd89d67d99383787bd0ccd1a1055c8e020 100644 (file)
@@ -17,7 +17,7 @@ import sqlalchemy.ext.asyncio as sa_asyncio
 import asyncpg
 
 from nominatim.config import Configuration
-from nominatim.apicmd.status import get_status, StatusResult
+from nominatim.api.status import get_status, StatusResult
 
 class NominatimAPIAsync:
     """ API loader asynchornous version.
diff --git a/nominatim/apicmd/__init__.py b/nominatim/apicmd/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
index e2b903c73defa60d2444aa44b1dca59a9b572946..050665f896c72b980831100b5da992efc6f5ad9d 100644 (file)
@@ -2,7 +2,7 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2023 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Subcommand definitions for API calls from the command line.
@@ -14,8 +14,7 @@ import logging
 from nominatim.tools.exec_utils import run_api_script
 from nominatim.errors import UsageError
 from nominatim.clicmd.args import NominatimArgs
-from nominatim.api import NominatimAPI
-from nominatim.apicmd.status import StatusResult
+from nominatim.api import NominatimAPI, StatusResult
 import nominatim.result_formatter.v1 as formatting
 
 # Do not repeat documentation of subcommand classes.
index 1d437af7ed667a92247088c35cb316faa3b86874..9114d45feed4541cc4a6b25b4d6c6ed51f9c66c2 100644 (file)
@@ -2,7 +2,7 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2023 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Output formatters for API version v1.
@@ -12,7 +12,7 @@ from collections import OrderedDict
 import json
 
 from nominatim.result_formatter.base import FormatDispatcher
-from nominatim.apicmd.status import StatusResult
+from nominatim.api import StatusResult
 
 create = FormatDispatcher()
 
index 81e6ed396846d34cd47f534231ade5ab8da03a7b..c56034b53127e57c920a157b0bb95f965d6fa120 100644 (file)
@@ -2,7 +2,7 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2023 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Server implementation using the falcon webserver framework.
@@ -13,8 +13,7 @@ from pathlib import Path
 import falcon
 import falcon.asgi
 
-from nominatim.api import NominatimAPIAsync
-from nominatim.apicmd.status import StatusResult
+from nominatim.api import NominatimAPIAsync, StatusResult
 import nominatim.result_formatter.v1 as formatting
 
 CONTENT_TYPE = {
index 74841f3f798298a68a78339a3ac24cb09b64ef90..797157af0844fdf5ec2c0e82d8408384d1bd488f 100644 (file)
@@ -2,7 +2,7 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2023 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Server implementation using the sanic webserver framework.
@@ -12,8 +12,7 @@ from pathlib import Path
 
 import sanic
 
-from nominatim.api import NominatimAPIAsync
-from nominatim.apicmd.status import StatusResult
+from nominatim.api import NominatimAPIAsync, StatusResult
 import nominatim.result_formatter.v1 as formatting
 
 api = sanic.Blueprint('NominatimAPI')
index 41ad899c9908769b970455faab3ffd159e8c688f..e6dbbc782a71439a29200a6802f3a23a8b6baeec 100644 (file)
@@ -2,7 +2,7 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2023 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Server implementation using the starlette webserver framework.
@@ -16,8 +16,7 @@ from starlette.exceptions import HTTPException
 from starlette.responses import Response
 from starlette.requests import Request
 
-from nominatim.api import NominatimAPIAsync
-from nominatim.apicmd.status import StatusResult
+from nominatim.api import NominatimAPIAsync, StatusResult
 import nominatim.result_formatter.v1 as formatting
 
 CONTENT_TYPE = {
index 4031441f4032245d4527984e661cf33a869ed83a..b0c2411f845c3f19661f9bb9f8007af97380108c 100644 (file)
@@ -2,7 +2,7 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2023 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Tests for API access commands of command-line interface wrapper.
@@ -11,8 +11,7 @@ import json
 import pytest
 
 import nominatim.clicmd.api
-import nominatim.api
-from nominatim.apicmd.status import StatusResult
+import nominatim.api as napi
 
 
 @pytest.mark.parametrize("endpoint", (('search', 'reverse', 'lookup', 'details', 'status')))
@@ -61,8 +60,8 @@ class TestCliStatusCall:
 
     @pytest.fixture(autouse=True)
     def setup_status_mock(self, monkeypatch):
-        monkeypatch.setattr(nominatim.api.NominatimAPI, 'status',
-                            lambda self: StatusResult(200, 'OK'))
+        monkeypatch.setattr(napi.NominatimAPI, 'status',
+                            lambda self: napi.StatusResult(200, 'OK'))
 
 
     def test_status_simple(self, cli_call, tmp_path):
index 919f5b8091e988956f782d1d9ff8d6b7d06778a3..fc5a36717f9c5498fd8d51a8de9822b1d8b9ebf1 100644 (file)
@@ -2,7 +2,7 @@
 #
 # This file is part of Nominatim. (https://nominatim.org)
 #
-# Copyright (C) 2022 by the Nominatim developer community.
+# Copyright (C) 2023 by the Nominatim developer community.
 # For a full list of authors see the git log.
 """
 Tests for formatting results for the V1 API.
@@ -11,7 +11,7 @@ import datetime as dt
 import pytest
 
 import nominatim.result_formatter.v1 as format_module
-from nominatim.apicmd.status import StatusResult
+from nominatim.api import StatusResult
 from nominatim.version import NOMINATIM_VERSION
 
 STATUS_FORMATS = {'text', 'json'}