Skip to content

Commit e6d2e95

Browse files
authored
feat: update dependencies and build infrastructure (#91)
1 parent 336008f commit e6d2e95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1567
-1182
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
default_language_version:
2-
python: "3.11"
2+
python: "3.12"
33
default_install_hook_types: [commit-msg, pre-commit]
44
repos:
55
- repo: https://github.com/compilerla/conventional-pre-commit
6-
rev: v3.4.0
6+
rev: v4.2.0
77
hooks:
88
- id: conventional-pre-commit
99
stages: [commit-msg]
@@ -17,19 +17,19 @@ repos:
1717
- id: end-of-file-fixer
1818
- id: mixed-line-ending
1919
- id: trailing-whitespace
20-
- repo: https://github.com/charliermarsh/ruff-pre-commit
21-
rev: "v0.6.9"
20+
- repo: https://github.com/astral-sh/ruff-pre-commit
21+
rev: "v0.11.13"
2222
hooks:
2323
- id: ruff
2424
args: ["--fix"]
2525
- id: ruff-format
2626
- repo: https://github.com/sourcery-ai/sourcery
27-
rev: v1.23.0
27+
rev: v1.37.0
2828
hooks:
2929
- id: sourcery
3030
args: [--diff=git diff HEAD, --no-summary]
3131
- repo: https://github.com/codespell-project/codespell
32-
rev: v2.3.0
32+
rev: v2.4.1
3333
hooks:
3434
- id: codespell
3535
additional_dependencies:
@@ -39,7 +39,7 @@ repos:
3939
.*\.json |.*\.svg |docs/changelog.rst
4040
)$
4141
- repo: https://github.com/asottile/blacken-docs
42-
rev: 1.19.0
42+
rev: 1.19.1
4343
hooks:
4444
- id: blacken-docs
4545
- repo: https://github.com/pre-commit/mirrors-prettier
@@ -53,7 +53,7 @@ repos:
5353
# - id: curlylint
5454
# args: ["--format", "stylish"]
5555
- repo: https://github.com/python-formate/flake8-dunder-all
56-
rev: v0.4.1
56+
rev: v0.5.0
5757
hooks:
5858
- id: ensure-dunder-all
5959
exclude: "test*|examples*|tools"
@@ -88,7 +88,7 @@ repos:
8888
# discord-py,
8989
# ]
9090
- repo: https://github.com/RobertCraigie/pyright-python
91-
rev: v1.1.384
91+
rev: v1.1.402
9292
hooks:
9393
- id: pyright
9494
additional_dependencies:

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
python 3.11
2+
python 3.12

Makefile

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ UV ?= uv $(UV_OPTS)
2020
help: ## Display this help text for Makefile
2121
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
2222

23-
upgrade: ## Upgrade all dependencies to the latest stable versions
23+
upgrade: ## Upgrade all dependencies to the latest stable versions
24+
@echo "=> Upgrading pre-commit"
25+
@(UV_RUN_BIN) run pre-commit autoupdate
2426
@if [ "$(USING_UV)" ]; then $(UV) lock --upgrade
2527
@echo "Dependencies Updated"
2628

2729
# =============================================================================
2830
# Developer Utils
2931
# =============================================================================
3032

31-
install-uv: ## Install latest version of UV
33+
install-uv: ## Install latest version of UV
3234
@echo "=> Installing uv"
3335
@curl -LsSf https://astral.sh/uv/install.sh | sh
3436
@echo "=> uv installed"
@@ -37,29 +39,51 @@ install-pre-commit: ## Install pre-commit and install hooks
3739
@echo "Installing pre-commit hooks"
3840
@(UV_RUN_BIN) run pre-commit install --install-hooks --all
3941
@(UV_RUN_BIN) run pre-commit install --hook-type commit-msg
42+
@echo "=> pre-commit hooks installed, updating pre-commit hooks"
43+
@(UV_RUN_BIN) run pre-commit autoupdate
4044
@echo "pre-commit installed"
4145

