Skip to content

Commit 6d48213

Browse files
formatting and linting
1 parent 9d6a16e commit 6d48213

File tree

8 files changed

+63
-50
lines changed

8 files changed

+63
-50
lines changed

data_loader/data_loader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import requests
88

99
if len(sys.argv) != 2:
10-
print("Usage: python data_loader.py <opensearch|elasticsearch>")
11-
sys.exit(1)
10+
print("Usage: python data_loader.py <opensearch|elasticsearch>")
11+
sys.exit(1)
1212

1313
DATA_DIR = os.path.join(os.path.dirname(__file__), "setup_data/")
1414

@@ -18,7 +18,7 @@
1818
elif backend == "elasticsearch":
1919
STAC_API_BASE_URL = "http://localhost:8080"
2020
else:
21-
print("Invalid backend tag. Enter either 'opensearch' or 'elasticsearch'.")
21+
print("Invalid backend tag. Enter either 'opensearch' or 'elasticsearch'.")
2222

2323

2424
def load_data(filename):

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""FastAPI application."""
2+
import os
3+
24
from stac_fastapi.api.app import StacApi
35
from stac_fastapi.api.models import create_get_request_model, create_post_request_model
46
from stac_fastapi.elasticsearch.core import (
@@ -7,15 +9,17 @@
79
EsAsyncBaseFiltersClient,
810
TransactionsClient,
911
)
10-
import os
1112

12-
backend = os.getenv("BACKEND", "elasticsearch").lower()
13-
if backend == "opensearch":
13+
if os.getenv("BACKEND", "elasticsearch").lower() == "opensearch":
1414
from stac_fastapi.elasticsearch.config.config_opensearch import SearchSettings
15-
from stac_fastapi.elasticsearch.database_logic.database_logic_opensearch import create_collection_index
15+
from stac_fastapi.elasticsearch.database_logic.database_logic_opensearch import (
16+
create_collection_index,
17+
)
1618
else:
1719
from stac_fastapi.elasticsearch.config.config_elasticsearch import SearchSettings
18-
from stac_fastapi.elasticsearch.database_logic.database_logic_elasticsearch import create_collection_index
20+
from stac_fastapi.elasticsearch.database_logic.database_logic_elasticsearch import (
21+
create_collection_index,
22+
)
1923

2024
from stac_fastapi.elasticsearch.extensions import QueryExtension
2125
from stac_fastapi.elasticsearch.session import Session

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config/config_opensearch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Any, Dict, Set
55

66
from opensearchpy import AsyncOpenSearch, OpenSearch
7+
78
from stac_fastapi.types.config import ApiSettings
89

910

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Item crud client."""
22
import logging
3-
import re
43
import os
4+
import re
55
from base64 import urlsafe_b64encode
66
from datetime import datetime as datetime_type
77
from datetime import timezone
@@ -19,15 +19,17 @@
1919
from stac_pydantic.links import Relations
2020
from stac_pydantic.shared import MimeTypes
2121

22-
backend = os.getenv("BACKEND", "elasticsearch").lower()
23-
if backend == "opensearch":
24-
from stac_fastapi.elasticsearch.database_logic.database_logic_opensearch import DatabaseLogic
22+
if os.getenv("BACKEND", "elasticsearch").lower() == "opensearch":
2523
from stac_fastapi.elasticsearch.config.config_opensearch import SearchSettings
24+
from stac_fastapi.elasticsearch.database_logic.database_logic_opensearch import (
25+
DatabaseLogic,
26+
)
2627
else:
27-
from stac_fastapi.elasticsearch.database_logic.database_logic_elasticsearch import DatabaseLogic
28+
from stac_fastapi.elasticsearch.database_logic.database_logic_elasticsearch import (
29+
DatabaseLogic,
30+
)
2831
from stac_fastapi.elasticsearch.config.config_elasticsearch import SearchSettings
2932

