Skip to content

BizHawkClient: Minor linting/style #3335

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

Merged
merged 1 commit into from
May 23, 2024
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
2 changes: 1 addition & 1 deletion worlds/_bizhawk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async def connect(ctx: BizHawkContext) -> bool:
return True
except (TimeoutError, ConnectionRefusedError):
continue

# No ports worked
ctx.streams = None
ctx.connection_status = ConnectionStatus.NOT_CONNECTED
Expand Down
14 changes: 6 additions & 8 deletions worlds/_bizhawk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
A module containing the BizHawkClient base class and metaclass
"""


from __future__ import annotations

import abc
Expand All @@ -12,14 +11,13 @@

if TYPE_CHECKING:
from .context import BizHawkClientContext
else:
BizHawkClientContext = object


def launch_client(*args) -> None:
from .context import launch
launch_subprocess(launch, name="BizHawkClient")


component = Component("BizHawk Client", "BizHawkClient", component_type=Type.CLIENT, func=launch_client,
file_identifier=SuffixIdentifier())
components.append(component)
Expand Down Expand Up @@ -56,7 +54,7 @@ def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any])
return new_class

@staticmethod
async def get_handler(ctx: BizHawkClientContext, system: str) -> Optional[BizHawkClient]:
async def get_handler(ctx: "BizHawkClientContext", system: str) -> Optional[BizHawkClient]:
for systems, handlers in AutoBizHawkClientRegister.game_handlers.items():
if system in systems:
for handler in handlers.values():
Expand All @@ -77,7 +75,7 @@ class BizHawkClient(abc.ABC, metaclass=AutoBizHawkClientRegister):
"""The file extension(s) this client is meant to open and patch (e.g. ".apz3")"""

@abc.abstractmethod
async def validate_rom(self, ctx: BizHawkClientContext) -> bool:
async def validate_rom(self, ctx: "BizHawkClientContext") -> bool:
"""Should return whether the currently loaded ROM should be handled by this client. You might read the game name
from the ROM header, for example. This function will only be asked to validate ROMs from the system set by the
client class, so you do not need to check the system yourself.
Expand All @@ -86,18 +84,18 @@ async def validate_rom(self, ctx: BizHawkClientContext) -> bool:
as necessary (such as setting `ctx.game = self.game`, modifying `ctx.items_handling`, etc...)."""
...

async def set_auth(self, ctx: BizHawkClientContext) -> None:
async def set_auth(self, ctx: "BizHawkClientContext") -> None:
"""Should set ctx.auth in anticipation of sending a `Connected` packet. You may override this if you store slot
name in your patched ROM. If ctx.auth is not set after calling, the player will be prompted to enter their
username."""
pass

@abc.abstractmethod
async def game_watcher(self, ctx: BizHawkClientContext) -> None:
async def game_watcher(self, ctx: "BizHawkClientContext") -> None:
"""Runs on a loop with the approximate interval `ctx.watcher_timeout`. The currently loaded ROM is guaranteed
to have passed your validator when this function is called, and the emulator is very likely to be connected."""
...

def on_package(self, ctx: BizHawkClientContext, cmd: str, args: dict) -> None:
def on_package(self, ctx: "BizHawkClientContext", cmd: str, args: dict) -> None:
"""For handling packages from the server. Called from `BizHawkClientContext.on_package`."""
pass
8 changes: 4 additions & 4 deletions worlds/_bizhawk/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
checking or launching the client, otherwise it will probably cause circular import issues.
"""


import asyncio
import enum
import subprocess
Expand Down Expand Up @@ -77,7 +76,7 @@ def on_package(self, cmd, args):
if self.client_handler is not None:
self.client_handler.on_package(self, cmd, args)

async def server_auth(self, password_requested: bool = False):
async def server_auth(self, password_requested: bool=False):
self.password_requested = password_requested

if self.bizhawk_ctx.connection_status != ConnectionStatus.CONNECTED:
Expand All @@ -103,7 +102,7 @@ async def server_auth(self, password_requested: bool = False):
await self.send_connect()
self.auth_status = AuthStatus.PENDING

async def disconnect(self, allow_autoreconnect: bool = False):
async def disconnect(self, allow_autoreconnect: bool=False):
self.auth_status = AuthStatus.NOT_AUTHENTICATED
await super().disconnect(allow_autoreconnect)

Expand Down Expand Up @@ -148,7 +147,8 @@ async def _game_watcher(ctx: BizHawkClientContext):
script_version = await get_script_version(ctx.bizhawk_ctx)

if script_version != EXPECTED_SCRIPT_VERSION:
logger.info(f"Connector script is incompatible. Expected version {EXPECTED_SCRIPT_VERSION} but got {script_version}. Disconnecting.")
logger.info(f"Connector script is incompatible. Expected version {EXPECTED_SCRIPT_VERSION} but "
f"got {script_version}. Disconnecting.")
disconnect(ctx.bizhawk_ctx)
continue

Expand Down
Loading