4246
.PHONY: install-frontend
43-
install-frontend: ## Install the frontend dependencies
47+
install-frontend: ## Install the frontend dependencies
4448
@echo "=> Installing frontend dependencies"
4549
@nodeenv --python-virtualenv
4650
@npm install
4751
@echo "=> Frontend dependencies installed"
4852

4953
.PHONY: install-backend
50-
install-backend: ## Install the backend dependencies
54+
install-backend: ## Install the backend dependencies
5155
@echo "=> Installing backend dependencies"
5256
@$(UV) venv && $(UV) pip install --quiet -U wheel setuptools cython mypy pip
5357
@$(UV) sync --all-extras --force-reinstall --dev
5458
@echo "=> Backend dependencies installed"
5559

5660
.PHONY: install
57-
install: clean destroy ## Install the project, dependencies, and pre-commit for local development
61+
install: clean destroy ## Install the project, dependencies, and pre-commit for local development
5862
@if ! $(UV) --version > /dev/null; then $(MAKE) install-uv; fi
5963
@$(MAKE) install-backend
6064
@$(MAKE) install-frontend
6165
@echo "=> Install complete! Note: If you want to re-install re-run 'make install'"
6266

67+
up-container: ## Start the Byte database container
68+
@echo "=> Starting Byte database container"
69+
@docker compose -f docker-compose.infra.yml up -d
70+
@echo "=> Started Byte database container"
71+
72+
clean-container: ## Stop, remove, and wipe the Byte database container, volume, network, and orphans
73+
@echo "=> Stopping and removing Byte database container, volumes, networks, and orphans"
74+
@docker compose -f docker-compose.infra.yml down -v --remove-orphans
75+
@echo "=> Stopped and removed Byte database container, volumes, networks, and orphans"
76+
77+
load-container: up-container migrate ## Perform database migrations and load test data into the Byte database container
78+
@echo "=> Loading database migrations and test data"
79+
@$(UV) run app database upgrade --no-prompt
80+
@echo "rest not yet implemented"
81+
@echo "=> Loaded database migrations and test data"
82+
83+
refresh-container: clean-container up-container load-container ## Refresh the Byte database container
84+
85+
86+
6387
# =============================================================================
6488
# Tests, Linting, Coverage
6589
# =============================================================================
@@ -76,6 +100,12 @@ fmt: ## Runs Ruff format, makes changes where necessary
76100
ruff: ## Runs Ruff
77101
@$(UV) run --no-sync ruff check . --unsafe-fixes --fix
78102

103+
ruff-check: ## Runs Ruff without changing files
104+
@$(UV) run --no-sync ruff check .
105+
106+
ruff-noqa: ## Runs Ruff, adding noqa comments to disable warnings
107+
@$(UV) run --no-sync ruff check . --add-noqa
108+
79109
test: ## Run the tests
80110
@$(UV) run --no-sync pytest tests
81111

@@ -89,29 +119,29 @@ check-all: lint test fmt-check coverage ## Run all linting, tests, and coverage
89119
# =============================================================================
90120
# Docs
91121
# =============================================================================
92-
docs-clean: ## Dump the existing built docs
122+
docs-clean: ## Dump the existing built docs
93123
@echo "=> Cleaning documentation build assets"
94124
@rm -rf docs/_build
95125
@echo "=> Removed existing documentation build assets"
96126

97-
docs-serve: docs-clean ## Serve the docs locally
127+
docs-serve: docs-clean ## Serve the docs locally
98128
@echo "=> Serving documentation"
99129
$(UV) run sphinx-autobuild docs docs/_build/ -j auto --watch byte_bot --watch docs --watch tests --watch CONTRIBUTING.rst --port 8002
100130

101-
docs: docs-clean ## Dump the existing built docs and rebuild them
131+
docs: docs-clean ## Dump the existing built docs and rebuild them
102132
@echo "=> Building documentation"
103133
@$(UV) run sphinx-build -M html docs docs/_build/ -E -a -j auto --keep-going
104134

