Skip to content

Commit

Permalink
DP-1504 : update movai-core-shared (#201)
Browse files Browse the repository at this point in the history
* Update setup.py

* update movai-core-shared, fix function names, lint
  • Loading branch information
AlexFernandes-MOVAI authored Jun 3, 2024
1 parent 922aadb commit 2e73351
Show file tree
Hide file tree
Showing 22 changed files with 46 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
rev: 22.10.0
hooks:
- id: black
args: ["--line-length=120", "-S"]
args: ["--line-length=100", "-S"]

- repo: https://github.com/pycqa/flake8 # static tests Python code
rev: 5.0.4
Expand Down
4 changes: 1 addition & 3 deletions backend/core/log_streaming/log_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ async def listen_to_client_msgs(self):
async for msg in self._ws:
if msg.type == WSMsgType.TEXT:
if msg.data == "close":
self._logger.debug(
"closing the websocket connection for client id: {self._id}"
)
self._logger.debug("closing the websocket connection for client id: {self._id}")
await self._ws.close()
elif msg.type == WSMsgType.ERROR:
self._logger.error(
Expand Down
9 changes: 6 additions & 3 deletions backend/core/log_streaming/log_streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

ZMQ_PUBLISHER_ADDR = f"tcp://message-server:{MESSAGE_SERVER_LOG_PUBLISHER_PORT}"


class LogStreamer:
def __init__(self, debug: bool = False) -> None:
"""Initializes the object.
Expand All @@ -32,7 +33,9 @@ def __init__(self, debug: bool = False) -> None:
"""
self._debug = debug
self._logger = logging.getLogger(self.__class__.__name__)
self._subscriber: AsyncZMQSubscriber = ZMQManager.get_client(ZMQ_PUBLISHER_ADDR, ZMQType.ASYNC_SUBSCRIBER)
self._subscriber: AsyncZMQSubscriber = ZMQManager.get_client(
ZMQ_PUBLISHER_ADDR, ZMQType.ASYNC_SUBSCRIBER
)
self._clients = {}
self._running = False

Expand Down Expand Up @@ -105,9 +108,9 @@ async def handle(self, request: dict) -> dict:

async def listen(self):
while self._running:
msg = await self._subscriber.recieve()
msg = await self._subscriber.receive()
await self.handle(msg)

def start(self):
self._running = True
self._logger.info("starting log streamer server!")
Expand Down
14 changes: 7 additions & 7 deletions backend/docs/git-v2-2.4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ paths:
schema:
type: string
description: relative path of the desired file inside the repo.
responses:
responses:
"200":
description: a model json object. schema can be found in dal/validation/schema/
"400":
Expand Down Expand Up @@ -107,7 +107,7 @@ paths:
schema:
type: string
description: relative path of the desired file inside the repo.
responses:
responses:
"200":
description: commit_sha
content:
Expand Down Expand Up @@ -157,7 +157,7 @@ paths:
schema:
type: string
description: relative path of the desired file inside the repo.
responses:
responses:
"200":
description: commit_sha, the new commit created.
content:
Expand Down Expand Up @@ -194,7 +194,7 @@ paths:
type: string
- in: path
description: the project id.
name: project
name: project
required: true
schema:
type: string
Expand All @@ -210,7 +210,7 @@ paths:
schema:
type: string
description: relative path of the desired file inside the repo.
responses:
responses:
"200":
description: a model json object. schema can be found in dal/validation/schema/.
"400":
Expand Down Expand Up @@ -242,7 +242,7 @@ paths:
type: string
- in: path
description: the project id.
name: project
name: project
required: true
schema:
type: string
Expand Down Expand Up @@ -404,7 +404,7 @@ paths:
"403":
description: Git Server Permission Error or SSH key not found on system.
"404":
description: File or repository NOT Found, the reason will be attached to
description: File or repository NOT Found, the reason will be attached to


/{remote}/{user}/{project}/version/{base_version}/{tag}:
Expand Down
9 changes: 4 additions & 5 deletions backend/docs/notifications-v2-2.4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ paths:
recipients: ["[email protected]"]
subject: "Error on Tugbot 8"
body: "reset robot by pressing Emergency button"
responses:
responses:
"200":
description: a model json object. schema can be found in dal/validation/schema/

/user:
post:
summary: send a user notification message.
Expand Down Expand Up @@ -80,8 +80,7 @@ paths:
example:
robot_name: ["tugbot2"]
msg: "Error on Tugbot 8"
responses:

responses:
"200":
description: notification pushed successfully to the redis.

1 change: 0 additions & 1 deletion backend/endpoints/api/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
Root module of API web modules
"""
from . import v1

15 changes: 3 additions & 12 deletions backend/endpoints/api/v1/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,7 @@
from .taskmanager import taskmanager_action_map, taskmanager_enterprise_map

frontend_map = {
"fleetmanager": {
"action": fleetmanager_action_map,
"enterprise": fleetmanager_enterprise_map
},
"ide": {
"action": ide_action_map,
"enterprise": ide_enterprise_map
},
"taskmanager": {
"action": taskmanager_action_map,
"enterprise": taskmanager_enterprise_map
}
"fleetmanager": {"action": fleetmanager_action_map, "enterprise": fleetmanager_enterprise_map},
"ide": {"action": ide_action_map, "enterprise": ide_enterprise_map},
"taskmanager": {"action": taskmanager_action_map, "enterprise": taskmanager_enterprise_map},
}
4 changes: 2 additions & 2 deletions backend/endpoints/api/v1/frontend/fleetmanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# Tasks
"getTasks": Tasks.get_tasks,
"saveTask": Tasks.save_task,
"deleteTask": Tasks.delete_task
"deleteTask": Tasks.delete_task,
}

fleetmanager_enterprise_map = {
Expand All @@ -33,5 +33,5 @@
# Tasks
"getTasks": Tasks.get_tasks,
"saveTask": Tasks.save_task,
"deleteTask": Tasks.delete_task
"deleteTask": Tasks.delete_task,
}
2 changes: 1 addition & 1 deletion backend/endpoints/api/v1/frontend/taskmanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
# Api
"gen_task": on_gen_task,
# genereate_sde
"gen_shared_data_entries": gen_shared_data_entries
"gen_shared_data_entries": gen_shared_data_entries,
}
4 changes: 3 additions & 1 deletion backend/endpoints/api/v1/frontend/taskmanager/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
try:
from movai_core_enterprise.gdnode.taskgenerator import TaskGenerator
except ImportError:
LOGGER.warning("Failed to import TaskGenerator, because movai_core_enterprise is not installed.")
LOGGER.warning(
"Failed to import TaskGenerator, because movai_core_enterprise is not installed."
)


def on_gen_task():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
try:
from movai_core_enterprise.scopes.shareddataentry import SharedDataEntry
except ImportError:
LOGGER.warning("Failed to import SharedDataEntry, because movai_core_enterprise is not installed.")
LOGGER.warning(
"Failed to import SharedDataEntry, because movai_core_enterprise is not installed."
)


def get_falsy_values(data_type="str"):
Expand Down
4 changes: 3 additions & 1 deletion backend/endpoints/api/v1/restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ async def frontend_apps(self, request: web.Request):
raise ValueError("the 'func' argument is missing in request's body!")

if func not in action_map:
raise ValueError(f"{func} unknown function, it is not found in the {app} action map.")
raise ValueError(
f"{func} unknown function, it is not found in the {app} action map."
)

if func in enterprise_map and not is_enterprise():
raise NotSupported(f"The {func} method is not supported for community edition.")
Expand Down
5 changes: 1 addition & 4 deletions backend/endpoints/api/v1/robot_reovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ def recovery_timeout(robot_id):
recovery_state = var_scope.get(RECOVERY_STATE_KEY)

if recovery_state == RecoveryStates.PUSHED.name:
response = {
"success": False,
"message": "Failed to recover robot"
}
response = {"success": False, "message": "Failed to recover robot"}
var_scope.set(RECOVERY_RESPONSE_KEY, response)
var_scope.set(RECOVERY_STATE_KEY, RecoveryStates.NOT_AVAILABLE.name)
except Exception as exc:
Expand Down
2 changes: 1 addition & 1 deletion backend/endpoints/api/v1/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def routes(self) -> List[web.RouteDef]:
web.get(r"/{scope:%s}/" % REST_SCOPES, self._rest_api.get_scope),
web.post(r"/{scope:%s}/" % REST_SCOPES, self._rest_api.post_to_scope),
web.get(r"/callback-builtins/", self._rest_api.get_callback_builtins),
web.post(r"/frontend/{app}/", self._rest_api.frontend_apps)
web.post(r"/frontend/{app}/", self._rest_api.frontend_apps),
]

@property
Expand Down
1 change: 0 additions & 1 deletion backend/endpoints/api/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@
from . import ldapconfig
from . import notifications
from . import role

2 changes: 1 addition & 1 deletion backend/endpoints/api/v2/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def db_get(cls) -> "AlertsConfig":

def db_set(self) -> None:
"""
Set current alerts config object in global Var with the recieved dict
Set current alerts config object in global Var with the received dict
"""
setattr(self.Meta.var, self.Meta.ALERTS_GLOBAL_VAR_STR, self.dict())

Expand Down
6 changes: 2 additions & 4 deletions backend/endpoints/api/v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,11 @@ def extract_object(self, exception: MovaiException = DoesNotExist):
raise exception(error_msg)

async def extract_data(self):
"""Extracts payload data from the request.
"""
"""Extracts payload data from the request."""
self._data = await self._request.json()

async def extract_params(self):
"""Extract parametes from query string.
"""
"""Extract parametes from query string."""
for param in self._request.query_string.split("&"):
name, value = param.split("=")
self._params[name] = value
Expand Down
1 change: 0 additions & 1 deletion backend/endpoints/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,4 @@ def get_domains(self, request: web.Request) -> web.Response:
return web.json_response(output, headers={"Server": "Movai-server"})



WebAppManager.register("/auth/", AuthApp)
2 changes: 1 addition & 1 deletion backend/endpoints/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def routes(self) -> List[web.RouteDef]:
return [
web.get("/widget/support", self.test_support),
web.get(self.redis_sub.http_endpoint, self.redis_sub.handler),
web.get("/logs", stream_logs)
web.get("/logs", stream_logs),
]

@property
Expand Down
4 changes: 3 additions & 1 deletion backend/helpers/rest_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from aiohttp import web


def deprecate_endpoint() -> None:
"""This is a helper function to deprecate unused functions
Expand All @@ -8,6 +9,7 @@ def deprecate_endpoint() -> None:
"""
raise web.HTTPForbidden(reason="This endpoint is deprecated")


def fetch_request_params(request: dict) -> dict:
"""fetches the params from the request and returns them in a dictionary.
Expand All @@ -26,4 +28,4 @@ def fetch_request_params(request: dict) -> dict:
else:
name, value = request.query_string.split("=")
params[name] = value
return params
return params
3 changes: 1 addition & 2 deletions docs/api/v2/email_alerts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ paths:
schema:
type: array
items:
type: string
type: string
example:
["Battery", "Temparature"]
components:
Expand Down Expand Up @@ -109,4 +109,3 @@ components:
type: array
items:
type: string

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"PyYAML==6.0",
"email-validator==2.0.0",
"pytz==2022.7.1",
"movai-core-shared==2.5.0.16",
"movai-core-shared==2.5.0.17",
"data-access-layer==2.5.0.21",
"gd-node==2.5.0.17"
"gd-node==2.5.0.17",
]


Expand Down

0 comments on commit 2e73351

Please sign in to comment.