Skip to content

Commit

Permalink
Fixing some linter issues
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
erikbosch committed Jul 5, 2023
1 parent f99ae3d commit 09ca9b1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
12 changes: 2 additions & 10 deletions kuksa-client/kuksa_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions kuksa-client/kuksa_client/cli_backend/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions kuksa-client/kuksa_client/cli_backend/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion kuksa-client/kuksa_client/grpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion kuksa-client/kuksa_client/grpc/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from typing import Dict
from typing import Iterable
from typing import List
from typing import Optional
import uuid

import grpc
Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion kuksa-client/setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 09ca9b1

Please sign in to comment.