Skip to content

Commit

Permalink
make call_sync internal API
Browse files Browse the repository at this point in the history
  • Loading branch information
ischneider committed Dec 13, 2024
1 parent 9d16dd9 commit c53c578
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions planet/clients/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def __init__(self, session: Session, base_url: Optional[str] = None):
if self._base_url.endswith('/'):
self._base_url = self._base_url[:-1]

def call_sync(self, f: Awaitable[T]) -> T:
def _call_sync(self, f: Awaitable[T]) -> T:
"""block on an async function call, using the call_sync method of the session"""
return self._session.call_sync(f)
return self._session._call_sync(f)

@staticmethod
def _check_search_id(sid):
Expand Down
4 changes: 2 additions & 2 deletions planet/clients/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ def __init__(self, session: Session, base_url: Optional[str] = None):
if self._base_url.endswith('/'):
self._base_url = self._base_url[:-1]

def call_sync(self, f: Awaitable[T]) -> T:
def _call_sync(self, f: Awaitable[T]) -> T:
"""block on an async function call, using the call_sync method of the session"""
return self._session.call_sync(f)
return self._session._call_sync(f)

@staticmethod
def _check_order_id(oid):
Expand Down
4 changes: 2 additions & 2 deletions planet/clients/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def __init__(self,
if self._base_url.endswith('/'):
self._base_url = self._base_url[:-1]

def call_sync(self, f: Awaitable[T]) -> T:
def _call_sync(self, f: Awaitable[T]) -> T:
"""block on an async function call, using the call_sync method of the session"""
return self._session.call_sync(f)
return self._session._call_sync(f)

async def list_subscriptions(
self,
Expand Down
2 changes: 1 addition & 1 deletion planet/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def _start_background_loop(loop):
daemon=True)
self._loop_thread.start()

def call_sync(self, f: Awaitable[T]) -> T:
def _call_sync(self, f: Awaitable[T]) -> T:
return asyncio.run_coroutine_threadsafe(f, self._loop).result()

@classmethod
Expand Down
26 changes: 13 additions & 13 deletions planet/sync/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def search(

try:
while True:
yield self._client.call_sync(results.__anext__())
yield self._client._call_sync(results.__anext__())
except StopAsyncIteration:
pass

Expand Down Expand Up @@ -125,7 +125,7 @@ def create_search(
Raises:
planet.exceptions.APIError: On API error.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.create_search(item_types,
search_filter,
name,
Expand All @@ -152,7 +152,7 @@ def update_search(self,
Returns:
Description of the saved search.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.update_search(search_id,
item_types,
search_filter,
Expand Down Expand Up @@ -184,7 +184,7 @@ def list_searches(self,

try:
while True:
yield self._client.call_sync(results.__anext__())
yield self._client._call_sync(results.__anext__())
except StopAsyncIteration:
pass

Expand All @@ -197,7 +197,7 @@ def delete_search(self, search_id: str):
Raises:
planet.exceptions.APIError: On API error.
"""
return self._client.call_sync(self._client.delete_search(search_id))
return self._client._call_sync(self._client.delete_search(search_id))

def get_search(self, search_id: str) -> Dict:
"""Get a saved search by id.
Expand All @@ -211,7 +211,7 @@ def get_search(self, search_id: str) -> Dict:
Raises:
planet.exceptions.APIError: On API error.
"""
return self._client.call_sync(self._client.get_search(search_id))
return self._client._call_sync(self._client.get_search(search_id))

def run_search(self,
search_id: str,
Expand Down Expand Up @@ -243,7 +243,7 @@ def run_search(self,

try:
while True:
yield self._client.call_sync(results.__anext__())
yield self._client._call_sync(results.__anext__())
except StopAsyncIteration:
pass

Expand All @@ -266,7 +266,7 @@ def get_stats(self,
planet.exceptions.APIError: On API error.
planet.exceptions.ClientError: If interval is not valid.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.get_stats(item_types, search_filter, interval))

def list_item_assets(self, item_type_id: str,
Expand All @@ -288,7 +288,7 @@ def list_item_assets(self, item_type_id: str,
Raises:
planet.exceptions.APIError: On API error.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.list_item_assets(item_type_id, item_id))

def get_asset(self, item_type_id: str, item_id: str,
Expand All @@ -308,7 +308,7 @@ def get_asset(self, item_type_id: str, item_id: str,
planet.exceptions.ClientError: If asset type identifier is not
valid.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.get_asset(item_type_id, item_id, asset_type_id))

def activate_asset(self, asset: Dict[str, Any]):
Expand All @@ -322,7 +322,7 @@ def activate_asset(self, asset: Dict[str, Any]):
planet.exceptions.ClientError: If asset description is not
valid.
"""
return self._client.call_sync(self._client.activate_asset(asset))
return self._client._call_sync(self._client.activate_asset(asset))

def wait_asset(
self,
Expand Down Expand Up @@ -352,7 +352,7 @@ def wait_asset(
not available or if the maximum number of attempts is reached
before the asset is active.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.wait_asset(asset, delay, max_attempts, callback))

def download_asset(self,
Expand Down Expand Up @@ -385,7 +385,7 @@ def download_asset(self,
planet.exceptions.ClientError: If asset is not active or asset
description is not valid.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.download_asset(asset,
filename,
directory,
Expand Down
18 changes: 9 additions & 9 deletions planet/sync/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def main():
Raises:
planet.exceptions.APIError: On API error.
"""
return self._client.call_sync(self._client.create_order(request))
return self._client._call_sync(self._client.create_order(request))

def get_order(self, order_id: str) -> Dict:
"""Get order details by Order ID.
Expand All @@ -78,7 +78,7 @@ def get_order(self, order_id: str) -> Dict:
planet.exceptions.ClientError: If order_id is not a valid UUID.
planet.exceptions.APIError: On API error.
"""
return self._client.call_sync(self._client.get_order(order_id))
return self._client._call_sync(self._client.get_order(order_id))

def cancel_order(self, order_id: str) -> Dict[str, Any]:
"""Cancel a queued order.
Expand All @@ -93,7 +93,7 @@ def cancel_order(self, order_id: str) -> Dict[str, Any]:
planet.exceptions.ClientError: If order_id is not a valid UUID.
planet.exceptions.APIError: On API error.
"""
return self._client.call_sync(self._client.cancel_order(order_id))
return self._client._call_sync(self._client.cancel_order(order_id))

def cancel_orders(self,
order_ids: Optional[List[str]] = None) -> Dict[str, Any]:
Expand All @@ -111,7 +111,7 @@ def cancel_orders(self,
valid UUID.
planet.exceptions.APIError: On API error.
"""
return self._client.call_sync(self._client.cancel_orders(order_ids))
return self._client._call_sync(self._client.cancel_orders(order_ids))

def aggregated_order_stats(self) -> Dict[str, Any]:
"""Get aggregated counts of active orders.
Expand All @@ -122,7 +122,7 @@ def aggregated_order_stats(self) -> Dict[str, Any]:
Raises:
planet.exceptions.APIError: On API error.
"""
return self._client.call_sync(self._client.aggregated_order_stats())
return self._client._call_sync(self._client.aggregated_order_stats())

def download_asset(self,
location: str,
Expand All @@ -146,7 +146,7 @@ def download_asset(self,
Raises:
planet.exceptions.APIError: On API error.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.download_asset(location,
filename,
directory,
Expand Down Expand Up @@ -175,7 +175,7 @@ def download_order(self,
planet.exceptions.ClientError: If the order is not in a final
state.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.download_order(order_id,
directory,
overwrite,
Expand Down Expand Up @@ -249,7 +249,7 @@ def wait(self,
if the maximum number of attempts is reached before the
specified state or a final state is reached.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.wait(order_id, state, delay, max_attempts, callback))

def list_orders(self,
Expand Down Expand Up @@ -319,6 +319,6 @@ def list_orders(self,

try:
while True:
yield self._client.call_sync(results.__anext__())
yield self._client._call_sync(results.__anext__())
except StopAsyncIteration:
pass
16 changes: 8 additions & 8 deletions planet/sync/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def list_subscriptions(self,

try:
while True:
yield self._client.call_sync(results.__anext__())
yield self._client._call_sync(results.__anext__())
except StopAsyncIteration:
pass

Expand All @@ -130,7 +130,7 @@ def create_subscription(self, request: Dict) -> Dict:
APIError: on an API server error.
ClientError: on a client error.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.create_subscription(request))

def cancel_subscription(self, subscription_id: str) -> None:
Expand All @@ -146,7 +146,7 @@ def cancel_subscription(self, subscription_id: str) -> None:
APIError: on an API server error.
ClientError: on a client error.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.cancel_subscription(subscription_id))

def update_subscription(self, subscription_id: str, request: dict) -> dict:
Expand All @@ -164,7 +164,7 @@ def update_subscription(self, subscription_id: str, request: dict) -> dict:
APIError: on an API server error.
ClientError: on a client error.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.update_subscription(subscription_id, request))

def patch_subscription(self, subscription_id: str,
Expand All @@ -183,7 +183,7 @@ def patch_subscription(self, subscription_id: str,
APIError: on an API server error.
ClientError: on a client error.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.patch_subscription(subscription_id, request))

def get_subscription(self, subscription_id: str) -> Dict[str, Any]:
Expand All @@ -199,7 +199,7 @@ def get_subscription(self, subscription_id: str) -> Dict[str, Any]:
APIError: on an API server error.
ClientError: on a client error.
"""
return self._client.call_sync(
return self._client._call_sync(
self._client.get_subscription(subscription_id))

def get_results(
Expand Down Expand Up @@ -238,7 +238,7 @@ def get_results(

try:
while True:
yield self._client.call_sync(results.__anext__())
yield self._client._call_sync(results.__anext__())
except StopAsyncIteration:
pass

Expand Down Expand Up @@ -274,6 +274,6 @@ def get_results_csv(
# https://github.com/hynek/stamina.
try:
while True:
yield self._client.call_sync(results.__anext__())
yield self._client._call_sync(results.__anext__())
except StopAsyncIteration:
pass

0 comments on commit c53c578

Please sign in to comment.