30-
3133
from stac_fastapi.elasticsearch import serializers
3234
from stac_fastapi.elasticsearch.models.links import PagingLinks
3335
from stac_fastapi.elasticsearch.serializers import CollectionSerializer, ItemSerializer

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic/database_logic_elasticsearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
SearchSettings as SyncSearchSettings,
1616
)
1717
from stac_fastapi.elasticsearch.extensions import filter
18+
from stac_fastapi.elasticsearch.utilities import bbox2polygon
1819
from stac_fastapi.types.errors import ConflictError, NotFoundError
1920
from stac_fastapi.types.stac import Collection, Item
20-
from stac_fastapi.elasticsearch.utilities import bbox2polygon
2121

2222
logger = logging.getLogger(__name__)
2323

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic/database_logic_opensearch.py

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
from typing import Any, Dict, Iterable, List, Optional, Protocol, Tuple, Type, Union
77

88
import attr
9-
from opensearchpy.helpers.search import Search
10-
from opensearchpy.helpers.query import Q
11-
from opensearchpy import helpers, exceptions
9+
from opensearchpy import exceptions, helpers
1210
from opensearchpy.exceptions import TransportError
11+
from opensearchpy.helpers.query import Q
12+
from opensearchpy.helpers.search import Search
1313

1414
from stac_fastapi.elasticsearch import serializers
1515
from stac_fastapi.elasticsearch.config.config_opensearch import AsyncSearchSettings
1616
from stac_fastapi.elasticsearch.config.config_opensearch import (
1717
SearchSettings as SyncSearchSettings,
1818
)
1919
from stac_fastapi.elasticsearch.extensions import filter
20+
from stac_fastapi.elasticsearch.utilities import bbox2polygon
2021
from stac_fastapi.types.errors import ConflictError, NotFoundError
2122
from stac_fastapi.types.stac import Collection, Item
22-
from stac_fastapi.elasticsearch.utilities import bbox2polygon
2323

2424
logger = logging.getLogger(__name__)
2525

@@ -184,22 +184,19 @@ async def create_collection_index() -> None:
184184

185185
search_body = {
186186
"mappings": ES_COLLECTIONS_MAPPINGS,
187-
"aliases":{COLLECTIONS_INDEX: {}}
187+
"aliases": {COLLECTIONS_INDEX: {}},
188188
}
189189

190190
index = f"{COLLECTIONS_INDEX}-000001"
191191

192192
try:
193-
await client.indices.create(
194-
index=index,
195-
body=search_body
196-
)
193+
await client.indices.create(index=index, body=search_body)
197194
except TransportError as e:
198195
if e.status_code == 400:
199196
pass # Ignore 400 status codes
200197
else:
201-
raise e
202-
198+
raise e
199+
203200
await client.close()
204201

205202

@@ -217,22 +214,19 @@ async def create_item_index(collection_id: str):
217214
client = AsyncSearchSettings().create_client
218215
index_name = index_by_collection_id(collection_id)
219216
search_body = {
220-
"aliases":{index_name: {}},
221-
"mappings":ES_ITEMS_MAPPINGS,
222-
"settings":ES_ITEMS_SETTINGS,
217+
"aliases": {index_name: {}},
218+
"mappings": ES_ITEMS_MAPPINGS,
219+
"settings": ES_ITEMS_SETTINGS,
223220
}
224221

225222
try:
226-
await client.indices.create(
227-
index=f"{index_name}-000001",
228-
body=search_body
229-
)
223+
await client.indices.create(index=f"{index_name}-000001", body=search_body)
230224
except TransportError as e:
231225
if e.status_code == 400:
232226
pass # Ignore 400 status codes
233227
else:
234-
raise e
235-
228+
raise e
229+
236230
await client.close()
237231

238232

@@ -317,7 +311,9 @@ class DatabaseLogic:
317311
"""CORE LOGIC"""
318312

