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

Bump to Python 3.12 #183

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-case-conflict
- id: check-merge-conflict
Expand All @@ -12,3 +12,4 @@ repos:
- id: mixed-line-ending
args: [ --fix=lf ]
- id: end-of-file-fixer
exclude: .devcontainer/devcontainer-lock.json
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11-slim@sha256:edaf703dce209d774af3ff768fc92b1e3b60261e7602126276f9ceb0e3a96874
FROM python:3.12-slim@sha256:541d45d3d675fb8197f534525a671e2f8d66c882b89491f9dda271f4f94dcd06

# Define Git SHA build argument for Sentry
ARG git_sha="development"
Expand Down
8 changes: 4 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@
releases_release_uri = f"{REPO_LINK}/releases/tag/v%s"


def linkcode_resolve(domain: str, info: dict) -> str:
def linkcode_resolve(domain: str, info: dict) -> str | None:
"""linkcode_resolve."""
if domain != "py":
return None
if not info["module"]:
return None

import importlib
import inspect
import types
import importlib # noqa: PLC0415
import inspect # noqa: PLC0415
import types # noqa: PLC0415

mod = importlib.import_module(info["module"])

Expand Down
2 changes: 1 addition & 1 deletion make.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function Invoke-Upgrade-Deps
function Invoke-Lint
{
pre-commit run --all-files
python -m ruff --fix .
python -m ruff check --fix .
python -m ruff format .
python -m mypy --strict src/
}
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ docs = { file = ["requirements/requirements-docs.txt"] }
[tool.ruff]
preview = true
unsafe-fixes = true
target-version = "py311"
target-version = "py312"
line-length = 120

