Skip to content

Commit 34c4d99

Browse files
committed
Add minimal type hinting for hopsworks.login and project.get_feature_store + stop execution method
1 parent d91679b commit 34c4d99

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

python/hopsworks/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
from __future__ import annotations
1617

1718
import warnings
1819
import logging
@@ -25,6 +26,7 @@
2526
from hopsworks.client.exceptions import RestAPIError, ProjectException
2627
from hopsworks import version, constants, client
2728
from hopsworks.connection import Connection
29+
from hopsworks import project
2830

2931
# Needs to run before import of hsml and hsfs
3032
warnings.filterwarnings(action="ignore", category=UserWarning, module=r".*psycopg2")
@@ -62,7 +64,7 @@ def login(
6264
project: str = None,
6365
api_key_value: str = None,
6466
api_key_file: str = None,
65-
):
67+
) -> project.Project:
6668
"""Connect to [Serverless Hopsworks](https://app.hopsworks.ai) by calling the `hopsworks.login()` function with no arguments.
6769
6870
```python

python/hopsworks/core/execution_api.py

+18
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,21 @@ def _delete(self, job_name, id):
7676
id,
7777
]
7878
_client._send_request("DELETE", path_params)
79+
80+
def _stop(self, job_name: str, id: int) -> None:
81+
_client = client.get_instance()
82+
path_params = [
83+
"project",
84+
self._project_id,
85+
"jobs",
86+
job_name,
87+
"executions",
88+
id,
89+
"status",
90+
]
91+
_client._send_request(
92+
"PUT",
93+
path_params=path_params,
94+
data={"state": "stopped"},
95+
headers={"Content-Type": "application/json"},
96+
)

python/hopsworks/execution.py

+9
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ def delete(self):
212212
"""
213213
self._execution_api._delete(self._job.name, self.id)
214214

215+
def stop(self):
216+
"""Stop the execution
217+
!!! danger "Potentially dangerous operation"
218+
This operation stops the execution.
219+
# Raises
220+
`RestAPIError`.
221+
"""
222+
self._execution_api._stop(self.job_name, self.id)
223+
215224
def await_termination(self):
216225
"""Wait until execution reaches terminal state
217226
# Raises

python/hopsworks/project.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
from __future__ import annotations
1617

1718
import humps
1819
import json
@@ -28,7 +29,7 @@
2829
environment_api,
2930
flink_cluster_api,
3031
)
31-
32+
from hsfs import feature_store
3233

3334
class Project:
3435
def __init__(
@@ -101,7 +102,7 @@ def created(self):
101102
"""Timestamp when the project was created"""
102103
return self._created
103104

104-
def get_feature_store(self, name: str = None):
105+
def get_feature_store(self, name: str = None) -> feature_store.FeatureStore:
105106
"""Connect to Project's Feature Store.
106107
107108
Defaulting to the project name of default feature store. To get a

0 commit comments

Comments
 (0)