fix(lint): Fix linting issues (#487)
Some checks failed
Security / sonarqube (push) Failing after 36s
Security / snyk (push) Successful in 1m1s

This pull request focuses on improving the documentation and readability of the Webex meme bot application by adding docstrings and minor formatting adjustments. Here's a breakdown of the changes:

*   **Docstrings:**
    *   Added module-level docstrings to `app/close.py`, `app/img.py`, and `app/main.py` providing a high-level overview of the purpose of each module.
    *   Added docstrings to classes (`ExitCommand`, `MakeMemeCommand`, `MakeMemeCallback`) describing their role.
    *   Added docstrings to methods within those classes (`__init__`, `pre_execute`, `execute`, `post_execute`) explaining their functionality, arguments, and return values where applicable. The `get_templates` and `format_meme_string` functions in `app/img.py` have been documented as well.
*   **Formatting:**
    *   Added a line break before the return type annotation in function definitions (e.g., `def execute(...) -> Response:`).
    *   Added the disable comment `# pylint: disable=line-too-long` to a line in `app/meme.py` to disable pylint for that line.
    *   Added the disable comment `# pylint: disable=unused-argument` to the `pre_execute`, `execute`, and `post_execute` methods to disable pylint checks about unused arguments. This is because these methods are part of an interface and must have the same signature even if some arguments are unused.
*   **Variable Naming:**
    *   Renamed the `vars` dictionary to `env_vars` in `tests/test_config.py` for better clarity.
*   **Test Update:**
    *   Added a docstring to the `test_config` function in `tests/test_config.py` to explain its functionality.
*   **Imports Update:**
    *   Updated imports in `tests/test_config.py` to disable pylint for wrong-import-position errors using `# pylint: disable=wrong-import-position`.

In essence, these changes enhance the maintainability and understandability of the codebase through comprehensive documentation and minor code style improvements.

Reviewed-on: #487
This commit is contained in:
2025-06-06 19:39:11 +02:00
parent 590e0941bf
commit 13097b36fb
8 changed files with 76 additions and 32 deletions

View File

@ -1,3 +1,5 @@
"""Generates meme images using the memegen.link API."""
from webex_bot.models.command import Command
from webex_bot.models.response import Response, response_from_adaptive_card
from webexteamssdk.models.cards import (
@ -22,6 +24,7 @@ class MakeMemeCommand(Command):
"""Class for initial Webex interactive card."""
def __init__(self) -> None:
"""Initialize the MakeMemeCommand with command keyword and help message."""
super().__init__(
command_keyword="/meme",
help_message="Make a Meme",
@ -29,10 +32,12 @@ class MakeMemeCommand(Command):
delete_previous_message=True,
)
def pre_execute(self, message, attachment_actions, activity) -> None:
def pre_execute(self, message, attachment_actions, activity) -> None: # pylint: disable=unused-argument
"""Pre-execution logic for the MakeMemeCommand."""
return
def execute(self, message, attachment_actions, activity) -> Response:
def execute(self, message, attachment_actions, activity) -> Response: # pylint: disable=unused-argument
"""Execute the MakeMemeCommand and return an adaptive card."""
card_body: list = [
ColumnSet(
columns=[
@ -45,13 +50,13 @@ class MakeMemeCommand(Command):
size=FontSize.MEDIUM,
),
TextBlock(
"This bot uses memegen.link to generate memes. Click 'View Templates' to view available templates.",
"This bot uses memegen.link to generate memes. Click 'View Templates' to view available templates.", # pylint: disable=line-too-long
weight=FontWeight.LIGHTER,
size=FontSize.SMALL,
wrap=True,
),
TextBlock(
"Both fields are required. If you do not want to specify a value, please type a space.",
"Both fields are required. If you do not want to specify a value, please type a space.", # pylint: disable=line-too-long
weight=FontWeight.LIGHTER,
size=FontSize.SMALL,
wrap=True,
@ -68,10 +73,7 @@ class MakeMemeCommand(Command):
Choices(
id="meme_type",
isMultiSelect=False,
choices=[
Choice(title=x["name"], value=x["choiceval"])
for x in TEMPLATES
],
choices=[Choice(title=x["name"], value=x["choiceval"]) for x in TEMPLATES],
),
Text(id="text_top", placeholder="Top Text", maxLength=100),
Text(
@ -103,6 +105,7 @@ class MakeMemeCallback(Command):
"""Class to process user data and return meme."""
def __init__(self) -> None:
"""Initialize the MakeMemeCallback with command keyword and help message."""
super().__init__(
card_callback_keyword="make_meme_callback_rbamzfyx",
delete_previous_message=True,
@ -113,7 +116,8 @@ class MakeMemeCallback(Command):
self.meme: str = ""
self.meme_filename: str = ""
def pre_execute(self, message, attachment_actions, activity) -> str:
def pre_execute(self, message, attachment_actions, activity) -> str: # pylint: disable=unused-argument
"""Pre-execution logic for the MakeMemeCallback."""
self.meme: str = attachment_actions.inputs.get("meme_type")
self.text_top: str = attachment_actions.inputs.get("text_top")
self.text_bottom: str = attachment_actions.inputs.get("text_bottom")
@ -127,13 +131,12 @@ class MakeMemeCallback(Command):
return "Generating your meme..."
def execute(self, message, attachment_actions, activity) -> Response | None:
def execute(self, message, attachment_actions, activity) -> Response | None: # pylint: disable=unused-argument
"""Execute the MakeMemeCallback and return a response with the meme image."""
if self.error:
return None
self.meme_filename: str = img.generate_api_url(
self.meme, self.text_top, self.text_bottom
)
self.meme_filename: str = img.generate_api_url(self.meme, self.text_top, self.text_bottom)
msg: Response = Response(
attributes={
"roomId": activity["target"]["globalId"],
@ -143,5 +146,6 @@ class MakeMemeCallback(Command):
)
return msg
def post_execute(self, message, attachment_actions, activity) -> None:
def post_execute(self, message, attachment_actions, activity) -> None: # pylint: disable=unused-argument
"""Post-execution logic for the MakeMemeCallback."""
return