Skip to content

Commit

Permalink
flake8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-costa-techlabs committed Aug 21, 2024
1 parent 04e9d19 commit 417d32b
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/commands/config/config_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ConfigSet(Command):
mongodb.cluster
Indicates whether a MongoDB cluster is being used (true/false).
mongodb.cluster_secret_key
This key is uploaded to all nodes within the MongoDB cluster. It is used for mutual authentication between nodes, ensuring that only authorized nodes can communicate with each other.
Expand Down
2 changes: 1 addition & 1 deletion src/commands/das/das_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)


class PermissionError(Exception): ...
class PermissionError(Exception): ... # noqa: E701


class DasCliUpdateVersion(Command):
Expand Down
4 changes: 2 additions & 2 deletions src/commands/das/das_ubuntu_advanced_packaging_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from typing import Tuple, Union


class DasError(Exception): ...
class DasError(Exception): ... # noqa: E701


class DasNotFoundError(DasError): ...
class DasNotFoundError(DasError): ... # noqa: E701


class DasUbuntuAdvancedPackagingTool:
Expand Down
28 changes: 17 additions & 11 deletions src/commands/db/db_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _redis_node(self, context, ip, username):
)

def _redis(self):
self.stdout(f"Stopping Redis service...")
self.stdout("Stopping Redis service...")

redis_nodes = self._settings.get("redis.nodes", [])

Expand All @@ -70,7 +70,7 @@ def _redis(self):
self._redis_node(**redis_node)
except DockerError as e:
self.stdout(
f"\nError occurred while trying to stop Redis\n",
"\nError occurred while trying to stop Redis\n",
severity=StdoutSeverity.ERROR,
)
raise e
Expand All @@ -93,7 +93,7 @@ def _mongodb_node(self, context, ip, username):
)

def _mongodb(self):
self.stdout(f"Stopping MongoDB service...")
self.stdout("Stopping MongoDB service...")

mongodb_nodes = self._settings.get("mongodb.nodes", [])

Expand All @@ -103,7 +103,7 @@ def _mongodb(self):

except DockerError as e:
self.stdout(
f"\nError occurred while trying to stop MongoDB\n",
"\nError occurred while trying to stop MongoDB\n",
severity=StdoutSeverity.ERROR,
)
raise e
Expand Down Expand Up @@ -170,14 +170,14 @@ def _redis_node(
f"Redis is already running. It is currently listening on port {redis_port} at {node_ip} under the server user {node_username}.",
severity=StdoutSeverity.WARNING,
)
except DockerError as e:
except DockerError:
self.stdout(
f"\nError occurred while trying to start Redis on port {redis_port} at {node_ip} under the server user {node_username}.\n",
severity=StdoutSeverity.ERROR,
)

def _redis(self) -> None:
self.stdout(f"Starting Redis service...")
self.stdout("Starting Redis service...")

redis_port = self._settings.get("redis.port")
redis_nodes = self._settings.get("redis.nodes", [])
Expand All @@ -191,7 +191,7 @@ def _redis(self) -> None:
self._redis_container_manager.start_cluster(redis_nodes, redis_port)
except Exception as e:
self.stdout(
f"\nFailed to start the cluster. Please check the conectivity between the nodes and try again.\n",
"\nFailed to start the cluster. Please check the conectivity between the nodes and try again.\n",
severity=StdoutSeverity.ERROR,
)
raise e
Expand Down Expand Up @@ -246,7 +246,7 @@ def _mongodb_node(
raise e

def _mongodb(self) -> None:
self.stdout(f"Starting MongoDB service...")
self.stdout("Starting MongoDB service...")

mongodb_port = self._settings.get("mongodb.port")
mongodb_username = self._settings.get("mongodb.username")
Expand Down Expand Up @@ -275,7 +275,7 @@ def _mongodb(self) -> None:
)
except Exception as e:
self.stdout(
f"\nFailed to start the cluster. Please check the conectivity between the nodes and try again.\n",
"\nFailed to start the cluster. Please check the conectivity between the nodes and try again.\n",
severity=StdoutSeverity.ERROR,
)
raise e
Expand All @@ -293,7 +293,9 @@ class DbRestart(Command):
short_help = "Restart all DBMS containers."

