Skip to content

Commit

Permalink
[PT-5318] Deprecate legacy webhooks methods (#633)
Browse files Browse the repository at this point in the history
* Deprecate legacy webhooks methods

* Clean up

* Bump version and changelog update
  • Loading branch information
javidq authored Jun 12, 2024
1 parent 6bb2293 commit 2b3ab37
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ You can check your current version with the following command:
```

For more information, see [UP42 Python package description](https://pypi.org/project/up42-py/).
## 1.0.4a18

**Jun 13, 2024**

- Deprecate legacy webhook code.
- Drop long deprecated `Catalog::construct_parameters`.

## 1.0.4a17

**Jun 13, 2024**
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "up42-py"
version = "1.0.4a17"
version = "1.0.4a18"
description = "Python SDK for UP42, the geospatial marketplace and developer platform."
authors = ["UP42 GmbH <[email protected]>"]
license = "https://github.com/up42/up42-py/blob/master/LICENSE"
Expand Down
5 changes: 0 additions & 5 deletions up42/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,6 @@ def estimate_order(self, order_parameters: Optional[Dict], **kwargs) -> int:
raise ValueError("Please provide the 'order_parameters' parameter!")
return order.Order.estimate(self.auth, order_parameters) # type: ignore

@utils.deprecation("construct_search_parameters", "0.25.0")
def construct_parameters(self, **kwargs): # pragma: no cover
"""Deprecated, see construct_search_parameters"""
return self.construct_search_parameters(**kwargs)

@staticmethod
def construct_search_parameters(
geometry: Union[
Expand Down
4 changes: 4 additions & 0 deletions up42/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def initialize_asset(asset_id: str) -> asset.Asset:
return up42_asset


@utils.deprecation("up42.Webhook::get", "2.0.0")
def initialize_webhook(webhook_id: str) -> webhooks.Webhook:
"""
Returns a Webhook object (has to exist on UP42).
Expand All @@ -62,6 +63,7 @@ def initialize_webhook(webhook_id: str) -> webhooks.Webhook:
return webhook


@utils.deprecation("up42.Webhook::all", "2.0.0")
def get_webhooks(return_json: bool = False) -> List[webhooks.Webhook]:
"""
Gets all registered webhooks for this workspace.
Expand All @@ -74,6 +76,7 @@ def get_webhooks(return_json: bool = False) -> List[webhooks.Webhook]:
return webhooks.Webhook.all(return_json=return_json)


@utils.deprecation("up42.Webhook::save", "2.0.0")
def create_webhook(
name: str,
url: str,
Expand All @@ -96,6 +99,7 @@ def create_webhook(
return webhooks.Webhook.create(name=name, url=url, events=events, active=active, secret=secret)


@utils.deprecation("up42.Webhook::get_webhook_events", "2.0.0")
def get_webhook_events() -> dict:
"""
Gets all available webhook events.
Expand Down
11 changes: 4 additions & 7 deletions up42/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,23 @@ def get_logger(


def deprecation(
replacement_name: str,
replacement_name: Optional[str],
version: str,
extra_message: str = "",
):
"""
Decorator for custom deprecation warnings.
Args:
replacement_name: Name of the replacement function.
version: The package version in which the deprecation will happen.
version: The breaking package version
extra_message: Optional message after default deprecation warning.
"""

def actual_decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
message = (
f"`{func.__name__}` will be deprecated in version {version}, "
f"use `{replacement_name}` instead! {extra_message}"
)
replace_with = f", use `{replacement_name}` instead" if replacement_name else ""
message = f"`{func.__name__}` is deprecated and will be dropped in version {version}{replace_with}."
warnings.warn(message, DeprecationWarning, stacklevel=2)
return func(*args, **kwargs)

Expand Down
10 changes: 10 additions & 0 deletions up42/webhooks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dataclasses
import warnings
from typing import List, Optional

from up42 import base, host, utils
Expand Down Expand Up @@ -68,10 +69,12 @@ def get(cls, webhook_id: str) -> "Webhook":
return cls.from_metadata(metadata)

@property
@utils.deprecation("up42.Webhook properties", "2.0.0")
def info(self) -> dict:
return dataclasses.asdict(self)

@property
@utils.deprecation("up42.Webhook::id", "2.0.0")
def webhook_id(self):
return self.id

Expand All @@ -86,6 +89,7 @@ def trigger_test_events(self) -> dict:
url = host.endpoint(f"/workspaces/{self.workspace_id}/webhooks/{self.id}/tests")
return self.session.post(url=url).json()["data"]

@utils.deprecation("up42.Webhook::save", "2.0.0")
def update(
self,
name: Optional[str] = None,
Expand Down Expand Up @@ -151,10 +155,16 @@ def all(cls, return_json: bool = False) -> List["Webhook"]:
logger.info("Queried %s webhooks.", len(payload))

if return_json:
warnings.warn(
"return_json is deprecated and will be dropped in version 2.0.0",
DeprecationWarning,
stacklevel=2,
)
return payload
return [cls.from_metadata(metadata) for metadata in payload]

@classmethod
@utils.deprecation("up42.Webhook::save", "2.0.0")
def create(
cls,
name: str,
Expand Down

0 comments on commit 2b3ab37

Please sign in to comment.