105135
# =============================================================================
106136
# Database
107137
# =============================================================================
108-
migrations: ## Generate database migrations
138+
migrations: ## Generate database migrations
109139
@echo "ATTENTION: This operation will create a new database migration for any defined models changes."
110140
@while [ -z "$$MIGRATION_MESSAGE" ]; do read -r -p "Migration message: " MIGRATION_MESSAGE; done ;
111141
@$(UV) run app database make-migrations --autogenerate -m "$${MIGRATION_MESSAGE}"
112142

113143
.PHONY: migrate
114-
migrate: ## Apply database migrations
144+
migrate: ## Apply database migrations
115145
@echo "ATTENTION: Will apply all database migrations."
116146
@$(UV) run app database upgrade --no-prompt
117147

@@ -155,11 +185,11 @@ destroy: ## Destroy the virtual environment
155185
run-dev-bot: ## Run the bot in dev mode
156186
@$(UV) run app run-bot
157187

158-
run-dev-server: ## Run the app in dev mode
188+
run-dev-server: up-container ## Run the app in dev mode
159189
@$(UV) run app run-web --http-workers 1 --reload
160190

161191
run-dev-frontend: ## Run the app frontend in dev mode
162192
@$(UV) run tailwindcss -i byte_bot/server/domain/web/resources/input.css -o byte_bot/server/domain/web/resources/style.css --watch
163193

164-
run-dev: ## Run the bot, web, and front end in dev mode
194+
run-dev: up-container ## Run the bot, web, and front end in dev mode
165195
@$(UV) run app run-all --http-workers 1 -d -v --reload

byte_bot/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
__all__ = (
1212
"__version__",
1313
"app",
14-
"cli",
15-
"utils",
1614
"byte",
15+
"cli",
1716
"server",
17+
"utils",
1818
)
1919

2020
rich_tracebacks(

byte_bot/__metadata__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import importlib.metadata
66

7-
__all__ = ("__version__", "__project__")
7+
__all__ = ("__project__", "__version__")
88

99
__version__ = importlib.metadata.version("byte-bot")
1010
"""Version of the app."""

byte_bot/byte/bot.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,18 @@ async def on_command_error(self, ctx: Context, error: CommandError) -> None:
9090
ctx: Context object.
9191
error: Error object.
9292
"""
93-
err = error.original if hasattr(error, "original") else error
93+
err = getattr(error, "original", error)
9494
if isinstance(err, Forbidden | NotFound):
9595
return
9696

9797
embed = discord.Embed(title="Command Error", description=str(error), color=discord.Color.red())
98-
embed.set_thumbnail(url=ctx.author.avatar.url)
98+
if ctx.author.avatar:
99+
embed.set_thumbnail(url=ctx.author.avatar.url)
99100
embed.add_field(name="Command", value=ctx.command)
100101
embed.add_field(name="Message", value=ctx.message.content)
101-
embed.add_field(name="Channel", value=ctx.channel.mention)
102+
embed.add_field(name="Channel", value=getattr(ctx.channel, "mention", str(ctx.channel)))
102103
embed.add_field(name="Author", value=ctx.author.mention)
103-
embed.add_field(name="Guild", value=ctx.guild.name)
104+
embed.add_field(name="Guild", value=ctx.guild.name if ctx.guild else "DM")
104105
embed.add_field(name="Location", value=f"[Jump]({ctx.message.jump_url})")
105106
embed.set_footer(text=f"Time: {ctx.message.created_at.strftime('%Y-%m-%d %H:%M:%S')}")
106107
await ctx.send(embed=embed, ephemeral=True)
@@ -132,7 +133,11 @@ async def on_guild_join(self, guild: discord.Guild) -> None:
132133
if response.status_code == httpx.codes.CREATED:
133134
logger.info("successfully added guild %s (ID: %s)", guild.name, guild.id)
134135
else:
135-
logger.error("%s joined guild '%s' but was not added to database", self.user.name, guild.name)
136+
logger.error(
137+
"%s joined guild '%s' but was not added to database",
138+
self.user.name if self.user else "Bot",
139+
guild.name,
140+
)
136141

137142

138143
def run_bot() -> None:

byte_bot/byte/lib/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from byte_bot.byte.lib import common, log, settings, utils
44

55
__all__ = [
6+
"common",
7+
"log",
68
"settings",
79
"utils",
8-
"log",
9-
"common",
1010
]

byte_bot/byte/lib/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from byte_bot.byte.lib import settings
1414

1515
__all__ = [
16-
"setup_logging",
1716
"get_logger",
17+
"setup_logging",
1818
]
1919

2020
install(show_locals=True, theme="dracula")

byte_bot/byte/lib/settings.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import os
6-
from pathlib import Path # noqa: TCH003
6+
from pathlib import Path # noqa: TC003
77
from typing import Final
88

99
from dotenv import load_dotenv
@@ -14,12 +14,12 @@
1414
from byte_bot.__metadata__ import __version__ as version
1515

1616
__all__ = [
17-
"discord",
18-
"log",
19-
"project",
2017
"DiscordSettings",
2118
"LogSettings",
2219
"ProjectSettings",
20+
"discord",
21+
"log",
22+
"project",
2323
]
2424

2525
load_dotenv()
@@ -44,13 +44,13 @@ class DiscordSettings(BaseSettings):
4444
"""Discord User ID for development."""
4545
PLUGINS_LOC: Path = PLUGINS_DIR
4646
"""Base Path to plugins directory."""
47-
PLUGINS_DIRS: list[Path] = [f"{PLUGINS_DIR}"]
47+
PLUGINS_DIRS: list[Path] = [PLUGINS_DIR]
4848
"""Directories to search for plugins."""
4949
PRESENCE_URL: str = ""
5050

5151
@field_validator("COMMAND_PREFIX")
5252
@classmethod
53-
def assemble_command_prefix(cls, value: str) -> list[str]:
53+
def assemble_command_prefix(cls, value: list[str]) -> list[str]:
5454
"""Assembles the bot command prefix based on the environment.
5555
5656
Args:
@@ -66,7 +66,9 @@ def assemble_command_prefix(cls, value: str) -> list[str]:
6666
}
6767
environment = os.getenv("ENVIRONMENT", "dev")
6868
# Add env specific command prefix in addition to the default "!"
69-
value.append(os.getenv("COMMAND_PREFIX", env_urls[environment]))
69+
env_prefix = os.getenv("COMMAND_PREFIX", env_urls[environment])
70+
if env_prefix not in value:
71+
value.append(env_prefix)
7072
return value
7173

