Skip to content

Commit

Permalink
Merge pull request #72 from python-discord/jb3/3.11-upgrade
Browse files Browse the repository at this point in the history
Python 3.11 upgrade & dep version bumps
  • Loading branch information
jb3 committed Sep 4, 2023
2 parents c780e6f + 1369c6d commit 20cfe8a
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 159 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Install Python Dependencies
uses: HassanAbouelela/actions/setup-python@setup-python_v1.4.1
with:
python_version: '3.10'
python_version: '3.11'

- name: Lint code with ruff
run: ruff check --format=github .
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/amd64 ghcr.io/owl-corp/python-poetry-base:3.10-slim
FROM --platform=linux/amd64 ghcr.io/owl-corp/python-poetry-base:3.11-slim

ENV PYTHONHASHSEED=random

Expand Down
6 changes: 3 additions & 3 deletions metricity/database.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""General utility functions and classes for Metricity."""

import logging
from datetime import datetime, timezone
from datetime import UTC, datetime

import gino
from sqlalchemy.engine import Dialect
Expand Down Expand Up @@ -50,11 +50,11 @@ def process_bind_param(self, value: datetime, _dialect: Dialect) -> datetime:
if value is not None:
if not value.tzinfo:
raise TypeError("tzinfo is required")
value = value.astimezone(timezone.utc).replace(tzinfo=None)
value = value.astimezone(UTC).replace(tzinfo=None)
return value

def process_result_value(self, value: datetime, _dialect: Dialect) -> datetime:
"""Convert the value to aware before passing back to user-land."""
if value is not None:
value = value.replace(tzinfo=timezone.utc)
value = value.replace(tzinfo=UTC)
return value
4 changes: 2 additions & 2 deletions metricity/exts/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, bot: commands.Bot) -> None:
@commands.Cog.listener()
async def on_socket_event_type(self, _: str) -> None:
"""Store the last event received as an int."""
self.last_event_received = int(datetime.datetime.now(datetime.timezone.utc).timestamp())
self.last_event_received = int(datetime.datetime.now(datetime.UTC).timestamp())

@commands.command()
@commands.has_any_role(BotConfig.staff_role_id)
Expand All @@ -34,7 +34,7 @@ async def status(self, ctx: commands.Context) -> None:
if ctx.guild.id != BotConfig.guild_id:
return

bot_ping = (datetime.datetime.now(datetime.timezone.utc) - ctx.message.created_at).total_seconds() * 1000
bot_ping = (datetime.datetime.now(datetime.UTC) - ctx.message.created_at).total_seconds() * 1000
if bot_ping <= 0:
bot_ping = "Your clock is out of sync, could not calculate ping."
else:
Expand Down
6 changes: 3 additions & 3 deletions metricity/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Database models used by Metricity for statistic collection."""

from datetime import datetime, timezone
from datetime import UTC, datetime
from typing import Any

from sqlalchemy.dialects.postgresql import insert
Expand Down Expand Up @@ -43,7 +43,7 @@ class Thread(db.Model):
db.ForeignKey("channels.id", ondelete="CASCADE"),
nullable=False,
)
created_at = db.Column(TZDateTime(), default=datetime.now(timezone.utc))
created_at = db.Column(TZDateTime(), default=datetime.now(UTC))
name = db.Column(db.String, nullable=False)
archived = db.Column(db.Boolean, default=False, nullable=False)
auto_archive_duration = db.Column(db.Integer, nullable=False)
Expand Down Expand Up @@ -112,5 +112,5 @@ class Message(db.Model):
db.ForeignKey("users.id", ondelete="CASCADE"),
index=True,
)
created_at = db.Column(TZDateTime(), default=datetime.now(timezone.utc))
created_at = db.Column(TZDateTime(), default=datetime.now(UTC))
is_deleted = db.Column(db.Boolean, default=False)
300 changes: 155 additions & 145 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Joe Banks <[email protected]>"]
license = "MIT"

[tool.poetry.dependencies]
python = "3.10.*"
python = "3.11.*"

# See https://bot-core.pythondiscord.com/ for docs.
pydis-core = "10.1.0"
Expand All @@ -21,8 +21,8 @@ psycopg2-binary = "2.9.7"
toml = "0.10.2"

[tool.poetry.dev-dependencies]
pre-commit = "3.3.3"
ruff = "0.0.285"
pre-commit = "3.4.0"
ruff = "0.0.287"

[tool.poetry.scripts]
start = "metricity.__main__:start"
Expand All @@ -32,7 +32,7 @@ requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

[tool.ruff]
target-version = "py310"
target-version = "py311"
extend-exclude = [".cache", "alembic"]
ignore = [
"ANN002", "ANN003", "ANN101",
Expand Down

0 comments on commit 20cfe8a

Please sign in to comment.