diff options
| -rw-r--r-- | arthur/apis/cloudflare/__init__.py | 0 | ||||
| -rw-r--r-- | arthur/apis/kubernetes/__init__.py | 0 | ||||
| -rw-r--r-- | arthur/apis/kubernetes/certificates.py | 4 | ||||
| -rw-r--r-- | arthur/apis/kubernetes/deployments.py | 8 | ||||
| -rw-r--r-- | arthur/apis/kubernetes/jobs.py | 12 | ||||
| -rw-r--r-- | arthur/apis/kubernetes/nodes.py | 14 | ||||
| -rw-r--r-- | arthur/bot.py | 7 | ||||
| -rw-r--r-- | arthur/exts/fun/devops_rules.py | 2 | ||||
| -rw-r--r-- | arthur/exts/kubernetes/certificates.py | 10 | ||||
| -rw-r--r-- | arthur/exts/kubernetes/deployments.py | 3 | ||||
| -rw-r--r-- | arthur/exts/kubernetes/jobs.py | 2 | ||||
| -rw-r--r-- | arthur/exts/kubernetes/nodes.py | 2 | ||||
| -rw-r--r-- | arthur/utils.py | 4 | ||||
| -rw-r--r-- | pyproject.toml | 9 | 
14 files changed, 39 insertions, 38 deletions
| diff --git a/arthur/apis/cloudflare/__init__.py b/arthur/apis/cloudflare/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/arthur/apis/cloudflare/__init__.py diff --git a/arthur/apis/kubernetes/__init__.py b/arthur/apis/kubernetes/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/arthur/apis/kubernetes/__init__.py diff --git a/arthur/apis/kubernetes/certificates.py b/arthur/apis/kubernetes/certificates.py index 86ad983..ab71443 100644 --- a/arthur/apis/kubernetes/certificates.py +++ b/arthur/apis/kubernetes/certificates.py @@ -8,8 +8,8 @@ from kubernetes_asyncio.client.api_client import ApiClient  async def list_certificates(namespace: str) -> dict[str, Any]:      """List certificate objects created through cert-manager.""" -    async with ApiClient() as api: -        api = client.CustomObjectsApi(api) +    async with ApiClient() as api_client: +        api = client.CustomObjectsApi(api_client)          return await api.list_namespaced_custom_object(              "cert-manager.io", "v1", namespace, "certificates"          ) diff --git a/arthur/apis/kubernetes/deployments.py b/arthur/apis/kubernetes/deployments.py index 305f4cf..b3aee83 100644 --- a/arthur/apis/kubernetes/deployments.py +++ b/arthur/apis/kubernetes/deployments.py @@ -9,8 +9,8 @@ from kubernetes_asyncio.client.models import V1DeploymentList  async def restart_deployment(deployment: str, namespace: str) -> None:      """Patch a deployment with a custom annotation to trigger redeployment.""" -    async with ApiClient() as api: -        api = client.AppsV1Api(api) +    async with ApiClient() as api_client: +        api = client.AppsV1Api(api_client)          await api.patch_namespaced_deployment(              name=deployment,              namespace=namespace, @@ -31,6 +31,6 @@ async def restart_deployment(deployment: str, namespace: str) -> None:  async def list_deployments(namespace: str) -> V1DeploymentList:      """Query the Kubernetes API for a list of deployments in the provided namespace.""" -    async with ApiClient() as api: -        api = client.AppsV1Api(api) +    async with ApiClient() as api_client: +        api = client.AppsV1Api(api_client)          return await api.list_namespaced_deployment(namespace=namespace) diff --git a/arthur/apis/kubernetes/jobs.py b/arthur/apis/kubernetes/jobs.py index 2813122..0269561 100644 --- a/arthur/apis/kubernetes/jobs.py +++ b/arthur/apis/kubernetes/jobs.py @@ -9,8 +9,8 @@ from kubernetes_asyncio.client.models import V1CronJob, V1CronJobList, V1Job  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) +    async with ApiClient() as api_client: +        api = client.BatchV1Api(api_client)          if namespace:              return await api.list_namespaced_cron_job(namespace)          return await api.list_cron_job_for_all_namespaces() @@ -18,15 +18,15 @@ async def list_cronjobs(namespace: str | None = None) -> V1CronJobList:  async def get_cronjob(namespace: str, cronjob_name: str) -> V1CronJob:      """Fetch a cronjob given the name and namespace.""" -    async with ApiClient() as api: -        api = client.BatchV1Api(api) +    async with ApiClient() as api_client: +        api = client.BatchV1Api(api_client)          return await api.read_namespaced_cron_job(cronjob_name, namespace)  async def create_job(namespace: str, job_name: str, cron_spec: dict[str, Any]) -> V1Job:      """Create a job in the specified namespace with the given specification and name.""" -    async with ApiClient() as api: -        api = client.BatchV1Api(api) +    async with ApiClient() as api_client: +        api = client.BatchV1Api(api_client)          return await api.create_namespaced_job(              namespace, V1Job(metadata={"name": job_name}, spec=cron_spec)          ) diff --git a/arthur/apis/kubernetes/nodes.py b/arthur/apis/kubernetes/nodes.py index ed45c26..3221a15 100644 --- a/arthur/apis/kubernetes/nodes.py +++ b/arthur/apis/kubernetes/nodes.py @@ -7,14 +7,14 @@ from kubernetes_asyncio.client.models import V1NodeList  async def list_nodes() -> V1NodeList:      """List Kubernetes nodes.""" -    async with ApiClient() as api: -        api = client.CoreV1Api(api) +    async with ApiClient() as api_client: +        api = client.CoreV1Api(api_client)          return await api.list_node() -async def _change_cordon(node: str, cordon: bool) -> None: -    async with ApiClient() as api: -        api = client.CoreV1Api(api) +async def _change_cordon(node: str, *, cordon: bool) -> None: +    async with ApiClient() as api_client: +        api = client.CoreV1Api(api_client)          await api.patch_node(              node,              body={"spec": {"unschedulable": cordon}}, @@ -23,9 +23,9 @@ async def _change_cordon(node: str, cordon: bool) -> None:  async def cordon_node(node: str) -> None:      """Cordon a Kubernetes node.""" -    await _change_cordon(node, True) +    await _change_cordon(node, cordon=True)  async def uncordon_node(node: str) -> None:      """Uncordon a Kubernetes node.""" -    await _change_cordon(node, False) +    await _change_cordon(node, cordon=False) diff --git a/arthur/bot.py b/arthur/bot.py index 4d56df2..8db850d 100644 --- a/arthur/bot.py +++ b/arthur/bot.py @@ -49,10 +49,9 @@ class KingArthur(BotBase):          await self.load_extensions(exts, sync_app_commands=False) -        # jishaku doesn't support 3.11 yet. -        # logger.info("Loading <red>jishaku</red>") -        # await self.load_extension("jishaku") -        # logger.info("Loaded <red>jishaku</red>") +        logger.info("Loading <red>jishaku</red>") +        await self.load_extension("jishaku") +        logger.info("Loaded <red>jishaku</red>")      async def is_owner(self, user: User | Member) -> bool:          """Check if the invoker is a bot owner.""" diff --git a/arthur/exts/fun/devops_rules.py b/arthur/exts/fun/devops_rules.py index fa0e1c4..0e311cb 100644 --- a/arthur/exts/fun/devops_rules.py +++ b/arthur/exts/fun/devops_rules.py @@ -52,7 +52,7 @@ class Rules(Cog):          )      @rules_group.command(name="refresh", aliases=("fetch", "update")) -    async def update_rules(self, ctx: Context) -> None: +    async def update_rules(self, _: Context) -> None:          """Re-fetch the list of rules from notion."""          await self.cog_load() diff --git a/arthur/exts/kubernetes/certificates.py b/arthur/exts/kubernetes/certificates.py index 69c1c32..a2383da 100644 --- a/arthur/exts/kubernetes/certificates.py +++ b/arthur/exts/kubernetes/certificates.py @@ -25,15 +25,15 @@ class Certificates(commands.Cog):          """List TLS certificates in the selected namespace (defaults to default)."""          certs = await certificates.list_certificates(namespace) -        table_data = [] - -        for certificate in certs["items"]: -            table_data.append([ +        table_data = [ +            [                  certificate["metadata"]["name"],                  ", ".join(certificate["spec"]["dnsNames"]),                  certificate["spec"]["issuerRef"]["name"],                  certificate["status"]["conditions"][0]["message"], -            ]) +            ] +            for certificate in certs["items"] +        ]          table = tabulate(              table_data, headers=["Name", "DNS Names", "Issuer", "Status"], tablefmt="psql" diff --git a/arthur/exts/kubernetes/deployments.py b/arthur/exts/kubernetes/deployments.py index bfa982a..66f9a1e 100644 --- a/arthur/exts/kubernetes/deployments.py +++ b/arthur/exts/kubernetes/deployments.py @@ -1,5 +1,6 @@  """The Deployments cog helps with managing Kubernetes deployments.""" +from http import HTTPStatus  from textwrap import dedent  from discord import ButtonStyle, Interaction, ui @@ -42,7 +43,7 @@ class ConfirmDeployment(ui.View):          try:              await deployments.restart_deployment(self.deployment, self.namespace)          except ApiException as e: -            if e.status == 404: +            if e.status == HTTPStatus.NOT_FOUND:                  return await interaction.message.edit(                      content=generate_error_message(                          description="Could not find deployment, check the namespace.", diff --git a/arthur/exts/kubernetes/jobs.py b/arthur/exts/kubernetes/jobs.py index de7a9fd..4abff9e 100644 --- a/arthur/exts/kubernetes/jobs.py +++ b/arthur/exts/kubernetes/jobs.py @@ -8,8 +8,6 @@ from arthur.apis.kubernetes import jobs  from arthur.bot import KingArthur  from arthur.config import CONFIG -# from arthur.utils import generate_error_message -  class CronJobView(discord.ui.View):      """This view allows users to select and trigger a CronJob.""" diff --git a/arthur/exts/kubernetes/nodes.py b/arthur/exts/kubernetes/nodes.py index 4c63076..1a617e7 100644 --- a/arthur/exts/kubernetes/nodes.py +++ b/arthur/exts/kubernetes/nodes.py @@ -46,7 +46,7 @@ class Nodes(commands.Cog):              if node.spec.taints:                  for taint in node.spec.taints: -                    statuses.append(taint.effect) +                    statuses.append(taint.effect)  # noqa: PERF401              node_creation = node.metadata.creation_timestamp diff --git a/arthur/utils.py b/arthur/utils.py index 07e0f19..f66ecd4 100644 --- a/arthur/utils.py +++ b/arthur/utils.py @@ -13,6 +13,6 @@ def generate_error_message(      return f"{emote} **{title}** {description}" -def datetime_to_discord(time: datetime, format: str = "f") -> str: +def datetime_to_discord(time: datetime, date_format: str = "f") -> str:      """Convert a datetime object to a Discord timestamp.""" -    return f"<t:{int(time.timestamp())}:{format}>" +    return f"<t:{int(time.timestamp())}:{date_format}>" diff --git a/pyproject.toml b/pyproject.toml index 269da86..10429f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,21 +40,24 @@ unsafe-fixes = true  preview = true  [tool.ruff.lint] -select = ["ANN", "B", "C4", "D", "DTZ", "E", "F", "I", "ISC", "INT", "N", "PGH", "PIE", "Q", "RET", "RSE", "RUF", "S", "SIM", "T20", "TID", "UP", "W"] +select = ["ALL"]  ignore = [      "ANN002", "ANN003", "ANN101", "ANN102", "ANN204", "ANN206", "ANN401",      "B904",      "C401", "C408", +    "CPY001",      "D100", "D104", "D105", "D107", "D203", "D212", "D214", "D215", "D301",      "D400", "D401", "D402", "D404", "D405", "D406", "D407", "D408", "D409", "D410", "D411", "D412", "D413", "D414", "D416", "D417",      "E731",      "RET504",      "RUF005",      "S311", -    "SIM102","SIM108", +    "SIM102", "SIM108", +    "PD", +    "PLR6301",      # Rules suggested to be ignored when using ruff format -    "D206", "E111", "E114", "E117", "E501", "ISC001", "Q000", "Q001", "Q002", "Q003", "W191", +    "COM812", "D206", "E111", "E114", "E117", "E501", "ISC001", "Q000", "Q001", "Q002", "Q003", "W191",  ]  [tool.ruff.lint.isort] | 