[tool.ruff.lint]
select = ["ALL"]
select = [
"ALL",
]
ignore = [
"CPY001", # (Missing copyright notice at top of file)
"ERA001", # (Found commented-out code) - Porting features a piece at a time
Expand Down
16 changes: 8 additions & 8 deletions requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile requirements/requirements-dev.in
#
build==1.0.3
build==1.2.1
# via pip-tools
cfgv==3.4.0
# via pre-commit
click==8.1.7
# via pip-tools
distlib==0.3.8
# via virtualenv
filelock==3.13.1
filelock==3.13.4
# via
# -c requirements/requirements.txt
# virtualenv
identify==2.5.34
identify==2.5.35
# via pre-commit
mypy==1.9.0
# via -r requirements/requirements-dev.in
mypy-extensions==1.0.0
# via mypy
nodeenv==1.8.0
# via pre-commit
packaging==23.2
packaging==24.0
# via build
pip-tools==7.4.1
# via -r requirements/requirements-dev.in
Expand All @@ -40,13 +40,13 @@ pyyaml==6.0.1
# via pre-commit
ruff==0.3.7
# via -r requirements/requirements-dev.in
typing-extensions==4.9.0
typing-extensions==4.11.0
# via
# -c requirements/requirements.txt
# mypy
virtualenv==20.25.0
virtualenv==20.25.1
# via pre-commit
wheel==0.42.0
wheel==0.43.0
# via pip-tools

# The following packages are considered to be unsafe in a requirements file:
Expand Down
8 changes: 4 additions & 4 deletions requirements/requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile requirements/requirements-docs.in
Expand All @@ -8,7 +8,7 @@ alabaster==0.7.16
# via sphinx
anyascii==0.3.2
# via sphinx-autoapi
astroid==3.0.3
astroid==3.1.0
# via sphinx-autoapi
babel==2.14.0
# via sphinx
Expand All @@ -26,7 +26,7 @@ docutils==0.20.1
# via sphinx
furo==2024.1.29
# via -r requirements/requirements-docs.in
idna==3.6
idna==3.7
# via
# -c requirements/requirements.txt
# requests
Expand All @@ -38,7 +38,7 @@ jinja2==3.1.3
# sphinx-autoapi
markupsafe==2.1.5
# via jinja2
packaging==23.2
packaging==24.0
# via sphinx
pygments==2.17.2
# via
Expand Down
4 changes: 2 additions & 2 deletions requirements/requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile requirements/requirements-tests.in
#
iniconfig==2.0.0
# via pytest
packaging==23.2
packaging==24.0
# via pytest
pluggy==1.4.0
# via pytest
Expand Down
8 changes: 0 additions & 8 deletions requirements/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ sentry-sdk
rapidfuzz
coloredlogs

# Database
psycopg[binary]
SQLAlchemy

# Utilities
# utils/helpers
tldextract
Expand All @@ -26,7 +22,3 @@ tldextract
arrow
# exts/utilities/snekbox
regex
# exts/fun/typeracer
wonderwords
# exts/fun/uwu
imsosorry
34 changes: 10 additions & 24 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile requirements/requirements.in
#
aiodns==3.1.1
aiodns==3.2.0
# via pydis-core
aiohttp==3.9.4
# via
Expand Down Expand Up @@ -32,46 +32,38 @@ discord-py==2.3.2
# via
# -r requirements/requirements.in
# pydis-core
filelock==3.13.1
filelock==3.13.4
# via tldextract
frozenlist==1.4.1
# via
# aiohttp
# aiosignal
greenlet==3.0.3
# via sqlalchemy
humanfriendly==10.0
# via coloredlogs
idna==3.6
idna==3.7
# via
# requests
# tldextract
# yarl
imsosorry==1.2.1
# via -r requirements/requirements.in
multidict==6.0.5
# via
# aiohttp
# yarl
psycopg[binary]==3.1.18
# via -r requirements/requirements.in
psycopg-binary==3.1.18
# via psycopg
pycares==4.4.0
# via aiodns
pycparser==2.21
pycparser==2.22
# via cffi
pydantic==2.6.1
pydantic==2.7.0
# via
# pydantic-settings
# pydis-core
pydantic-core==2.16.2
pydantic-core==2.18.1
# via pydantic
pydantic-settings==2.2.1
# via -r requirements/requirements.in
pydis-core==11.1.0
# via -r requirements/requirements.in
python-dateutil==2.8.2
python-dateutil==2.9.0.post0
# via arrow
python-dotenv==1.0.1
# via pydantic-settings
Expand All @@ -89,25 +81,19 @@ sentry-sdk==1.45.0
# via -r requirements/requirements.in
six==1.16.0
# via python-dateutil
sqlalchemy==2.0.29
# via -r requirements/requirements.in
statsd==4.0.1
# via pydis-core
tldextract==5.1.2
# via -r requirements/requirements.in
types-python-dateutil==2.8.19.20240106
types-python-dateutil==2.9.0.20240316
# via arrow
typing-extensions==4.9.0
typing-extensions==4.11.0
# via
# psycopg
# pydantic
# pydantic-core
# sqlalchemy
urllib3==2.2.1
# via
# requests
# sentry-sdk
wonderwords==2.2.0
# via -r requirements/requirements.in
yarl==1.9.4
# via aiohttp
20 changes: 3 additions & 17 deletions src/bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
"""Anubis, a fancy Discord bot."""

import logging

import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration
from pydis_core.utils import apply_monkey_patches

from bot import log
from bot.constants import GIT_SHA, Sentry

sentry_logging = LoggingIntegration(level=logging.DEBUG, event_level=logging.WARNING)

sentry_sdk.init(
dsn=Sentry.dsn,
integrations=[
sentry_logging,
],
release=f"{Sentry.release_prefix}@{GIT_SHA}",
traces_sample_rate=0.5,
profiles_sample_rate=0.5,
)

log.setup()

apply_monkey_patches()
14 changes: 9 additions & 5 deletions src/bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@

from bot import constants
from bot.bot import Bot

intents = discord.Intents.default()
intents.message_content = True
from bot.log import setup_sentry


async def main() -> None:
"""Run the bot."""
setup_sentry()

allowed_roles = list({discord.Object(id_) for id_ in constants.MODERATION_ROLES})
intents = discord.Intents.default()
intents.message_content = True

bot = Bot(
guild_id=constants.Guild.id,
http_session=aiohttp.ClientSession(),
allowed_roles=list({discord.Object(id_) for id_ in constants.MODERATION_ROLES}),
command_prefix=commands.when_mentioned,
allowed_roles=allowed_roles,
command_prefix=commands.when_mentioned_or(constants.Bot.prefix),
intents=intents,
)

Expand Down
7 changes: 6 additions & 1 deletion src/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Self

from pydis_core import BotBase
from sentry_sdk import push_scope
from sentry_sdk import push_scope, start_transaction

from bot import exts
from bot.log import get_logger
Expand All @@ -25,13 +25,18 @@
def __init__(self: Self, *args: list, **kwargs: dict) -> None:
super().__init__(*args, **kwargs)

async def load_extension(self, name: str, *args: list, **kwargs: dict) -> None:
"""Extend D.py's load_extension function to also record sentry performance stats."""
with start_transaction(op="cog-load", name=name):
await super().load_extension(name, *args, **kwargs)

async def setup_hook(self: Self) -> None:
"""Default async initialisation method for discord.py.""" # noqa: D401
await super().setup_hook()

await self.load_extensions(exts)

async def on_error(self: Self, event: str, *args: list, **kwargs: dict) -> None:

Check failure on line 39 in src/bot/bot.py

View workflow job for this annotation

GitHub Actions / lint / lint

Ruff (PLR6301)

src/bot/bot.py:39:15: PLR6301 Method `on_error` could be a function, class method, or static method
"""Log errors raised in event listeners rather than printing them to stderr."""
with push_scope() as scope:
scope.set_tag("event", event)
Expand Down
Loading
Loading