Skip to content

Commit

Permalink
Merge pull request #142 from python-discord/jb3/dep-bumps
Browse files Browse the repository at this point in the history
Bump Poetry Python version to 3.12
  • Loading branch information
jb3 authored Apr 7, 2024
2 parents 06ae7a2 + 2078972 commit ac45f4c
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 275 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.2
with:
python_version: '3.11'
python_version: '3.12'

- name: Run pre-commit hooks
run: SKIP=ruff pre-commit run --all-files
Expand Down
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.11-slim
FROM --platform=linux/amd64 ghcr.io/owl-corp/python-poetry-base:3.12-slim

ENV PYTHONHASHSEED=random

Expand Down
3 changes: 3 additions & 0 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@

config.set_main_option("sqlalchemy.url", build_db_uri())


def do_run_migrations(connection: Connection) -> None:
"""Run migrations."""
context.configure(connection=connection, target_metadata=target_metadata)

with context.begin_transaction():
context.run_migrations()


async def run_async_migrations() -> None:
"""Run migrations asynchronously using the asyncpg driver."""
connectable = async_engine_from_config(
Expand All @@ -50,6 +52,7 @@ async def run_async_migrations() -> None:

await connectable.dispose()


def run_migrations_offline() -> None:
"""
Run migrations in 'offline' mode.
Expand Down
5 changes: 5 additions & 0 deletions create_metricity_db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Ensures the metricity db exists before running migrations."""

import asyncio
from urllib.parse import SplitResult, urlsplit

Expand All @@ -18,6 +19,7 @@ def parse_db_url(db_url: str) -> SplitResult:
raise ValueError("The given db_url is not a valid PostgreSQL database URL.")
return db_url_parts


async def create_db() -> None:
"""Create the Metricity database if it does not exist."""
parts = parse_db_url(build_db_uri())
Expand Down Expand Up @@ -45,5 +47,8 @@ async def create_db() -> None:

await sys_conn.close()


if __name__ == "__main__":
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
asyncio.get_event_loop().run_until_complete(create_db())
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.8"

x-logging: &logging
driver: "json-file"
options:
Expand Down
3 changes: 3 additions & 0 deletions metricity/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

log = logging.getLogger(__name__)


def build_db_uri() -> str:
"""Build the database uri from the config."""
if DatabaseConfig.uri:
Expand All @@ -27,9 +28,11 @@ def build_db_uri() -> str:
f"@{DatabaseConfig.host}:{DatabaseConfig.port}/{DatabaseConfig.database}"
)


engine: AsyncEngine = create_async_engine(build_db_uri(), echo=DatabaseConfig.log_queries)
async_session = async_sessionmaker(engine, expire_on_commit=False)


class TZDateTime(TypeDecorator):
"""
A db type that supports the use of aware datetimes in user-land.
Expand Down
1 change: 1 addition & 0 deletions metricity/exts/event_listeners/guild_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

log = logging.get_logger(__name__)


class GuildListeners(commands.Cog):
"""Listen for guild (and guild channel) events and sync them to the database."""

Expand Down
1 change: 0 additions & 1 deletion metricity/exts/event_listeners/member_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ async def on_member_update(self, _before: discord.Member, member: discord.Member
await sess.commit()



async def setup(bot: Bot) -> None:
"""Load the MemberListeners cog."""
await bot.add_cog(MemberListeners(bot))
518 changes: 253 additions & 265 deletions poetry.lock

Large diffs are not rendered by default.

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

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

# See https://bot-core.pythondiscord.com/ for docs.
pydis-core = "10.7.0"
pydis-core = "11.1.0"

alembic = "1.13.1"
coloredlogs = "15.0.1"
deepmerge = "1.1.1"
sqlalchemy = { extras = ["asyncio"], version = "2.0.25" }
sqlalchemy = { extras = ["asyncio"], version = "2.0.29" }
python-dotenv = "1.0.1"
asyncpg = "0.29.0"

[tool.poetry.dev-dependencies]
pre-commit = "3.6.0"
ruff = "0.2.0"
pre-commit = "3.7.0"
ruff = "0.3.5"

[tool.poetry.scripts]
start = "metricity.__main__:start"
Expand Down

0 comments on commit ac45f4c

Please sign in to comment.