Skip to content

Commit

Permalink
Deprecate the deprecator (#494)
Browse files Browse the repository at this point in the history
* Enable Github actions to trigger internal Gitlab CI (#490)

* update actions and gitlab CI

* update project path

* use trigger API to build internal docker instead

* test trigger on branch push

* fix github action

* test why trigger workflow not starting

* fix branch name

* remove step in trigger job

* remove test branch

* move mirror to a separate workflow, update pipeline running rules

* Revert "move mirror to a separate workflow, update pipeline running rules"

This reverts commit 92b4b04.

---------

Co-authored-by: Matic Lubej <[email protected]>

* deprecate deprecation wrappers

* switch to type_extensions deprecations

* add comments

* Fix bug that occurs with dataclass_json 0.62 (#493)

* remove "undefined" catch-all flag from a field

* mypy fixes

* fix wrong import

* remove redundant import

---------

Co-authored-by: Matic Lubej <[email protected]>
Co-authored-by: Matic Lubej <[email protected]>
  • Loading branch information
3 people authored Nov 13, 2023
1 parent 2df6028 commit e33b58d
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ jobs:
with:
args: "https://git.sinergise.com/eo/code/sentinelhub-py-dev/"
env:
FOLLOW_TAGS: "true"
GITLAB_HOSTNAME: "git.sinergise.com"
GITLAB_USERNAME: "github-action"
GITLAB_PASSWORD: ${{ secrets.GITLAB_PASSWORD }}
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/ci_trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: trigger

on:
release:
types:
- published

jobs:
trigger:
runs-on: ubuntu-latest
steps:
- name: Trigger API
run: >
curl -X POST --fail \
-F token=${{ secrets.GITLAB_PIPELINE_TRIGGER_TOKEN }} \
-F ref=main \
-F variables[CUSTOM_RUN_TAG]=auto \
-F variables[LAYER_NAME]=dotai-eo \
https://git.sinergise.com/api/v4/projects/1031/trigger/pipeline
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ update_base_image:
run_sh_integration_tests:
stage: test
image: "$BASE_IMAGE"
dependencies: [ ]
needs: [ ]
dependencies: []
needs: []
rules:
- when: always
if: '$UPDATE_BASE_IMAGE != "true"'
Expand Down
5 changes: 3 additions & 2 deletions sentinelhub/api/batch/statistical.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

from dataclasses_json import CatchAll, LetterCase, Undefined, dataclass_json
from dataclasses_json import config as dataclass_config
from typing_extensions import deprecated

from ...exceptions import deprecated_function
from ...exceptions import SHDeprecationWarning
from ...types import Json, JsonDict
from ..base_request import InputDataDict
from ..statistical import SentinelHubStatistical
Expand Down Expand Up @@ -140,7 +141,7 @@ def start_job(self, batch_request: BatchStatisticalRequestType) -> Json:
"""
return self._call_job(batch_request, "start")

@deprecated_function(message_suffix="The service endpoint will be removed soon. Please use `stop_job` instead.")
@deprecated("The method `cancel_job` has been replaced with use `stop_job`.", category=SHDeprecationWarning)
def cancel_job(self, batch_request: BatchStatisticalRequestType) -> Json:
"""Cancels a batch job
Expand Down
2 changes: 1 addition & 1 deletion sentinelhub/api/byoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ByocCollectionAdditionalData:
other_data: CatchAll = field(default_factory=dict)


@dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.INCLUDE)
@dataclass_json(letter_case=LetterCase.CAMEL)
@dataclass
class ByocCollection(BaseCollection):
"""Dataclass to hold BYOC collection data"""
Expand Down
4 changes: 2 additions & 2 deletions sentinelhub/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
letter_case=LetterCase.CAMEL,
)

geometry_config = dataclass_config( # type: ignore[misc]
geometry_config = dataclass_config(
encoder=Geometry.get_geojson,
decoder=lambda geojson: Geometry.from_geojson(geojson) if geojson else None,
exclude=lambda geojson: geojson is None,
Expand All @@ -31,7 +31,7 @@

def enum_config(enum_class: Type[Enum]) -> Dict[str, dict]:
"""Given an Enum class it provide an object for serialization/deserialization"""
return dataclass_config( # type: ignore[misc]
return dataclass_config(
encoder=lambda enum_item: enum_item.value,
decoder=lambda item: enum_class(item) if item else None,
exclude=lambda item: item is None,
Expand Down
8 changes: 6 additions & 2 deletions sentinelhub/aws/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import warnings
from typing import Any, Dict, Optional
from typing_extensions import deprecated

try:
from boto3 import Session
Expand All @@ -18,12 +19,15 @@
from ..download.client import DownloadClient
from ..download.handlers import fail_missing_file
from ..download.models import DownloadRequest, DownloadResponse
from ..exceptions import AwsDownloadFailedException, deprecated_class
from ..exceptions import AwsDownloadFailedException, SHDeprecationWarning

LOGGER = logging.getLogger(__name__)


@deprecated_class(message_suffix="It will remain in the codebase for now, but won't be actively maintained.")
@deprecated(
"AWS functionality will remain in the codebase for now, but won't be actively maintained.",
category=SHDeprecationWarning,
)
class AwsDownloadClient(DownloadClient):
"""An AWS download client class"""

Expand Down
13 changes: 10 additions & 3 deletions sentinelhub/aws/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import warnings
from abc import ABCMeta, abstractmethod
from typing import Any, List, Optional, Tuple, Union
from typing_extensions import deprecated

from ..api.opensearch import get_tile_info, get_tile_info_id
from ..config import SHConfig
from ..constants import MimeType
from ..data_collections import DataCollection
from ..download import DownloadRequest
from ..exceptions import AwsDownloadFailedException, SHUserWarning, deprecated_class
from ..exceptions import AwsDownloadFailedException, SHUserWarning, SHDeprecationWarning
from ..time_utils import parse_time
from .client import AwsDownloadClient
from .constants import AwsConstants, EsaSafeType
Expand Down Expand Up @@ -320,7 +321,10 @@ def is_early_compact_l2a(self) -> bool:
)


@deprecated_class(message_suffix="It will remain in the codebase for now, but won't be actively maintained.")
@deprecated(
"AWS functionality will remain in the codebase for now, but won't be actively maintained.",
category=SHDeprecationWarning,
)
class AwsProduct(AwsData):
"""Class for collecting Sentinel-2 products data from AWS."""

Expand Down Expand Up @@ -468,7 +472,10 @@ def get_filepath(self, filename: str) -> str:
return os.path.join(self.parent_folder, self.product_id, self.add_file_extension(filename)).replace(":", ".")


@deprecated_class(message_suffix="It will remain in the codebase for now, but won't be actively maintained.")
@deprecated(
"AWS functionality will remain in the codebase for now, but won't be actively maintained.",
category=SHDeprecationWarning,
)
class AwsTile(AwsData):
"""Class for collecting Sentinel-2 tiles data from AWS."""

Expand Down
13 changes: 10 additions & 3 deletions sentinelhub/aws/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import functools
from abc import abstractmethod
from typing import Any, Generic, List, Optional, Tuple, TypeVar, Union
from typing_extensions import deprecated

from ..base import DataRequest
from ..data_collections import DataCollection
from ..exceptions import deprecated_class
from ..exceptions import SHDeprecationWarning
from .client import AwsDownloadClient
from .data import REQUESTER_PAYS_PARAMS, AwsProduct, AwsTile
from .data_safe import SafeProduct, SafeTile
Expand Down Expand Up @@ -61,7 +62,10 @@ def get_aws_service(self) -> T:
return self.aws_service


@deprecated_class(message_suffix="It will remain in the codebase for now, but won't be actively maintained.")
@deprecated(
"AWS functionality will remain in the codebase for now, but won't be actively maintained.",
category=SHDeprecationWarning,
)
class AwsProductRequest(_BaseAwsDataRequest[AwsProduct]):
"""AWS Service request class for an ESA product."""

Expand Down Expand Up @@ -97,7 +101,10 @@ def create_request(self) -> None:
self.download_list, self.folder_list = self.aws_service.get_requests()


@deprecated_class(message_suffix="It will remain in the codebase for now, but won't be actively maintained.")
@deprecated(
"AWS functionality will remain in the codebase for now, but won't be actively maintained.",
category=SHDeprecationWarning,
)
class AwsTileRequest(_BaseAwsDataRequest[AwsTile]):
"""AWS Service request class for an ESA tile."""

Expand Down
2 changes: 2 additions & 0 deletions sentinelhub/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class SHRateLimitWarning(SHRuntimeWarning):
warnings.simplefilter("always", SHRateLimitWarning)


# THIS SHOULD BE REMOVED IN THE FUTURE, after rest of libraries transition away.
def deprecated_function(
category: type[DeprecationWarning] = SHDeprecationWarning, message_suffix: str | None = None
) -> Callable[[Callable], Callable]:
Expand All @@ -86,6 +87,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
return deco


# THIS SHOULD BE REMOVED IN THE FUTURE, after rest of libraries transition away.
def deprecated_class(
category: type[DeprecationWarning] = SHDeprecationWarning, message_suffix: str | None = None
) -> Callable[[type], type]:
Expand Down
17 changes: 12 additions & 5 deletions sentinelhub/geo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

from typing import TYPE_CHECKING, Sequence, Tuple, cast

from typing_extensions import deprecated

from .constants import CRS
from .exceptions import deprecated_function
from .exceptions import SHDeprecationWarning

if TYPE_CHECKING:
from .geometry import BBox
Expand Down Expand Up @@ -83,7 +85,7 @@ def to_utm_bbox(bbox: BBox) -> BBox:
return bbox.transform(utm_crs)


@deprecated_function()
@deprecated("The function `get_utm_bbox` has been deprecated.", category=SHDeprecationWarning)
def get_utm_bbox(img_bbox: Sequence[float], transform: Sequence[float]) -> list[float]:
"""Get UTM coordinates given a bounding box in pixels and a transform
Expand All @@ -96,7 +98,10 @@ def get_utm_bbox(img_bbox: Sequence[float], transform: Sequence[float]) -> list[
return [east1, north1, east2, north2]


@deprecated_function(message_suffix="Use `transform_point` and `get_utm_crs` instead.")
@deprecated(
"The function `wgs84_to_utm` has been deprecated. Use `transform_point` and `get_utm_crs` instead.",
category=SHDeprecationWarning,
)
def wgs84_to_utm(lng: float, lat: float, utm_crs: CRS | None = None) -> tuple[float, float]:
"""Convert WGS84 coordinates to UTM. If UTM CRS is not set it will be calculated automatically.
Expand All @@ -110,7 +115,9 @@ def wgs84_to_utm(lng: float, lat: float, utm_crs: CRS | None = None) -> tuple[fl
return transform_point((lng, lat), CRS.WGS84, utm_crs)


@deprecated_function(message_suffix="Use `transform_point` instead.")
@deprecated(
"The function `to_wgs84` has been deprecated. Use `transform_point` instead.", category=SHDeprecationWarning
)
def to_wgs84(east: float, north: float, crs: CRS) -> tuple[float, float]:
"""Convert any CRS with (east, north) coordinates to WGS84
Expand Down Expand Up @@ -153,7 +160,7 @@ def pixel_to_utm(row: float, column: float, transform: Sequence[float]) -> tuple
return east, north


@deprecated_function()
@deprecated("The function `wgs84_to_pixel` has been deprecated.", category=SHDeprecationWarning)
def wgs84_to_pixel(
lng: float, lat: float, transform: Sequence[float], utm_epsg: CRS | None = None, truncate: bool = True
) -> tuple[float, float] | tuple[int, int]:
Expand Down
6 changes: 3 additions & 3 deletions sentinelhub/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import warnings
from abc import ABCMeta, abstractmethod
from math import ceil
from typing import Callable, Dict, Iterator, Tuple, TypeVar, Union, cast
from typing import Callable, Dict, Iterator, Tuple, TypeVar, Union

import shapely.geometry
import shapely.geometry.base
Expand Down Expand Up @@ -159,9 +159,9 @@ def _tuple_from_list_or_tuple(
:raises: TypeError
"""
if len(bbox) == 4:
min_x, min_y, max_x, max_y = cast(Tuple[float, float, float, float], bbox)
min_x, min_y, max_x, max_y = bbox
else:
(min_x, min_y), (max_x, max_y) = cast(Tuple[Tuple[float, float], Tuple[float, float]], bbox)
(min_x, min_y), (max_x, max_y) = bbox
return float(min_x), float(min_y), float(max_x), float(max_y)

@staticmethod
Expand Down

0 comments on commit e33b58d

Please sign in to comment.