319313
async def get_all_collections(
320-
self, token: Optional[str], limit: int
314+
self,
315+
token: Optional[str],
316+
limit: int,
321317
) -> Iterable[Dict[str, Any]]:
322318
"""Retrieve a list of all collections from the database.
323319
@@ -333,16 +329,15 @@ async def get_all_collections(
333329
with the `COLLECTIONS_INDEX` as the target index and `size=limit` to retrieve records.
334330
The result is a generator of dictionaries containing the source data for each collection.
335331
"""
336-
search_body = {}
332+
search_body: Dict[str, Any] = {}
337333
if token:
338334
search_after = urlsafe_b64decode(token.encode()).decode().split(",")
339335
search_body["search_after"] = search_after
336+
340337
search_body["sort"] = {"id": {"order": "asc"}}
341-
338+
342339
collections = await self.client.search(
343-
index=COLLECTIONS_INDEX,
344-
body=search_body,
345-
size=limit
340+
index=COLLECTIONS_INDEX, body=search_body, size=limit
346341
)
347342
hits = collections["hits"]["hits"]
348343
return hits
@@ -545,14 +540,14 @@ async def execute_search(
545540
Raises:
546541
NotFoundError: If the collections specified in `collection_ids` do not exist.
547542
"""
548-
search_body = {}
543+
search_body: Dict[str, Any] = {}
549544
query = search.query.to_dict() if search.query else None
550545
if query:
551-
search_body["query"] = query
546+
search_body["query"] = query
552547
if token:
553548
search_after = urlsafe_b64decode(token.encode()).decode().split(",")
554549
search_body["search_after"] = search_after
555-
search_body["sort"] = sort if sort else DEFAULT_SORT
550+
search_body["sort"] = sort if sort else DEFAULT_SORT
556551

557552
index_param = indices(collection_ids)
558553

@@ -561,7 +556,7 @@ async def execute_search(
561556
index=index_param,
562557
ignore_unavailable=ignore_unavailable,
563558
body=search_body,
564-
size=limit
559+
size=limit,
565560
)
566561
)
567562

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/utilities.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
"""Module for geospatial processing functions.
2+
3+
This module contains functions for transforming geospatial coordinates,
4+
such as converting bounding boxes to polygon representations.
5+
"""
16
from typing import List
27

8+
39
def bbox2polygon(b0: float, b1: float, b2: float, b3: float) -> List[List[List[float]]]:
410
"""Transform a bounding box represented by its four coordinates `b0`, `b1`, `b2`, and `b3` into a polygon.
511

stac_fastapi/elasticsearch/tests/conftest.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111
from stac_fastapi.api.app import StacApi
1212
from stac_fastapi.api.models import create_get_request_model, create_post_request_model
1313

14-
backend = os.getenv("BACKEND", "elasticsearch").lower()
15-
if backend == "opensearch":
14+
if os.getenv("BACKEND", "elasticsearch").lower() == "opensearch":
1615
from stac_fastapi.elasticsearch.config.config_opensearch import AsyncSearchSettings
17-
from stac_fastapi.elasticsearch.database_logic.database_logic_opensearch import create_collection_index
16+
from stac_fastapi.elasticsearch.database_logic.database_logic_opensearch import (
17+
create_collection_index,
18+
)
1819
else:
19-
from stac_fastapi.elasticsearch.config.config_elasticsearch import AsyncSearchSettings
20-
from stac_fastapi.elasticsearch.database_logic.database_logic_elasticsearch import create_collection_index
20+
from stac_fastapi.elasticsearch.config.config_elasticsearch import (
21+
AsyncSearchSettings,
22+
)
23+
from stac_fastapi.elasticsearch.database_logic.database_logic_elasticsearch import (
24+
create_collection_index,
25+
)
2126

2227
from stac_fastapi.elasticsearch.core import (
2328
BulkTransactionsClient,

0 commit comments

Comments
 (0)