Skip to content

Commit

Permalink
Ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
aversey committed Jul 17, 2024
1 parent 3d932d6 commit 4e8aad8
Show file tree
Hide file tree
Showing 23 changed files with 241 additions and 158 deletions.
23 changes: 15 additions & 8 deletions python/hopsworks/core/environment_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ def __init__(

self._environment_engine = environment_engine.EnvironmentEngine(project_id)

def create_environment(self, name: str, description: Optional[str] = None, base_environment_name: Optional[str] = "python-feature-pipeline", await_creation: Optional[bool] = True) -> environment.Environment:
def create_environment(
self,
name: str,
description: Optional[str] = None,
base_environment_name: Optional[str] = "python-feature-pipeline",
await_creation: Optional[bool] = True,
) -> environment.Environment:
"""Create Python environment for the project
```python
Expand Down Expand Up @@ -66,13 +72,14 @@ def create_environment(self, name: str, description: Optional[str] = None, base_
name,
]
headers = {"content-type": "application/json"}
data = {"name": name,
"baseImage": {
"name": base_environment_name,
"description": description
}}
data = {
"name": name,
"baseImage": {"name": base_environment_name, "description": description},
}
env = environment.Environment.from_response_json(
_client._send_request("POST", path_params, headers=headers, data=json.dumps(data)),
_client._send_request(
"POST", path_params, headers=headers, data=json.dumps(data)
),
self._project_id,
self._project_name,
)
Expand Down Expand Up @@ -148,4 +155,4 @@ def _delete(self, name):
name,
]
headers = {"content-type": "application/json"}
_client._send_request("DELETE", path_params, headers=headers),
(_client._send_request("DELETE", path_params, headers=headers),)
18 changes: 12 additions & 6 deletions python/hopsworks/core/secret_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def get_secret(self, name: str, owner: str = None) -> secret.Secret:
"shared",
]

return secret.Secret.from_response_json(_client._send_request("GET", path_params, query_params=query_params))[0]
return secret.Secret.from_response_json(
_client._send_request("GET", path_params, query_params=query_params)
)[0]

def get(self, name: str, owner: str = None) -> str:
"""Get the secret's value.
Expand All @@ -90,16 +92,20 @@ def get(self, name: str, owner: str = None) -> str:
return self.get_secret(name=name, owner=owner).value
except RestAPIError as e:
if (
e.response.json().get("errorCode", "") == 160048
and e.response.status_code == 404
and util.is_interactive()
e.response.json().get("errorCode", "") == 160048
and e.response.status_code == 404
and util.is_interactive()
):
secret_input = getpass.getpass(prompt="\nCould not find secret, enter value here to create it: ")
secret_input = getpass.getpass(
prompt="\nCould not find secret, enter value here to create it: "
)
return self.create_secret(name, secret_input).value
else:
raise e

def create_secret(self, name: str, value: str, project: str = None) -> secret.Secret:
def create_secret(
self, name: str, value: str, project: str = None
) -> secret.Secret:
"""Create a new secret.
```python
Expand Down
20 changes: 11 additions & 9 deletions python/hopsworks/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,18 @@ def install_wheel(self, path: str, await_installation: Optional[bool] = True):
"packageSource": "WHEEL",
}

library_rest = self._library_api._install(
library_name, self.name, library_spec
)
library_rest = self._library_api._install(library_name, self.name, library_spec)

if await_installation:
return self._environment_engine.await_library_command(self.name, library_name)
return self._environment_engine.await_library_command(
self.name, library_name
)

return library_rest

def install_requirements(self, path: str, await_installation: Optional[bool] = True):
def install_requirements(
self, path: str, await_installation: Optional[bool] = True
):
"""Install libraries specified in a requirements.txt file
```python
Expand Down Expand Up @@ -184,12 +186,12 @@ def install_requirements(self, path: str, await_installation: Optional[bool] = T
"packageSource": "REQUIREMENTS_TXT",
}

library_rest = self._library_api._install(
library_name, self.name, library_spec
)
library_rest = self._library_api._install(library_name, self.name, library_spec)

if await_installation:
return self._environment_engine.await_library_command(self.name, library_name)
return self._environment_engine.await_library_command(
self.name, library_name
)

return library_rest

Expand Down
2 changes: 1 addition & 1 deletion python/hopsworks/job_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(
next_execution_date_time=None,
id=None,
end_date_time=None,
**kwargs
**kwargs,
):
self._id = id
self._start_date_time = (
Expand Down
4 changes: 3 additions & 1 deletion python/hopsworks/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def get_hostname_replaced_url(sub_path: str):
url_parsed = client.get_instance().replace_public_host(urlparse(href))
return url_parsed.geturl()


def is_interactive():
import __main__ as main
return not hasattr(main, '__file__')

return not hasattr(main, "__file__")
4 changes: 1 addition & 3 deletions python/hsfs/core/explicit_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,7 @@ def default(self, obj):
}
elif isinstance(
obj,
(
storage_connector.StorageConnector
),
(storage_connector.StorageConnector),
):
return {
"name": obj.name,
Expand Down
32 changes: 19 additions & 13 deletions python/hsfs/core/feature_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,32 @@


class FeatureLogging:

def __init__(self, id: int,
transformed_features: "feature_group.FeatureGroup",
untransformed_features: "feature_group.FeatureGroup"):
def __init__(
self,
id: int,
transformed_features: "feature_group.FeatureGroup",
untransformed_features: "feature_group.FeatureGroup",
):
self._id = id
self._transformed_features = transformed_features
self._untransformed_features = untransformed_features

@classmethod
def from_response_json(cls, json_dict: Dict[str, Any]) -> 'FeatureLogging':
def from_response_json(cls, json_dict: Dict[str, Any]) -> "FeatureLogging":
from hsfs.feature_group import FeatureGroup # avoid circular import

json_decamelized = humps.decamelize(json_dict)
transformed_features = json_decamelized.get('transformed_log')
untransformed_features = json_decamelized.get('untransformed_log')
transformed_features = json_decamelized.get("transformed_log")
untransformed_features = json_decamelized.get("untransformed_log")
if transformed_features:
transformed_features = FeatureGroup.from_response_json(transformed_features)
if untransformed_features:
untransformed_features = FeatureGroup.from_response_json(untransformed_features)
return cls(json_decamelized.get('id'), transformed_features, untransformed_features)
untransformed_features = FeatureGroup.from_response_json(
untransformed_features
)
return cls(
json_decamelized.get("id"), transformed_features, untransformed_features
)

@property
def transformed_features(self) -> "feature_group.FeatureGroup":
Expand All @@ -40,14 +47,13 @@ def id(self) -> str:

def to_dict(self):
return {
'id': self._id,
'transformed_log': self._transformed_features,
'untransformed_log': self._untransformed_features,
"id": self._id,
"transformed_log": self._transformed_features,
"untransformed_log": self._untransformed_features,
}

def json(self) -> Dict[str, Any]:
return json.dumps(self, cls=util.FeatureStoreEncoder)

def __repr__(self):
return self.json()

16 changes: 10 additions & 6 deletions python/hsfs/core/feature_view_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class FeatureViewApi:
_TRANSFORMED_lOG = "transformed"
_UNTRANSFORMED_LOG = "untransformed"


def __init__(self, feature_store_id: int) -> None:
self._feature_store_id = feature_store_id
self._client = client.get_instance()
Expand Down Expand Up @@ -407,7 +406,8 @@ def get_models_provenance(
def enable_feature_logging(
self,
feature_view_name: str,
feature_view_version: int,):
feature_view_version: int,
):
_client = client.get_instance()
path_params = self._base_path + [
feature_view_name,
Expand All @@ -420,7 +420,8 @@ def enable_feature_logging(
def pause_feature_logging(
self,
feature_view_name: str,
feature_view_version: int,):
feature_view_version: int,
):
_client = client.get_instance()
path_params = self._base_path + [
feature_view_name,
Expand All @@ -434,7 +435,8 @@ def pause_feature_logging(
def resume_feature_logging(
self,
feature_view_name: str,
feature_view_version: int,):
feature_view_version: int,
):
_client = client.get_instance()
path_params = self._base_path + [
feature_view_name,
Expand All @@ -448,7 +450,8 @@ def resume_feature_logging(
def materialize_feature_logging(
self,
feature_view_name: str,
feature_view_version: int,):
feature_view_version: int,
):
_client = client.get_instance()
path_params = self._base_path + [
feature_view_name,
Expand All @@ -469,7 +472,8 @@ def materialize_feature_logging(
def get_feature_logging(
self,
feature_view_name: str,
feature_view_version: int,):
feature_view_version: int,
):
_client = client.get_instance()
path_params = self._base_path + [
feature_view_name,
Expand Down
Loading

0 comments on commit 4e8aad8

Please sign in to comment.