From e33b58d5e9193d2631ba1da4ecaa09498578513e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Luk=C5=A1i=C4=8D?= <31988337+zigaLuksic@users.noreply.github.com> Date: Mon, 13 Nov 2023 11:32:43 +0100 Subject: [PATCH] Deprecate the deprecator (#494) * 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 92b4b04649e9ab820490da32d67d32e740035130. --------- Co-authored-by: Matic Lubej * 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 Co-authored-by: Matic Lubej --- .github/workflows/ci_action.yml | 1 + .github/workflows/ci_trigger.yml | 19 +++++++++++++++++++ .gitlab-ci.yml | 4 ++-- sentinelhub/api/batch/statistical.py | 5 +++-- sentinelhub/api/byoc.py | 2 +- sentinelhub/api/utils.py | 4 ++-- sentinelhub/aws/client.py | 8 ++++++-- sentinelhub/aws/data.py | 13 ++++++++++--- sentinelhub/aws/request.py | 13 ++++++++++--- sentinelhub/exceptions.py | 2 ++ sentinelhub/geo_utils.py | 17 ++++++++++++----- sentinelhub/geometry.py | 6 +++--- 12 files changed, 71 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/ci_trigger.yml diff --git a/.github/workflows/ci_action.yml b/.github/workflows/ci_action.yml index 2512232b..2617d7b8 100644 --- a/.github/workflows/ci_action.yml +++ b/.github/workflows/ci_action.yml @@ -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 }} diff --git a/.github/workflows/ci_trigger.yml b/.github/workflows/ci_trigger.yml new file mode 100644 index 00000000..5bdd9419 --- /dev/null +++ b/.github/workflows/ci_trigger.yml @@ -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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2107b30a..87226e29 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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"' diff --git a/sentinelhub/api/batch/statistical.py b/sentinelhub/api/batch/statistical.py index 41de655f..9e54b09f 100644 --- a/sentinelhub/api/batch/statistical.py +++ b/sentinelhub/api/batch/statistical.py @@ -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 @@ -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 diff --git a/sentinelhub/api/byoc.py b/sentinelhub/api/byoc.py index b379dd29..6c3d94ee 100644 --- a/sentinelhub/api/byoc.py +++ b/sentinelhub/api/byoc.py @@ -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""" diff --git a/sentinelhub/api/utils.py b/sentinelhub/api/utils.py index 8a58ebf1..0856f024 100644 --- a/sentinelhub/api/utils.py +++ b/sentinelhub/api/utils.py @@ -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, @@ -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, diff --git a/sentinelhub/aws/client.py b/sentinelhub/aws/client.py index 15c3ecaa..a5fb77f5 100644 --- a/sentinelhub/aws/client.py +++ b/sentinelhub/aws/client.py @@ -5,6 +5,7 @@ import logging import warnings from typing import Any, Dict, Optional +from typing_extensions import deprecated try: from boto3 import Session @@ -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""" diff --git a/sentinelhub/aws/data.py b/sentinelhub/aws/data.py index 75079b4a..fc8f6b6a 100644 --- a/sentinelhub/aws/data.py +++ b/sentinelhub/aws/data.py @@ -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 @@ -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.""" @@ -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.""" diff --git a/sentinelhub/aws/request.py b/sentinelhub/aws/request.py index bb6a09f4..f52ab4cf 100644 --- a/sentinelhub/aws/request.py +++ b/sentinelhub/aws/request.py @@ -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 @@ -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.""" @@ -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.""" diff --git a/sentinelhub/exceptions.py b/sentinelhub/exceptions.py index 0bb44264..99db0ec9 100644 --- a/sentinelhub/exceptions.py +++ b/sentinelhub/exceptions.py @@ -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]: @@ -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]: diff --git a/sentinelhub/geo_utils.py b/sentinelhub/geo_utils.py index 6c2cdaf0..f27de78c 100644 --- a/sentinelhub/geo_utils.py +++ b/sentinelhub/geo_utils.py @@ -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 @@ -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 @@ -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. @@ -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 @@ -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]: diff --git a/sentinelhub/geometry.py b/sentinelhub/geometry.py index ba44218c..e5491cf0 100644 --- a/sentinelhub/geometry.py +++ b/sentinelhub/geometry.py @@ -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 @@ -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