Skip to content

Commit

Permalink
Perform ruff fixes and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
aversey committed Jun 27, 2024
1 parent 4b4ae38 commit 6783fd0
Show file tree
Hide file tree
Showing 48 changed files with 229 additions and 151 deletions.
1 change: 1 addition & 0 deletions python/hopsworks/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from hopsworks.client import external, hopsworks


_client = None
_python_version = None

Expand Down
5 changes: 2 additions & 3 deletions python/hopsworks/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
#

import os
import furl
from abc import ABC, abstractmethod

import furl
import requests
import urllib3

from hopsworks.client import exceptions, auth
from hopsworks.client import auth, exceptions
from hopsworks.decorators import connected


Expand Down
6 changes: 3 additions & 3 deletions python/hopsworks/client/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# limitations under the License.
#

import os
import base64
import requests
import os

from hopsworks.client import base, auth, exceptions
import requests
from hopsworks.client import auth, base, exceptions


class Client(base.Client):
Expand Down
4 changes: 2 additions & 2 deletions python/hopsworks/client/hopsworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from pathlib import Path

import requests
from hopsworks.client import auth, base

from hopsworks.client import base, auth

try:
import jks
Expand Down Expand Up @@ -134,7 +134,7 @@ def _convert_jks_to_pem(self, jks_path, keystore_pw):
ca_certs = ""

# Convert CA Certificates into PEM format and append to string
for alias, c in ks.certs.items():
for _alias, c in ks.certs.items():
ca_certs = ca_certs + self._bytes_to_pem_str(c.cert, "CERTIFICATE")
return ca_certs

Expand Down
11 changes: 6 additions & 5 deletions python/hopsworks/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

import os
import re
import warnings
import sys
import warnings

from requests.exceptions import ConnectionError

from hopsworks.decorators import connected, not_connected
from hopsworks import client, version
from hopsworks.core import project_api, secret_api, variable_api
from hopsworks.decorators import connected, not_connected
from requests.exceptions import ConnectionError


HOPSWORKS_PORT_DEFAULT = 443
HOSTNAME_VERIFICATION_DEFAULT = True
Expand Down Expand Up @@ -210,7 +210,8 @@ def _check_compatibility(self):
warnings.warn(
"The installed hopsworks client version {0} may not be compatible with the connected Hopsworks backend version {1}. \nTo ensure compatibility please install the latest bug fix release matching the minor version of your backend ({2}) by running 'pip install hopsworks=={2}.*'".format(
client_version, backend_version, major_minor_backend
)
),
stacklevel=1,
)
sys.stderr.flush()

Expand Down
13 changes: 6 additions & 7 deletions python/hopsworks/core/dataset_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
# limitations under the License.
#

import copy
import logging
import math
import os
import time
from tqdm.auto import tqdm
import shutil
import logging
import copy
import time
from concurrent.futures import ThreadPoolExecutor, wait

from hopsworks import client
from hopsworks.client.exceptions import RestAPIError
from hopsworks.client.exceptions import DatasetException
from concurrent.futures import ThreadPoolExecutor, wait
from hopsworks.client.exceptions import DatasetException, RestAPIError
from tqdm.auto import tqdm


class Chunk:
Expand Down
2 changes: 1 addition & 1 deletion python/hopsworks/core/environment_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ def _delete(self, python_version):
python_version,
]
headers = {"content-type": "application/json"}
_client._send_request("DELETE", path_params, headers=headers),
(_client._send_request("DELETE", path_params, headers=headers),)
10 changes: 7 additions & 3 deletions python/hopsworks/core/flink_cluster_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
# limitations under the License.
#

import os
import json
from hopsworks import client, flink_cluster, util, job
import os

from hopsworks import client, flink_cluster, job, util
from hopsworks.core import job_api
from python.hopsworks.client.exceptions import RestAPIError


class FlinkClusterApi:
Expand Down Expand Up @@ -69,7 +71,9 @@ def setup_cluster(self, name: str, config=None):
# If the job already exists, retrieve it
_flink_cluster = self.get_cluster(name)
if _flink_cluster._job.job_type != "FLINK":
raise "This is not a Flink cluster. Please use different name to create new Flink cluster"
raise RestAPIError(
"This is not a Flink cluster. Please use different name to create new Flink cluster"
)
return _flink_cluster
else:
# If the job doesn't exists, create a new job
Expand Down
18 changes: 9 additions & 9 deletions python/hopsworks/core/git_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
# limitations under the License.
#

import json
import logging
from typing import List, Union

