Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pylint and mypy warnings #572

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions mlos_bench/mlos_bench/event_loop_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
else:
from typing_extensions import TypeAlias

CoroReturnType = TypeVar('CoroReturnType') # pylint: disable=invalid-name
if sys.version_info >= (3, 9):
FutureReturnType: TypeAlias = Future[CoroReturnType]
else:
FutureReturnType: TypeAlias = Future


class EventLoopContext:
"""
Expand Down Expand Up @@ -78,12 +84,6 @@ def exit(self) -> None:
self._event_loop = None
self._event_loop_thread = None

CoroReturnType = TypeVar('CoroReturnType')
if sys.version_info >= (3, 9):
FutureReturnType: TypeAlias = Future[CoroReturnType]
else:
FutureReturnType: TypeAlias = Future

def run_coroutine(self, coro: Coroutine[Any, Any, CoroReturnType]) -> FutureReturnType:
"""
Runs the given coroutine in the background event loop thread and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def __init__(self,
methods : Union[Dict[str, Callable], List[Callable], None]
New methods to register with the service.
"""
# Same methods are also provided by the AzureVMService class
# pylint: disable=duplicate-code
super().__init__(
config, global_config, parent,
self.merge_methods(methods, [
Expand Down
19 changes: 2 additions & 17 deletions mlos_bench/mlos_bench/services/remote/ssh/ssh_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,18 @@

from abc import ABCMeta
from asyncio import Event as CoroEvent, Lock as CoroLock
from concurrent.futures import Future
from types import TracebackType
from typing import Any, Callable, Coroutine, Dict, List, Literal, Optional, Tuple, Type, TypeVar, Union
from typing import Any, Callable, Coroutine, Dict, List, Literal, Optional, Tuple, Type, Union
from threading import current_thread

import logging
import os
import sys

import asyncssh

from asyncssh.connection import SSHClientConnection

from mlos_bench.services.base_service import Service
from mlos_bench.event_loop_context import EventLoopContext

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

from mlos_bench.event_loop_context import EventLoopContext, CoroReturnType, FutureReturnType

_LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -284,12 +275,6 @@ def clear_client_cache(cls) -> None:
"""
cls._EVENT_LOOP_THREAD_SSH_CLIENT_CACHE.cleanup()

CoroReturnType = TypeVar('CoroReturnType')
if sys.version_info >= (3, 9):
FutureReturnType: TypeAlias = Future[CoroReturnType]
else:
FutureReturnType: TypeAlias = Future

def _run_coroutine(self, coro: Coroutine[Any, Any, CoroReturnType]) -> FutureReturnType:
"""
Runs the given coroutine in the background event loop thread.
Expand Down
14 changes: 6 additions & 8 deletions mlos_bench/mlos_bench/tests/services/remote/ssh/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@
@pytest.fixture(scope="session")
def ssh_test_server_hostname() -> str:
"""Returns the local hostname to use to connect to the test ssh server."""
if sys.platform == 'win32':
# Docker (Desktop) for Windows (WSL2) uses a special networking magic
# to refer to the host machine when exposing ports.
return 'localhost'
# On Linux, if we're running in a docker container, we can use the
# --add-host (extra_hosts in docker-compose.yml) to refer to the host IP.
if resolve_host_name(HOST_DOCKER_NAME):
if sys.platform != 'win32' and resolve_host_name(HOST_DOCKER_NAME):
bpkroth marked this conversation as resolved.
Show resolved Hide resolved
# On Linux, if we're running in a docker container, we can use the
# --add-host (extra_hosts in docker-compose.yml) to refer to the host IP.
return HOST_DOCKER_NAME
# Otherwise, assume we're executing directly inside conda on the host.
# Docker (Desktop) for Windows (WSL2) uses a special networking magic
# to refer to the host machine as `localhost` when exposing ports.
# In all other cases, assume we're executing directly inside conda on the host.
return 'localhost'


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_ssh_service_context_handler() -> None:
ssh_fileshare_service._run_coroutine(asyncio.sleep(0.1))

# The background thread should remain running since we have another context still open.
assert isinstance(SshService._EVENT_LOOP_CONTEXT._event_loop_thread, Thread) # type: ignore[unreachable]
assert isinstance(SshService._EVENT_LOOP_CONTEXT._event_loop_thread, Thread)
assert SshService._EVENT_LOOP_THREAD_SSH_CLIENT_CACHE is not None


Expand Down