diff options
| author | 2023-04-27 22:28:08 +0100 | |
|---|---|---|
| committer | 2023-04-27 22:28:08 +0100 | |
| commit | fffe818885154fcc54b399f13155ee95a1a408bc (patch) | |
| tree | 86ead71bb3b5d57f886b77a45455d43bfa2cd5ec /arthur | |
| parent | build(deps): bump pydantic from 1.10.5 to 1.10.7 (#50) (diff) | |
| parent | Fix linting errors from new ruff rules (diff) | |
Merge pull request #54 from python-discord/migrate-to-ruff
Migrate to ruff
Diffstat (limited to 'arthur')
| -rw-r--r-- | arthur/apis/cloudflare/zones.py | 3 | ||||
| -rw-r--r-- | arthur/apis/kubernetes/deployments.py | 6 | ||||
| -rw-r--r-- | arthur/apis/kubernetes/jobs.py | 7 | ||||
| -rw-r--r-- | arthur/bot.py | 9 | ||||
| -rw-r--r-- | arthur/config.py | 3 | ||||
| -rw-r--r-- | arthur/exts/error_handler/error_handler.py | 22 | ||||
| -rw-r--r-- | arthur/exts/kubernetes/deployments.py | 7 | 
7 files changed, 25 insertions, 32 deletions
| diff --git a/arthur/apis/cloudflare/zones.py b/arthur/apis/cloudflare/zones.py index 7d407a0..1139d25 100644 --- a/arthur/apis/cloudflare/zones.py +++ b/arthur/apis/cloudflare/zones.py @@ -1,5 +1,4 @@  """APIs for managing Cloudflare zones.""" -from typing import Optional  import aiohttp @@ -10,7 +9,7 @@ AUTH_HEADER = {"Authorization": f"Bearer {CONFIG.cloudflare_token}"}  async def list_zones(      session: aiohttp.ClientSession, -    zone_name: Optional[str] = None, +    zone_name: str | None = None,  ) -> dict[str, str]:      """List all Cloudflare zones."""      endpoint = "https://api.cloudflare.com/client/v4/zones" diff --git a/arthur/apis/kubernetes/deployments.py b/arthur/apis/kubernetes/deployments.py index f7b4d5c..971c4a0 100644 --- a/arthur/apis/kubernetes/deployments.py +++ b/arthur/apis/kubernetes/deployments.py @@ -1,5 +1,5 @@  """APIs for working with Kubernetes deployments.""" -from datetime import datetime, timezone +from datetime import UTC, datetime  from kubernetes_asyncio import client  from kubernetes_asyncio.client.api_client import ApiClient @@ -18,9 +18,7 @@ async def restart_deployment(deployment: str, namespace: str) -> None:                      "template": {                          "metadata": {                              "annotations": { -                                "king-arthur.pydis.com/restartedAt": datetime.now( -                                    timezone.utc -                                ).isoformat() +                                "king-arthur.pydis.com/restartedAt": datetime.now(UTC).isoformat()                              }                          }                      } diff --git a/arthur/apis/kubernetes/jobs.py b/arthur/apis/kubernetes/jobs.py index a5edc53..606177c 100644 --- a/arthur/apis/kubernetes/jobs.py +++ b/arthur/apis/kubernetes/jobs.py @@ -1,19 +1,18 @@  """APIs for interacting with Kubernetes Jobs & Cronjobs.""" -from typing import Any, Optional +from typing import Any  from kubernetes_asyncio import client  from kubernetes_asyncio.client.api_client import ApiClient  from kubernetes_asyncio.client.models import V1CronJob, V1CronJobList, V1Job -async def list_cronjobs(namespace: Optional[str] = None) -> V1CronJobList: +async def list_cronjobs(namespace: str | None = None) -> V1CronJobList:      """Query the Kubernetes API for a list of cronjobss in the provided namespace."""      async with ApiClient() as api:          api = client.BatchV1Api(api)          if namespace:              return await api.list_namespaced_cron_job(namespace) -        else: -            return await api.list_cron_job_for_all_namespaces() +        return await api.list_cron_job_for_all_namespaces()  async def get_cronjob(namespace: str, cronjob_name: str) -> V1CronJob: diff --git a/arthur/bot.py b/arthur/bot.py index 33aecf5..fc97846 100644 --- a/arthur/bot.py +++ b/arthur/bot.py @@ -1,6 +1,6 @@  """Module containing the core bot base for King Arthur."""  from pathlib import Path -from typing import Any, Union +from typing import Any  from discord import Interaction, Member, User  from discord.ext import commands @@ -20,13 +20,12 @@ class KingArthur(BotBase):          self.add_check(self._is_devops)      @staticmethod -    def _is_devops(ctx: Union[commands.Context, Interaction]) -> bool: +    def _is_devops(ctx: commands.Context | Interaction) -> bool:          """Check all commands are executed by authorised personnel."""          if isinstance(ctx, Interaction):              if isinstance(ctx.user, Member):                  return CONFIG.devops_role in [r.id for r in ctx.user.roles] -            else: -                return False +            return False          if ctx.command.name == "ed":              return True @@ -53,7 +52,7 @@ class KingArthur(BotBase):          await self.load_extension("jishaku")          logger.info("Loaded <red>jishaku</red>") -    async def is_owner(self, user: Union[User, Member]) -> bool: +    async def is_owner(self, user: User | Member) -> bool:          """Check if the invoker is a bot owner."""          if not user.guild:              return False diff --git a/arthur/config.py b/arthur/config.py index d754696..13ad241 100644 --- a/arthur/config.py +++ b/arthur/config.py @@ -1,5 +1,4 @@  """Utilities for interacting with the config for King Arthur.""" -from typing import Optional  from pydantic import BaseSettings @@ -23,7 +22,7 @@ class Config(BaseSettings):      guild_id: int = 267624335836053506      # Token for authorising with the Notion API -    notion_api_token: Optional[str] = None +    notion_api_token: str | None = None      class Config:  # noqa: D106          env_file = ".env" diff --git a/arthur/exts/error_handler/error_handler.py b/arthur/exts/error_handler/error_handler.py index 14a8ed2..5273b8a 100644 --- a/arthur/exts/error_handler/error_handler.py +++ b/arthur/exts/error_handler/error_handler.py @@ -21,19 +21,17 @@ class ErrorHandler(Cog):          """Handle exceptions raised during command processing."""          if isinstance(error, commands.CommandNotFound):              return -        if isinstance(error, commands.MissingRequiredArgument): +        if isinstance(error, commands.MissingRequiredArgument | commands.BadArgument):              await self._add_error_reaction(ctx.message)              await ctx.send_help(ctx.command) -        elif isinstance(error, commands.BadArgument): -            await self._add_error_reaction(ctx.message) -            await ctx.send_help(ctx.command) -        elif isinstance(error, commands.CheckFailure): -            await self._add_error_reaction(ctx.message) -        elif isinstance(error, commands.NoPrivateMessage): -            await self._add_error_reaction(ctx.message) -        elif isinstance(error, commands.CommandOnCooldown): -            await self._add_error_reaction(ctx.message) -        elif isinstance(error, commands.DisabledCommand): +        elif isinstance( +            error, +            commands.CheckFailure +            | commands.NoPrivateMessage +            | commands.CommandOnCooldown +            | commands.DisabledCommand +            | commands.DisabledCommand, +        ):              await self._add_error_reaction(ctx.message)          elif isinstance(error, commands.CommandInvokeError):              await self._add_error_reaction(ctx.message) @@ -49,7 +47,7 @@ class ErrorHandler(Cog):              await ctx.send(                  generate_error_message(                      description=( -                        f"Unknown exception occurred: `{error.__class__.__name__}:" f" {error}`" +                        f"Unknown exception occurred: `{error.__class__.__name__}: {error}`"                      )                  )              ) diff --git a/arthur/exts/kubernetes/deployments.py b/arthur/exts/kubernetes/deployments.py index 7a69baf..46e09a3 100644 --- a/arthur/exts/kubernetes/deployments.py +++ b/arthur/exts/kubernetes/deployments.py @@ -64,6 +64,7 @@ class ConfirmDeployment(ui.View):              await interaction.message.edit(content=description, view=None)          self.stop() +        return None      @ui.button(label="Cancel", style=ButtonStyle.grey, row=0)      async def cancel(self, interaction: Interaction, _button: ui.Button) -> None: @@ -79,10 +80,9 @@ def deployment_to_emote(deployment: V1Deployment) -> str:      """Convert a deployment to an emote based on it's replica status."""      if deployment.status.available_replicas == deployment.spec.replicas:          return "\N{LARGE GREEN CIRCLE}" -    elif deployment.status.available_replicas == 0 or not deployment.status.available_replicas: +    if deployment.status.available_replicas == 0 or not deployment.status.available_replicas:          return "\N{LARGE RED CIRCLE}" -    else: -        return "\N{LARGE YELLOW CIRCLE}" +    return "\N{LARGE YELLOW CIRCLE}"  class Deployments(commands.Cog): @@ -146,6 +146,7 @@ class Deployments(commands.Cog):          )          await ctx.send(return_message.format(namespace, table)) +        return None      @deployments.command(name="restart", aliases=["redeploy"])      async def deployments_restart( | 
