Skip to content

Commit 52ca273

Browse files
vatjrobzor92
andauthored
[FSTORE-1281] Add method to stop execution + type hinting login+get_feature_store (#203)
* Add minimal type hinting for hopsworks.login and project.get_feature_store + stop execution method * Contributing edit to switch to ruff * sort imports * Update CONTRIBUTING.md from review Co-authored-by: Robin Andersson <robin.eric.andersson@gmail.com> --------- Co-authored-by: Robin Andersson <robin.eric.andersson@gmail.com>
1 parent 12aa2bb commit 52ca273

File tree

6 files changed

+75
-40
lines changed

6 files changed

+75
-40
lines changed

CONTRIBUTING.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@
1212
pip install -e ".[dev]"
1313
```
1414

15-
- Install [pre-commit](https://pre-commit.com/) and then activate its hooks. pre-commit is a framework for managing and maintaining multi-language pre-commit hooks. The library uses pre-commit to ensure code-style and code formatting through [black](https://github.com/psf/black) and [flake8](https://gitlab.com/pycqa/flake8). Run the following commands from the `python` directory:
15+
- Install [pre-commit](https://pre-commit.com/) and then activate its hooks. pre-commit is a framework for managing and maintaining multi-language pre-commit hooks. The library uses pre-commit to ensure code-style and code formatting through [ruff](https://docs.astral.sh/ruff/). Run the following commands from the `python` directory:
1616

17-
```bash
18-
cd python
19-
pip install --user pre-commit
20-
pre-commit install
21-
```
17+
```bash
18+
cd python
19+
pip install --user pre-commit
20+
pre-commit install
21+
```
2222

2323
Afterwards, pre-commit will run whenever you commit.
2424

25-
- To run formatting and code-style separately, you can configure your IDE, such as VSCode, to use black and flake8, or run them via the command line:
25+
- To run formatting and code-style separately, you can configure your IDE, such as VSCode, to use `ruff`, or run it via the command line:
2626

27-
```bash
28-
cd python
29-
flake8 hopsworks
30-
black hopsworks
31-
```
27+
```bash
28+
# linting
29+
ruff check python --fix
30+
# formatting
31+
ruff format python
32+
```
3233

3334
### Python documentation
3435

docs/CONTRIBUTING.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@
1212
pip install -e ".[dev]"
1313
```
1414

15-
- Install [pre-commit](https://pre-commit.com/) and then activate its hooks. pre-commit is a framework for managing and maintaining multi-language pre-commit hooks. The library uses pre-commit to ensure code-style and code formatting through [black](https://github.com/psf/black) and [flake8](https://gitlab.com/pycqa/flake8). Run the following commands from the `python` directory:
15+
- Install [pre-commit](https://pre-commit.com/) and then activate its hooks. pre-commit is a framework for managing and maintaining multi-language pre-commit hooks. The Feature Store uses pre-commit to ensure code-style and code formatting through [ruff](https://docs.astral.sh/ruff/). Run the following commands from the `python` directory:
1616

17-
```bash
18-
cd python
19-
pip install --user pre-commit
20-
pre-commit install
21-
```
17+
```bash
18+
cd python
19+
pip install --user pre-commit
20+
pre-commit install
21+
```
2222

2323
Afterwards, pre-commit will run whenever you commit.
2424

25-
- To run formatting and code-style separately, you can configure your IDE, such as VSCode, to use black and flake8, or run them via the command line:
25+
- To run formatting and code-style separately, you can configure your IDE, such as VSCode, to use `ruff`, or run it via the command line:
2626

27-
```bash
28-
cd python
29-
flake8 hopsworks
30-
black hopsworks
31-
```
27+
```bash
28+
# linting
29+
ruff check python --fix
30+
# formatting
31+
ruff format python
32+
```
3233

3334
### Python documentation
3435

python/hopsworks/__init__.py

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

17-
import warnings
18+
import getpass
1819
import logging
1920
import os
2021
import sys
21-
import getpass
2222
import tempfile
23+
import warnings
2324
from pathlib import Path
2425

25-
from hopsworks.client.exceptions import RestAPIError, ProjectException
26-
from hopsworks import version, constants, client
26+
from hopsworks import client, constants, project, version
27+
from hopsworks.client.exceptions import ProjectException, RestAPIError
2728
from hopsworks.connection import Connection
2829

30+
2931
# Needs to run before import of hsml and hsfs
3032
warnings.filterwarnings(action="ignore", category=UserWarning, module=r".*psycopg2")
3133

32-
import hsml # noqa: F401, E402
3334
import hsfs # noqa: F401, E402
35+
import hsml # noqa: F401, E402
36+
3437

3538
__version__ = version.__version__
3639

@@ -62,7 +65,7 @@ def login(
6265
project: str = None,
6366
api_key_value: str = None,
6467
api_key_file: str = None,
65-
):
68+
) -> project.Project:
6669
"""Connect to [Serverless Hopsworks](https://app.hopsworks.ai) by calling the `hopsworks.login()` function with no arguments.
6770
6871
```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

+13-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
# limitations under the License.
1515
#
1616

17-
import humps
1817
import json
19-
from hopsworks.engine import execution_engine
20-
from hopsworks.core import execution_api
18+
19+
import humps
2120
from hopsworks import constants, util
21+
from hopsworks.core import execution_api
22+
from hopsworks.engine import execution_engine
2223

2324

2425
class Execution:
@@ -212,6 +213,15 @@ def delete(self):
212213
"""
213214
self._execution_api._delete(self._job.name, self.id)
214215

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

python/hopsworks/project.py

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

17-
import humps
1818
import json
1919

20-
from hopsworks import util, client, constants
20+
import humps
21+
from hopsworks import client, constants, util
2122
from hopsworks.client.external import Client
2223
from hopsworks.core import (
23-
job_api,
24-
git_api,
2524
dataset_api,
26-
kafka_api,
27-
opensearch_api,
2825
environment_api,
2926
flink_cluster_api,
27+
git_api,
28+
job_api,
29+
kafka_api,
30+
opensearch_api,
3031
)
32+
from hsfs import feature_store
3133

3234

3335
class Project:
@@ -101,7 +103,7 @@ def created(self):
101103
"""Timestamp when the project was created"""
102104
return self._created
103105

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

0 commit comments

Comments
 (0)