Skip to content

Commit bea8c0f

Browse files
authored
More additional fixes (#584)
1 parent 1832ebf commit bea8c0f

File tree

12 files changed

+107
-69
lines changed

12 files changed

+107
-69
lines changed

changes/584.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
More additional fixes

docker/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ ENV UV_LINK_MODE=copy
99
# Disable Python downloads as the system Python interpreter instead
1010
ENV UV_PYTHON_DOWNLOADS=0
1111

12+
# Disable development dependencies from being installed
13+
ENV UV_NO_DEV=1
14+
1215
# Set Tini version
1316
# Ref: https://github.com/krallin/tini?tab=readme-ov-file#using-tini
1417
ENV TINI_VERSION=v0.19.0
@@ -27,14 +30,14 @@ COPY pyproject.toml uv.lock /app/
2730
RUN --mount=type=cache,target=/root/.cache/uv \
2831
--mount=type=bind,source=uv.lock,target=uv.lock \
2932
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
30-
uv sync --frozen --no-install-project --no-dev
33+
uv sync --frozen --no-install-project
3134

3235
# Add project source code
3336
COPY ./src /app
3437

3538
# Install the rest (this allows for optimal caching)
3639
RUN --mount=type=cache,target=/root/.cache/uv \
37-
uv sync --frozen --no-dev
40+
uv sync --frozen
3841

3942
FROM python:3.13-slim-trixie
4043

docker/docker-compose.dev.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: kumiko_dev
22

33
services:
44
database:
5-
container_name: beaklevision_postgres
5+
container_name: kumiko_postgres
66
image: postgres:17
77
environment:
88
POSTGRES_PASSWORD: ${DB_PASSWORD}
@@ -39,7 +39,7 @@ services:
3939
database:
4040
condition: service_healthy
4141
volumes:
42-
- ../app/schema.sql:/schema.sql
42+
- ../src/schema.sql:/schema.sql
4343

4444
volumes:
4545
database:

docker/docker-compose.prod.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
image: ghcr.io/no767/kumiko:edge
77
volumes:
88
# Do not edit the next line. If you want to change the path of the configuration file, please edit the CONFIG_LOCATION variable
9-
- ${CONFIG_LOCATION}:/app/config.yml:ro
9+
- ${CONFIG_LOCATION}:/app/config.yml
1010
ports:
1111
- 8770:8770
1212
depends_on:
@@ -72,7 +72,7 @@ services:
7272
database:
7373
condition: service_healthy
7474
volumes:
75-
- ../app/schema.sql:/schema.sql
75+
- ../src/schema.sql:/schema.sql
7676

7777
volumes:
7878
database:
@@ -81,4 +81,4 @@ volumes:
8181

8282
networks:
8383
db_bridge:
84-
driver: bridge
84+
driver: bridge

docker/docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
image: ghcr.io/no767/kumiko:edge
77
volumes:
88
# Do not edit the next line. If you want to change the path of the configuration file, please edit the CONFIG_LOCATION variable
9-
- ${CONFIG_LOCATION}:/app/config.yml:ro
9+
- ${CONFIG_LOCATION}:/app/config.yml
1010
ports:
1111
- 8770:8770
1212
depends_on:
@@ -53,11 +53,11 @@ services:
5353
database:
5454
condition: service_healthy
5555
volumes:
56-
- ../app/schema.sql:/schema.sql
56+
- ../src/schema.sql:/schema.sql
5757

5858
volumes:
5959
database:
6060

6161
networks:
6262
db_bridge:
63-
driver: bridge
63+
driver: bridge

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ dependencies = [
1414
"msgspec~=0.19.0",
1515
"prometheus-async~=25.1.0",
1616
"prometheus-client~=0.23.1",
17-
"psutil~=7.1.1",
17+
"psutil~=7.1.2",
1818
"pygit2~=1.19.0",
1919
"python-dateutil~=2.9.0.post0",
2020
"pyyaml~=6.0.3",
2121
"typing-extensions~=4.15.0 ; python_full_version < '3.11'",
2222
"uvloop~=0.22.1 ; sys_platform != 'win32'",
23+
"watchfiles~=1.1.1",
2324
"winloop~=0.3.1 ; sys_platform == 'win32'",
2425
]
2526

@@ -28,11 +29,11 @@ discord-ext-menus = { git = "https://github.com/Rapptz/discord-ext-menus", rev =
2829

2930
[dependency-groups]
3031
dev = [
31-
"watchfiles~=1.1.1",
3232
"towncrier~=25.8.0",
3333
{ include-group = "lint" },
3434
{ include-group = "docs" }
3535
]
36+
3637
lint = [
3738
"pyright[nodejs]~=1.1.407",
3839
"ruff~=0.14.2",

src/cogs/ext/prometheus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _get_stats(self) -> GuildCount:
6161
elif isinstance(channel, discord.VoiceChannel):
6262
voice += 1
6363

64-
return GuildCount(count=guilds, text=text, voice=voice, users=users)
64+
return GuildCount(amount=guilds, text=text, voice=voice, users=users)
6565

6666
def fill(self) -> None:
6767
stats = self._get_stats()

src/utils/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class KeyboardInterruptHandler:
1212
def __init__(self, bot: Kumiko):
1313
self.bot = bot
14-
self._task: Optional[asyncio.Task]
14+
self._task: Optional[asyncio.Task] = None
1515

1616
def __call__(self):
1717
if self._task:

src/utils/help.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
from __future__ import annotations
2+
13
import inspect
24
import itertools
3-
from collections.abc import Mapping
4-
from typing import Any, Optional, Union
5+
from typing import TYPE_CHECKING, Any, Optional, Union
56

67
import discord
78
from discord.ext import commands, menus
89

9-
from core import Kumiko
1010
from utils.embeds import Embed
1111

1212
from .pages import KumikoPages
1313

14+
if TYPE_CHECKING:
15+
from collections.abc import Mapping
16+
17+
from core import Kumiko
1418
# RGB Colors:
1519
# Pink (255, 161, 231) - Used for the main bot page
1620
# Lavender (197, 184, 255) - Used for cog and group pages

src/utils/logger.py

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,65 @@
11
import logging
22
from logging.handlers import RotatingFileHandler
33
from types import TracebackType
4-
from typing import TypeVar
54

6-
import discord
5+
from utils.checks import is_docker
76

8-
BE = TypeVar("BE", bound=BaseException)
7+
MAX_BYTES = 32 * 1024 * 1024 # 32 MiB
98

109

1110
class KumikoLogger:
1211
def __init__(self) -> None:
13-
self.self = self
14-
self.log = logging.getLogger("kumiko")
12+
self._disable_watchfiles_logger()
1513

16-
def __enter__(self) -> None:
17-
max_bytes = 32 * 1024 * 1024 # 32 MiB
18-
self.log.setLevel(logging.INFO)
19-
logging.getLogger("watchfiles").setLevel(logging.ERROR)
20-
logging.getLogger("discord").setLevel(logging.INFO)
21-
handler = RotatingFileHandler(
22-
filename="kumiko.log",
23-
encoding="utf-8",
24-
mode="w",
25-
maxBytes=max_bytes,
26-
backupCount=5,
27-
)
28-
fmt = logging.Formatter(
29-
fmt="%(asctime)s %(levelname)s\t%(message)s",
30-
datefmt="[%Y-%m-%d %H:%M:%S]",
14+
def _get_formatter(self) -> logging.Formatter:
15+
dt_fmt = "%Y-%m-%d %H:%M:%S"
16+
return logging.Formatter(
17+
"[{asctime}] [{levelname}]\t\t{message}", dt_fmt, style="{"
3118
)
32-
handler.setFormatter(fmt)
33-
self.log.addHandler(handler)
34-
discord.utils.setup_logging(formatter=fmt)
19+
20+
def _disable_watchfiles_logger(self) -> None:
21+
watchfiles = logging.getLogger("watchfiles")
22+
23+
watchfiles.propagate = False
24+
watchfiles.addHandler(logging.NullHandler())
25+
26+
def __enter__(self) -> None:
27+
discord_logger = logging.getLogger("discord")
28+
29+
root = logging.getLogger("kumiko")
30+
31+
handler = logging.StreamHandler()
32+
handler.setFormatter(self._get_formatter())
33+
34+
if not is_docker():
35+
file_handler = RotatingFileHandler(
36+
filename="kumiko.log",
37+
encoding="utf-8",
38+
mode="w",
39+
maxBytes=MAX_BYTES,
40+
backupCount=5,
41+
)
42+
file_handler.setFormatter(self._get_formatter())
43+
44+
discord_logger.addHandler(file_handler)
45+
root.addHandler(file_handler)
46+
47+
discord_logger.setLevel(logging.INFO)
48+
discord_logger.addHandler(handler)
49+
50+
root.setLevel(logging.INFO)
51+
root.addHandler(handler)
3552

3653
def __exit__(
3754
self,
3855
exc_type: type[BaseException] | None,
3956
exc: BaseException | None,
4057
traceback: TracebackType | None,
4158
) -> None:
42-
self.log.info("Shutting down...")
43-
handlers = self.log.handlers[:]
59+
root = logging.getLogger("kumiko")
60+
61+
root.info("Shutting down...")
62+
handlers = root.handlers[:]
4463
for hdlr in handlers:
4564
hdlr.close()
46-
self.log.removeHandler(hdlr)
65+
root.removeHandler(hdlr)

0 commit comments

Comments
 (0)