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

api: Add a display property to all components #272

Open
wants to merge 1 commit into
base: mainline
Choose a base branch
from
Open
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
79 changes: 79 additions & 0 deletions src/mewbot/api/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import abc
import functools
import inspect

from mewbot.api.registry import ComponentRegistry
from mewbot.core import (
Expand Down Expand Up @@ -52,6 +53,32 @@ class Component(metaclass=ComponentRegistry):

_id: str

def help(self) -> str:
"""
Returns a human-readable help string for this Component.
"""
return inspect.getsource(type(self))

def display_name(self) -> str:
"""
Return a human-readable display name for this Component.
"""
return type(self).__name__

def description(self) -> str:
"""
Return a human-readable description of this Component.
"""
if (cand_str := type(self).__doc__) is not None:
return cand_str
return f"{self.display_name()} has no doc string set."

def status(self) -> str:
"""
Returns a human-readable status string for this Component.
"""
return f"Status for class {self.display_name()} is not defined."

def serialise(self) -> ConfigBlock:
"""
Create a Loader compatible configuration block for this Component.
Expand Down Expand Up @@ -158,6 +185,32 @@ class Input:
def __init__(self) -> None:
self.queue = None

def help(self) -> str:
"""
Returns a human-readable help string for this Input.
"""
return inspect.getsource(type(self))

def display_name(self) -> str:
"""
Return a human-readable display name for this Input.
"""
return type(self).__name__

def description(self) -> str:
"""
Return a human-readable description of this Input.
"""
if (cand_str := type(self).__doc__) is not None:
return cand_str
return f"{self.display_name()} has no doc string set."

def status(self) -> str:
"""
Returns a human-readable status string for this Input.
"""
return f"Status for class {self.display_name()} is not defined."

@staticmethod
@abc.abstractmethod
def produces_inputs() -> set[type[InputEvent]]:
Expand Down Expand Up @@ -191,6 +244,32 @@ class Output:
they can consume it.
"""

def help(self) -> str:
"""
Returns a human-readable help string for this Output.
"""
return inspect.getsource(type(self))

def display_name(self) -> str:
"""
Return a human-readable display name for this Output.
"""
return type(self).__name__

def description(self) -> str:
"""
Return a human-readable description of this Output.
"""
if (cand_str := type(self).__doc__) is not None:
return cand_str
return f"{self.display_name()} has no doc string set."

def status(self) -> str:
"""
Returns a human-readable status string for this Output.
"""
return f"Status for class {self.display_name()} is not defined."

@staticmethod
@abc.abstractmethod
def consumes_outputs() -> set[type[OutputEvent]]:
Expand Down
Loading
Loading