From 15cb70b8205d9a82bed4124c45166f4ee354569b Mon Sep 17 00:00:00 2001 From: Erik Jaegervall Date: Fri, 30 Jun 2023 13:01:13 +0200 Subject: [PATCH] Fixing some linter issues I tried running mypy, pylint and flake8. Nothing alarming found but many false positives, so we are not mature to enable them in CI. This addresses some low hanging fruits. --- kuksa-client/kuksa_client/__init__.py | 12 ++---------- kuksa-client/kuksa_client/cli_backend/grpc.py | 13 +++++++------ kuksa-client/kuksa_client/cli_backend/ws.py | 4 ++-- kuksa-client/kuksa_client/grpc/__init__.py | 2 +- kuksa-client/kuksa_client/grpc/aio.py | 3 ++- kuksa-client/setup.py | 14 +++++++++++++- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/kuksa-client/kuksa_client/__init__.py b/kuksa-client/kuksa_client/__init__.py index 2d7cb608b..4a3064a5c 100644 --- a/kuksa-client/kuksa_client/__init__.py +++ b/kuksa-client/kuksa_client/__init__.py @@ -19,19 +19,11 @@ ######################################################################## import asyncio -import json -import os -import queue -import ssl -import sys import threading -import time from typing import Any from typing import Dict from typing import Iterable -import uuid - -from kuksa_client._metadata import * +from typing import Optional from . import cli_backend @@ -52,7 +44,7 @@ def stop(self): self.backend.stop() # Do authorization by passing a jwt token or a token file - def authorize(self, token_or_tokenfile: str=None, timeout=5): + def authorize(self, token_or_tokenfile: Optional[str]=None, timeout=5): return self.backend.authorize(token_or_tokenfile, timeout) # Update VSS Tree Entry diff --git a/kuksa-client/kuksa_client/cli_backend/grpc.py b/kuksa-client/kuksa_client/cli_backend/grpc.py index 0c177de05..784f9dbec 100644 --- a/kuksa-client/kuksa_client/cli_backend/grpc.py +++ b/kuksa-client/kuksa_client/cli_backend/grpc.py @@ -25,6 +25,7 @@ from typing import Callable from typing import Dict from typing import Iterable +from typing import Optional import uuid import os import re @@ -144,12 +145,12 @@ def setValues(self, updates: Dict[str, Any], attribute="value", timeout=5): return json.dumps({"error": "Invalid Attribute"}) # Function for authorization - def authorize(self, token_or_tokenfile:str =None, timeout=5): + def authorize(self, token_or_tokenfile:Optional[str] =None, timeout=5): if token_or_tokenfile is None: token_or_tokenfile = self.token_or_tokenfile if os.path.isfile(token_or_tokenfile): - token_or_tokenfile = pathlib.Path(token_or_tokenfile) - token = token_or_tokenfile.expanduser().read_text(encoding='utf-8').rstrip('\n') + token_or_tokenfile_path = pathlib.Path(token_or_tokenfile) + token = token_or_tokenfile_path.expanduser().read_text(encoding='utf-8').rstrip('\n') else: token = token_or_tokenfile requestArgs = { @@ -178,12 +179,12 @@ def subscribeMultiple(self, paths: Iterable[str], callback, attribute="value", t # Unsubscribe value changes of to a given path. # The subscription id from the response of the corresponding subscription request will be required - def unsubscribe(self, sub_id: int, timeout=5): + def unsubscribe(self, sub_id: str, timeout=5): try: - sub_id = uuid.UUID(sub_id) + sub_uuid = uuid.UUID(sub_id) except ValueError as exc: return json.dumps({"error": str(exc)}) - requestArgs = {'subscription_id': sub_id} + requestArgs = {'subscription_id': sub_uuid} return self._sendReceiveMsg(("unsubscribe", requestArgs), timeout) def connect(self, timeout=5): diff --git a/kuksa-client/kuksa_client/cli_backend/ws.py b/kuksa-client/kuksa_client/cli_backend/ws.py index 260a3667e..d2ad2e02b 100644 --- a/kuksa-client/kuksa_client/cli_backend/ws.py +++ b/kuksa-client/kuksa_client/cli_backend/ws.py @@ -113,7 +113,7 @@ def stop(self): self.run = False print("Server disconnected.") - def disconnect(self): + def disconnect(self, _): self.stop() # Function to authorize against the kuksa.val server @@ -228,7 +228,7 @@ def unsubscribe(self, subId, timeout=5): def checkConnection(self): return self.wsConnected - async def connect(self): + async def connect(self, _=None): if not self.insecure: context = ssl.create_default_context() context.load_cert_chain( diff --git a/kuksa-client/kuksa_client/grpc/__init__.py b/kuksa-client/kuksa_client/grpc/__init__.py index 1d5c7ab56..fe5d78222 100644 --- a/kuksa-client/kuksa_client/grpc/__init__.py +++ b/kuksa-client/kuksa_client/grpc/__init__.py @@ -911,7 +911,7 @@ def authorize(self, token: str, **rpc_kwargs) -> str: return "Authenticated" @check_connected - def get_server_info(self, **rpc_kwargs) -> ServerInfo: + def get_server_info(self, **rpc_kwargs) -> Optional[ServerInfo]: """ Parameters: rpc_kwargs diff --git a/kuksa-client/kuksa_client/grpc/aio.py b/kuksa-client/kuksa_client/grpc/aio.py index 118139740..d8a90c89c 100644 --- a/kuksa-client/kuksa_client/grpc/aio.py +++ b/kuksa-client/kuksa_client/grpc/aio.py @@ -25,6 +25,7 @@ from typing import Dict from typing import Iterable from typing import List +from typing import Optional import uuid import grpc @@ -345,7 +346,7 @@ async def authorize(self, token: str, **rpc_kwargs) -> str: return "Authenticated" @check_connected_async - async def get_server_info(self, **rpc_kwargs) -> ServerInfo: + async def get_server_info(self, **rpc_kwargs) -> Optional[ServerInfo]: """ Parameters: rpc_kwargs diff --git a/kuksa-client/setup.py b/kuksa-client/setup.py index 6ecfe0d0c..fcea7cb6e 100644 --- a/kuksa-client/setup.py +++ b/kuksa-client/setup.py @@ -1,3 +1,15 @@ +# /******************************************************************************** +# * Copyright (c) 2023 Contributors to the Eclipse Foundation +# * +# * See the NOTICE file(s) distributed with this work for additional +# * information regarding copyright ownership. +# * +# * This program and the accompanying materials are made available under the +# * terms of the Apache License 2.0 which is available at +# * http://www.apache.org/licenses/LICENSE-2.0 +# * +# * SPDX-License-Identifier: Apache-2.0 +# ********************************************************************************/ import setuptools try: from setuptools.command import build @@ -7,7 +19,7 @@ from setuptools.command import sdist -class BuildPackageProtos: +class BuildPackageProtos(setuptools.Command): def run(self): self.run_command('build_pb2') return super().run()