from hopsworks import (
client,
git_repo,
git_op_execution,
util,
git_commit,
git_file_status,
git_op_execution,
git_repo,
util,
)
from hopsworks.client.exceptions import GitException
from hopsworks.engine import git_engine
from hopsworks.core import git_provider_api
from typing import List, Union
from hopsworks.engine import git_engine
from hopsworks.git_file_status import GitFileStatus

import json
import logging


class GitApi:
def __init__(
Expand Down Expand Up @@ -347,7 +347,7 @@ def _status(self, repo_id):

status_dict = json.loads(git_op.command_result_message)
file_status = None
if status_dict is not None and type(status_dict["status"]) is list:
if status_dict is not None and isinstance(status_dict["status"], list):
file_status = []
for status in status_dict["status"]:
file_status.append(
Expand Down
6 changes: 3 additions & 3 deletions python/hopsworks/core/git_provider_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# limitations under the License.
#

import json

from hopsworks import client, git_provider
from hopsworks.engine import git_engine
from hopsworks.client.exceptions import GitException

import json
from hopsworks.engine import git_engine


class GitProviderApi:
Expand Down
2 changes: 1 addition & 1 deletion python/hopsworks/core/job_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import json

from hopsworks import client, job, util, job_schedule
from hopsworks import client, job, job_schedule, util
from hopsworks.client.exceptions import RestAPIError


Expand Down
5 changes: 3 additions & 2 deletions python/hopsworks/core/kafka_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
# limitations under the License.
#

from hopsworks import client, kafka_topic, kafka_schema, constants
from hopsworks.client.exceptions import KafkaException
import json
import socket

from hopsworks import client, constants, kafka_schema, kafka_topic
from hopsworks.client.exceptions import KafkaException
from hopsworks.client.external import Client


Expand Down
3 changes: 2 additions & 1 deletion python/hopsworks/core/project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# limitations under the License.
#

from hopsworks import client, project, constants
import json

from hopsworks import client, constants, project
from hopsworks.client.exceptions import RestAPIError


Expand Down
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
4 changes: 2 additions & 2 deletions python/hopsworks/engine/environment_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import time

from hopsworks import client, library, environment, command
from hopsworks.client.exceptions import RestAPIError, EnvironmentException
from hopsworks import client, command, environment, library
from hopsworks.client.exceptions import EnvironmentException, RestAPIError


class EnvironmentEngine:
Expand Down
4 changes: 2 additions & 2 deletions python/hopsworks/engine/execution_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
# limitations under the License.
#

from hopsworks.core import dataset_api, execution_api
import os
import logging
import os
import time
import uuid

from hopsworks.client.exceptions import JobExecutionException, RestAPIError
from hopsworks.core import dataset_api, execution_api


class ExecutionEngine:
Expand Down
7 changes: 4 additions & 3 deletions python/hopsworks/engine/git_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
# limitations under the License.
#

from hopsworks.core import git_op_execution_api
from hopsworks.client.exceptions import GitException
import time
import logging
import time

from hopsworks.client.exceptions import GitException
from hopsworks.core import git_op_execution_api


class GitEngine:
Expand Down
2 changes: 1 addition & 1 deletion python/hopsworks/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# limitations under the License.
#

import humps
import os

import humps
from hopsworks import command, util
from hopsworks.core import environment_api, library_api
from hopsworks.engine import environment_engine
Expand Down
6 changes: 3 additions & 3 deletions python/hopsworks/flink_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#

import time
from hopsworks.engine import execution_engine
from hopsworks.core import execution_api
from hopsworks.core import flink_cluster_api

from hopsworks import util
from hopsworks.core import execution_api, flink_cluster_api
from hopsworks.engine import execution_engine


class FlinkCluster:
Expand Down
5 changes: 3 additions & 2 deletions python/hopsworks/git_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
# limitations under the License.
#

from hopsworks import util
import humps
import json

import humps
from hopsworks import util


class GitCommit:
def __init__(
Expand Down
2 changes: 1 addition & 1 deletion python/hopsworks/git_file_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# limitations under the License.
#

import humps
import json

import humps
from hopsworks import util


Expand Down
5 changes: 3 additions & 2 deletions python/hopsworks/git_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
# limitations under the License.
#

import humps
import json
from hopsworks.core import git_provider_api

import humps
from hopsworks import util
from hopsworks.core import git_provider_api


class GitProvider:
Expand Down
5 changes: 3 additions & 2 deletions python/hopsworks/git_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
# limitations under the License.
#

import humps
import json
from hopsworks.core import git_remote_api

import humps
from hopsworks import util
from hopsworks.core import git_remote_api


class GitRemote:
Expand Down
Loading

0 comments on commit 6783fd0

Please sign in to comment.