7274
@field_validator("PRESENCE_URL")
@@ -125,13 +127,11 @@ class ProjectSettings(BaseSettings):
125127

126128

127129
# noinspection PyShadowingNames
128-
def load_settings() -> (
129-
tuple[
130-
DiscordSettings,
131-
LogSettings,
132-
ProjectSettings,
133-
]
134-
):
130+
def load_settings() -> tuple[
131+
DiscordSettings,
132+
LogSettings,
133+
ProjectSettings,
134+
]:
135135
"""Load Settings file.
136136
137137
Returns:

byte_bot/byte/lib/utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@
2626
from discord.ext.commands._types import Check
2727

2828
__all__ = (
29+
"PEP",
2930
"BaseRuffRule",
30-
"RuffRule",
3131
"FormattedRuffRule",
32-
"PEP",
32+
"RuffRule",
33+
"chunk_sequence",
34+
"format_ruff_rule",
3335
"is_byte_dev",
3436
"linker",
35-
"mention_user",
36-
"mention_user_nickname",
3737
"mention_channel",
38-
"mention_role",
39-
"mention_slash_command",
4038
"mention_custom_emoji",
4139
"mention_custom_emoji_animated",
42-
"mention_timestamp",
4340
"mention_guild_navigation",
44-
"format_ruff_rule",
45-
"query_all_ruff_rules",
46-
"run_ruff_format",
41+
"mention_role",
42+
"mention_slash_command",
43+
"mention_timestamp",
44+
"mention_user",
45+
"mention_user_nickname",
4746
"paste",
48-
"chunk_sequence",
4947
"query_all_peps",
48+
"query_all_ruff_rules",
49+
"run_ruff_format",
5050
)
5151

5252
_T = TypeVar("_T")

0 commit comments

Comments
 (0)