help = """
'das-cli db restart' restarts all database containers previously started with 'das-cli start'. If no database have been started, 'das-cli db restart' just start them.
'das-cli db restart' restarts all database containers previously started with
'das-cli start'. If no database have been started, 'das-cli db restart' just
start them.
IMPORTANTE NOTE: Restarting the databases will result in all data being lost. Databases are started empty.
Expand All @@ -320,7 +322,11 @@ class DbCli(CommandGroup):

short_help = "Manage db-related operations."

help = "'das-cli db' commands allow you to manage DAS backend DBMSs for use with the DAS CLI. 'das-cli db' provides commands to start, stop, and restart the databases as needed."
help = """
'das-cli db' commands allow you to manage DAS backend DBMSs for use
with the DAS CLI. 'das-cli db' provides commands to start, stop, and
restart the databases as needed.
"""

@inject
def __init__(
Expand Down
55 changes: 43 additions & 12 deletions src/commands/faas/faas_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ class FaaSStop(Command):
short_help = "Stop the running OpenFaaS service.."

help = """
'das-cli faas stop' allows you to stop the execution of the DAS function in OpenFaaS. This is useful for terminating the function's operation when it's no longer needed. After stopping the faas, the function will no longer be available and cannot be used with the DAS.
'das-cli faas stop' allows you to stop the execution of the DAS function in
OpenFaaS. This is useful for terminating the function's operation when it's no
longer needed. After stopping the faas, the function will no longer be
available and cannot be used with the DAS.
.SH EXAMPLES
Expand All @@ -62,7 +65,7 @@ def __init__(self, settings: Settings) -> None:
def run(self):
self._settings.raise_on_missing_file()

self.stdout(f"Stopping OpenFaaS service...")
self.stdout("Stopping OpenFaaS service...")

openfaas_container_name = self._settings.get("openfaas.container_name")

Expand All @@ -80,12 +83,24 @@ class FaaSStart(Command):

short_help = "Start OpenFaaS service."

help = """
OpenFaaS, an open-source serverless computing platform, makes running functions in containers fast and simple. With this command, you can initialize the DAS remotely through a function in OpenFaaS, which can be run on your server or locally.
If you've just installed the DAS CLI, the function will be executed using the latest version by default. However, if you want to specify a particular version, you can use the faas update-version command. Versions are available at https://github.com/singnet/das-serverless-functions/releases, or you can choose to leave it as latest, which will always use the latest available version.
Since the function needs to communicate with databases, you need to run db start to establish this communication. Upon the first execution of the function, it might take a little longer as it needs to fetch the specified version and set everything up for you. Subsequent initializations will be faster unless you change the version, which will require the same process again to set everything up.
help = r"""
OpenFaaS, an open-source serverless computing platform, makes running functions
in containers fast and simple. With this command, you can initialize the DAS
remotely through a function in OpenFaaS, which can be run on your server or
locally.
If you've just installed the DAS CLI, the function will be executed using the
latest version by default. However, if you want to specify a particular
version, you can use the faas update-version command. Versions are available at
https://github.com/singnet/das-serverless-functions/releases, or you can choose
to leave it as latest, which will always use the latest available version.
Since the function needs to communicate with databases, you need to run db
start to establish this communication. Upon the first execution of the
function, it might take a little longer as it needs to fetch the specified
version and set everything up for you. Subsequent initializations will be
faster unless you change the version, which will require the same process again
to set everything up.
.B
Ensure that the following ports are open:
Expand All @@ -99,7 +114,8 @@ class FaaSStart(Command):
.IP \[bu] 2
Port 5000: For the watchdog
After starting the function, you will receive a message on the screen with the function version and the port on which the function is being executed.
After starting the function, you will receive a message on the screen with the
function version and the port on which the function is being executed.
.SH EXAMPLES
Expand Down Expand Up @@ -209,7 +225,12 @@ class FaaSRestart(Command):
short_help = "Restart OpenFaaS service."

help = """
'das-cli faas restart' restarts OpenFaaS server container. This is useful when you want to restart the function to apply configuration changes. During this process, there is typically a downtime until the function is running again and deemed healthy. This downtime occurs because the existing instance of the function needs to be stopped, and then a new instance needs to be started with the updated configuration or changes.
'das-cli faas restart' restarts OpenFaaS server container. This is useful when
you want to restart the function to apply configuration changes. During this
process, there is typically a downtime until the function is running again and
deemed healthy. This downtime occurs because the existing instance of the
function needs to be stopped, and then a new instance needs to be started with
the updated configuration or changes.
.SH EXAMPLES
Expand All @@ -235,7 +256,10 @@ class FaaSVersion(Command):
short_help = "Get OpenFaaS function version."

help = """
'das-cli faas version' is used to display the current version of the DAS function in OpenFaaS. This command is particularly useful for checking the version of the deployed function, which can be helpful troubleshooting issues, or ensuring compatibility.
'das-cli faas version' is used to display the current version of the DAS
function in OpenFaaS. This command is particularly useful for checking the
version of the deployed function, which can be helpful troubleshooting issues,
or ensuring compatibility.
.SH EXAMPLES
Expand Down Expand Up @@ -275,7 +299,14 @@ class FaaSUpdateVersion(Command):
short_help = "Update an OpenFaaS service to a newer version."

