Skip to content

Commit

Permalink
Issue #611 eliminate unnecessary Capabilties base class
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Sep 3, 2024
1 parent 2bac719 commit 6778c73
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 54 deletions.
49 changes: 0 additions & 49 deletions openeo/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,8 @@

import contextlib
import re
from abc import ABC
from typing import Tuple, Union

# TODO Is this base class (still) useful?


class Capabilities(ABC):
"""Represents capabilities of a connection / back end."""

def __init__(self, data):
pass

def version(self):
""" Get openEO version. DEPRECATED: use api_version instead"""
# Field: version
# TODO: raise deprecation warning here?
return self.api_version()

def api_version(self) -> str:
"""Get OpenEO API version."""
raise NotImplementedError

@property
def api_version_check(self) -> ComparableVersion:
"""Helper to easily check if the API version is at least or below some threshold version."""
api_version = self.api_version()
if not api_version:
raise ApiVersionException("No API version found")
return ComparableVersion(api_version)

def list_features(self):
""" List all supported features / endpoints."""
# Field: endpoints
pass

def has_features(self, method_name):
""" Check whether a feature / endpoint is supported."""
# Field: endpoints > ...
pass

def currency(self):
""" Get default billing currency."""
# Field: billing > currency
pass

def list_plans(self):
""" List all billing plans."""
# Field: billing > plans
pass


# Type annotation aliases
_VersionTuple = Tuple[Union[int, str], ...]

Expand Down
1 change: 1 addition & 0 deletions openeo/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class OpenEoClientException(BaseOpenEoException):


class CapabilitiesException(OpenEoClientException):
# TODO move this to openeo.capabilities?
"""Back-end does not support certain openEO feature or endpoint."""


Expand Down
19 changes: 15 additions & 4 deletions openeo/rest/rest_capabilities.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from typing import List, Optional

from openeo.capabilities import Capabilities
from openeo.capabilities import ApiVersionException, ComparableVersion
from openeo.internal.jupyter import render_component
from openeo.util import deep_get


class RESTCapabilities(Capabilities):
"""Represents REST capabilities of a connection / back end."""
# TODO: rename this class to "OpenEOCapabilities" or even just "Capabilities"?
# Note that this class is about *openEO* capabilities, not *REST* capabilities.
# TODO: also note that there isn't even a direct dependency on REST/HTTP aspects here,
# so this class could be moved to a more generic (utility) location. Or just openeo.capabilities?
class RESTCapabilities:
"""Represents the capabilities of an openEO back-end."""

def __init__(self, data: dict, url: str = None):
super(RESTCapabilities, self).__init__(data)
self.capabilities = data
self.url = url

Expand All @@ -27,6 +30,14 @@ def api_version(self) -> str:
# Legacy/deprecated
return self.capabilities.get('version')

@property
def api_version_check(self) -> ComparableVersion:
"""Helper to easily check if the API version is at least or below some threshold version."""
api_version = self.api_version()
if not api_version:
raise ApiVersionException("No API version found")
return ComparableVersion(api_version)

def list_features(self):
""" List all supported features / endpoints."""
return self.capabilities.get('endpoints')
Expand Down
1 change: 0 additions & 1 deletion tests/rest/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ def test_capabilities_api_version(requests_mock):
requests_mock.get(API_URL, status_code=200, json={"api_version": "1.0.0"})
con = openeo.connect("https://oeo.test")
capabilities = con.capabilities()
assert capabilities.version() == "1.0.0"
assert capabilities.api_version() == "1.0.0"


Expand Down

0 comments on commit 6778c73

Please sign in to comment.