Skip to content

Commit a41fa23

Browse files
committed
Add docs to variable_api
1 parent 90c2321 commit a41fa23

File tree

1 file changed

+55
-6
lines changed

1 file changed

+55
-6
lines changed

python/hopsworks/core/variable_api.py

+55-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from __future__ import annotations
1717

1818
import re
19+
from typing import Optional, Tuple
1920

2021
from hopsworks import client
2122
from hopsworks.client.exceptions import RestAPIError
@@ -26,7 +27,15 @@ def __init__(self):
2627
pass
2728

2829
def get_variable(self, variable: str):
29-
"""Get the configured value for a variable"""
30+
"""Get the configured value of a variable.
31+
32+
# Arguments
33+
vairable: Name of the variable.
34+
# Returns
35+
The vairable's value
36+
# Raises
37+
`RestAPIError`: If unable to get the variable
38+
"""
3039

3140
_client = client.get_instance()
3241

@@ -35,7 +44,17 @@ def get_variable(self, variable: str):
3544

3645
return domain["successMessage"]
3746

38-
def get_version(self, software: str):
47+
def get_version(self, software: str) -> Optional[str]:
48+
"""Get version of a software component.
49+
50+
# Arguments
51+
software: Name of the software.
52+
# Returns
53+
The software's version, if the software is available, otherwise `None`.
54+
# Raises
55+
`RestAPIError`: If unable to get the version
56+
"""
57+
3958
_client = client.get_instance()
4059
path_params = [
4160
"variables",
@@ -48,13 +67,31 @@ def get_version(self, software: str):
4867
return entry["version"]
4968
return None
5069

51-
def parse_major_and_minor(self, backend_version):
70+
def parse_major_and_minor(self, backend_version: str) -> Tuple[Optional[str], Optional[str]]:
71+
"""Extract major and minor version from full version.
72+
73+
# Arguments
74+
backend_version: The full version.
75+
# Returns
76+
(major, minor): The pair of major and minor parts of the version, or (None, None) if the version format is incorrect.
77+
"""
78+
5279
version_pattern = r"(\d+)\.(\d+)"
5380
matches = re.match(version_pattern, backend_version)
5481

82+
if matches is None:
83+
return (None, None)
5584
return matches.group(1), matches.group(2)
5685

57-
def get_flyingduck_enabled(self):
86+
def get_flyingduck_enabled(self) -> bool:
87+
"""Check if Flying Duck is enabled on the backend.
88+
89+
# Returns
90+
`True`: If flying duck is availalbe, `False` otherwise.
91+
# Raises
92+
`RestAPIError`: If unable to obtain the flag's value.
93+
"""
94+
5895
_client = client.get_instance()
5996
path_params = [
6097
"variables",
@@ -64,7 +101,13 @@ def get_flyingduck_enabled(self):
64101
resp = _client._send_request("GET", path_params)
65102
return resp["successMessage"] == "true"
66103

67-
def get_loadbalancer_external_domain(self):
104+
def get_loadbalancer_external_domain(self) -> str:
105+
"""Get domain of external loadbalancer.
106+
107+
# Returns
108+
`str`: The domain of external loadbalancer, if it is set up, otherwise empty string `""`.
109+
"""
110+
68111
_client = client.get_instance()
69112
path_params = [
70113
"variables",
@@ -77,7 +120,13 @@ def get_loadbalancer_external_domain(self):
77120
except RestAPIError:
78121
return ""
79122

80-
def get_service_discovery_domain(self):
123+
def get_service_discovery_domain(self) -> str:
124+
"""Get domain of service discovery server.
125+
126+
# Returns
127+
`str`: The domain of service discovery server, if it is set up, otherwise empty string `""`.
128+
"""
129+
81130
_client = client.get_instance()
82131
path_params = [
83132
"variables",

0 commit comments

Comments
 (0)