help = """
'das-cli update-version' allows you to update the version of your function in OpenFaaS. All available versions can be found at https://github.com/singnet/das-serverless-functions/releases. This command has two optional parameters. When executed without parameters, it will fetch the latest version of the 'query-engine' function and update it on your local server if a newer version is found. You can also specify the function you want to update in OpenFaaS (currently only 'query-engine' is available), and define the version of the function you want to use, as mentioned earlier.
'das-cli update-version' allows you to update the version of your function in
OpenFaaS. All available versions can be found at
https://github.com/singnet/das-serverless-functions/releases. This command has
two optional parameters. When executed without parameters, it will fetch the
latest version of the 'query-engine' function and update it on your local
server if a newer version is found. You can also specify the function you want
to update in OpenFaaS (currently only 'query-engine' is available), and define
the version of the function you want to use, as mentioned earlier.
.SH EXAMPLES
Expand Down
2 changes: 1 addition & 1 deletion src/commands/jupyter_notebook/jupyter_notebook_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(self, settings: Settings) -> None:
def run(self):
self._settings.raise_on_missing_file()

self.stdout(f"Stopping jupyter notebook...")
self.stdout("Stopping jupyter notebook...")

jupyter_notebook_container_name = self._settings.get("jupyter_notebook.container_name")

Expand Down
6 changes: 3 additions & 3 deletions src/commands/python_library/python_library_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import requests


class PackageError(Exception): ...
class PackageError(Exception): ... # noqa: E701


class PackageNotFoundError(PackageError): ...
class PackageNotFoundError(PackageError): ... # noqa: E701


class PythonLibraryPackage:
Expand Down Expand Up @@ -59,7 +59,7 @@ def get_version(self, package_name):
raise PackageNotFoundError(
f"Version information not found for package '{package_name}'."
)
except subprocess.CalledProcessError as e:
except subprocess.CalledProcessError:
raise PackageNotFoundError(f"Package '{package_name}' is not installed.")

def update_version(self, package_name, version=None):
Expand Down
4 changes: 2 additions & 2 deletions src/commands/release_notes/release_notes_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from config import RELEASE_NOTES_URL


class ReleaseNoteError(Exception): ...
class ReleaseNoteError(Exception): ... # noqa: E701


class ReleaseNoteNotFound(ReleaseNoteError): ...
class ReleaseNoteNotFound(ReleaseNoteError): ... # noqa: E701


class Library:
Expand Down
32 changes: 31 additions & 1 deletion src/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from .logger import logger
from .module import Module
from .network import get_public_ip
from .prompt_types import Choice, FunctionVersion, IntRange, Path, ReachableIpAddress
from .prompt_types import FunctionVersion, ReachableIpAddress
from click import Choice, IntRange, Path
from .settings import JsonHandler, Settings
from .utils import (
get_rand_token,
Expand All @@ -20,3 +21,32 @@
is_executable_bin,
remove_special_characters,
)

__all__ = [
"ssh",
"Command",
"CommandArgument",
"CommandGroup",
"CommandOption",
"StdoutSeverity",
"StdoutType",
"Container",
"ContainerManager",
"ImageManager",
"RemoteContextManager",
"logger",
"Module",
"get_public_ip",
"Choice",
"FunctionVersion",
"IntRange",
"Path",
"ReachableIpAddress",
"JsonHandler",
"Settings",
"get_rand_token",
"get_script_name",
"get_server_username",
"is_executable_bin",
"remove_special_characters",
]
2 changes: 2 additions & 0 deletions src/common/docker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .container_manager import Container, ContainerManager
from .image_manager import ImageManager
from .remote_context_manager import RemoteContextManager

__all__ = ["Container", "ContainerManager", "ImageManager", "RemoteContextManager"]
3 changes: 2 additions & 1 deletion src/common/docker/container_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def stop(self):

try:
container.kill()
except:
# TODO: better exception handling, for now do not use bare except
except Exception:
pass

try:
Expand Down
6 changes: 0 additions & 6 deletions src/common/docker/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ class DockerContainerNotFoundError(DockerError):
pass


class DockerImageNotFoundError(DockerError):
"""Exception raised when a specified image cannot be found."""

pass


class DockerImageNotFoundError(DockerError):
"""Exception raised when a specified Docker image cannot be found."""

Expand Down
2 changes: 1 addition & 1 deletion src/common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from config.config import LOG_FILE_NAME


class LoggerError(Exception): ...
class LoggerError(Exception): ... # noqa: E701


class Logger:
Expand Down
3 changes: 2 additions & 1 deletion src/common/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
def get_public_ip():
try:
return requests.get("https://api.ipify.org").content.decode("utf8")
except:
# TODO: better exception handler, for now do not use bare except
except Exception:
return None


Expand Down
2 changes: 1 addition & 1 deletion src/common/prompt_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from typing import Union

from click import Choice, IntRange, ParamType, Path
from click import ParamType

from common.network import is_server_port_available

Expand Down
Loading

0 comments on commit 417d32b

Please sign in to comment.