Skip to content

Commit

Permalink
ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
robzor92 committed Jul 3, 2024
1 parent 07cfbaa commit 37f63c1
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 27 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 @@ -31,7 +31,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 @@ -65,13 +71,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 @@ -142,4 +149,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
16 changes: 8 additions & 8 deletions python/hopsworks/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def install_wheel(self, path, 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

Expand Down Expand Up @@ -180,12 +180,12 @@ def install_requirements(self, path, await_installation: Optional[bool] = True):
"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
8 changes: 6 additions & 2 deletions python/hopsworks/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def created(self):
"""Timestamp when the project was created"""
return self._created

def get_feature_store(self, name: str = None, engine: str = None) -> feature_store.FeatureStore:
def get_feature_store(
self, name: str = None, engine: str = None
) -> feature_store.FeatureStore:
"""Connect to Project's Feature Store.
Defaulting to the project name of default feature store. To get a
Expand Down Expand Up @@ -142,7 +144,9 @@ def get_feature_store(self, name: str = None, engine: str = None) -> feature_sto
engine=engine,
).get_feature_store(name)
else:
return connection(engine=engine).get_feature_store(name) # If internal client
return connection(engine=engine).get_feature_store(
name
) # If internal client

def get_model_registry(self):
"""Connect to Project's Model Registry API.
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__")
1 change: 0 additions & 1 deletion python/tests/hopsworks/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def tearDown(self):
hopsworks.logout()

def _check_api_key_existence(self):

path = hopsworks._get_cached_api_key_path()

api_key_name = ".hw_api_key"
Expand Down

0 comments on commit 37f63c1

Please sign in to comment.