reorganize api submodule

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.
This commit is contained in:
Sarah Hoffmann
2023-01-24 13:28:04 +01:00
parent e56957f047
commit 32c1e59622
11 changed files with 36 additions and 22 deletions

19
nominatim/api/__init__.py Normal file
View File

@@ -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)

View File

@@ -17,7 +17,7 @@ import sqlalchemy.ext.asyncio as sa_asyncio
import asyncpg import asyncpg
from nominatim.config import Configuration from nominatim.config import Configuration
from nominatim.apicmd.status import get_status, StatusResult from nominatim.api.status import get_status, StatusResult
class NominatimAPIAsync: class NominatimAPIAsync:
""" API loader asynchornous version. """ API loader asynchornous version.

View File

@@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Subcommand definitions for API calls from the command line. 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.tools.exec_utils import run_api_script
from nominatim.errors import UsageError from nominatim.errors import UsageError
from nominatim.clicmd.args import NominatimArgs from nominatim.clicmd.args import NominatimArgs
from nominatim.api import NominatimAPI from nominatim.api import NominatimAPI, StatusResult
from nominatim.apicmd.status import StatusResult
import nominatim.result_formatter.v1 as formatting import nominatim.result_formatter.v1 as formatting
# Do not repeat documentation of subcommand classes. # Do not repeat documentation of subcommand classes.

View File

@@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Output formatters for API version v1. Output formatters for API version v1.
@@ -12,7 +12,7 @@ from collections import OrderedDict
import json import json
from nominatim.result_formatter.base import FormatDispatcher from nominatim.result_formatter.base import FormatDispatcher
from nominatim.apicmd.status import StatusResult from nominatim.api import StatusResult
create = FormatDispatcher() create = FormatDispatcher()

View File

@@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Server implementation using the falcon webserver framework. Server implementation using the falcon webserver framework.
@@ -13,8 +13,7 @@ from pathlib import Path
import falcon import falcon
import falcon.asgi import falcon.asgi
from nominatim.api import NominatimAPIAsync from nominatim.api import NominatimAPIAsync, StatusResult
from nominatim.apicmd.status import StatusResult
import nominatim.result_formatter.v1 as formatting import nominatim.result_formatter.v1 as formatting
CONTENT_TYPE = { CONTENT_TYPE = {

View File

@@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Server implementation using the sanic webserver framework. Server implementation using the sanic webserver framework.
@@ -12,8 +12,7 @@ from pathlib import Path
import sanic import sanic
from nominatim.api import NominatimAPIAsync from nominatim.api import NominatimAPIAsync, StatusResult
from nominatim.apicmd.status import StatusResult
import nominatim.result_formatter.v1 as formatting import nominatim.result_formatter.v1 as formatting
api = sanic.Blueprint('NominatimAPI') api = sanic.Blueprint('NominatimAPI')

View File

@@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Server implementation using the starlette webserver framework. Server implementation using the starlette webserver framework.
@@ -16,8 +16,7 @@ from starlette.exceptions import HTTPException
from starlette.responses import Response from starlette.responses import Response
from starlette.requests import Request from starlette.requests import Request
from nominatim.api import NominatimAPIAsync from nominatim.api import NominatimAPIAsync, StatusResult
from nominatim.apicmd.status import StatusResult
import nominatim.result_formatter.v1 as formatting import nominatim.result_formatter.v1 as formatting
CONTENT_TYPE = { CONTENT_TYPE = {

View File

@@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Tests for API access commands of command-line interface wrapper. Tests for API access commands of command-line interface wrapper.
@@ -11,8 +11,7 @@ import json
import pytest import pytest
import nominatim.clicmd.api import nominatim.clicmd.api
import nominatim.api import nominatim.api as napi
from nominatim.apicmd.status import StatusResult
@pytest.mark.parametrize("endpoint", (('search', 'reverse', 'lookup', 'details', 'status'))) @pytest.mark.parametrize("endpoint", (('search', 'reverse', 'lookup', 'details', 'status')))
@@ -61,8 +60,8 @@ class TestCliStatusCall:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup_status_mock(self, monkeypatch): def setup_status_mock(self, monkeypatch):
monkeypatch.setattr(nominatim.api.NominatimAPI, 'status', monkeypatch.setattr(napi.NominatimAPI, 'status',
lambda self: StatusResult(200, 'OK')) lambda self: napi.StatusResult(200, 'OK'))
def test_status_simple(self, cli_call, tmp_path): def test_status_simple(self, cli_call, tmp_path):

View File

@@ -2,7 +2,7 @@
# #
# This file is part of Nominatim. (https://nominatim.org) # 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. # For a full list of authors see the git log.
""" """
Tests for formatting results for the V1 API. Tests for formatting results for the V1 API.
@@ -11,7 +11,7 @@ import datetime as dt
import pytest import pytest
import nominatim.result_formatter.v1 as format_module 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 from nominatim.version import NOMINATIM_VERSION
STATUS_FORMATS = {'text', 'json'} STATUS_FORMATS = {'text', 'json'}