Skip to content

Commit

Permalink
Optimize pre-commit workflow (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
No767 authored Oct 22, 2024
1 parent 8f802b1 commit 8e6e9c3
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 64 deletions.
48 changes: 0 additions & 48 deletions .pre-commit-config.yaml

This file was deleted.

1 change: 0 additions & 1 deletion bot/cogs/ext/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from discord.ext import commands, tasks

try:

from prometheus_async.aio.web import start_http_server
from prometheus_client import Counter, Enum, Gauge, Info, Summary
except ImportError:
Expand Down
4 changes: 3 additions & 1 deletion bot/cogs/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ async def about(self, interaction: discord.Interaction) -> None:

revisions = self.get_last_commits()
embed = Embed()
embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.display_avatar.url) # type: ignore
embed.set_author(
name=self.bot.user.name, icon_url=self.bot.user.display_avatar.url
) # type: ignore
embed.title = "Support Server Invite"
embed.url = "https://discord.gg/ns3e74frqn"
desc = [
Expand Down
1 change: 0 additions & 1 deletion bot/cogs/pride_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ def disambiguate(self, rows) -> str:
async def send_profile(
self, interaction: discord.Interaction, profile: PrideProfile
) -> None:

query = """
UPDATE pride_profiles
SET views = views + 1
Expand Down
7 changes: 6 additions & 1 deletion bot/cogs/pronouns.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,12 @@ def format_info(self, entry: ProfileInfo) -> PartialProfileInfo:
for sub_entry in entry.pronouns
),
flags=", ".join(flag for flag in entry.flags),
circle="\n".join(f"- {self.determine_mutual(entity['username'], entity['circleMutual'])}\n\t- Relationship: {entity['relationship']}" for entity in entry.meta.circle) if len(entry.meta.circle) != 0 else "None", # type: ignore
circle="\n".join(
f"- {self.determine_mutual(entity['username'], entity['circleMutual'])}\n\t- Relationship: {entity['relationship']}"
for entity in entry.meta.circle
)
if len(entry.meta.circle) != 0
else "None", # type: ignore
)

async def format_page(self, menu: ProfilePages, page):
Expand Down
5 changes: 4 additions & 1 deletion bot/libs/utils/pages/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ def _update_labels(self, page_number: int) -> None:
async def start(
self, *, content: Optional[str] = None, ephemeral: bool = False
) -> None:
if self.check_embeds and not self.ctx.channel.permissions_for(self.ctx.me).embed_links: # type: ignore
if (
self.check_embeds
and not self.ctx.channel.permissions_for(self.ctx.me).embed_links
): # type: ignore
await self.ctx.send(
"Bot does not have embed links permission in this channel.",
ephemeral=True,
Expand Down
4 changes: 3 additions & 1 deletion bot/libs/utils/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ async def on_error(
elif isinstance(error, app_commands.CommandInvokeError):
original = error.original
if not isinstance(original, discord.HTTPException):
bot.logger.exception("In %s: ", interaction.command.qualified_name, exc_info=original) # type: ignore
bot.logger.exception(
"In %s: ", interaction.command.qualified_name, exc_info=original
) # type: ignore
await interaction.response.send_message(
embed=FullErrorEmbed(error), ephemeral=True
)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guides/dev/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Local Setup
.. code-block:: bash
pip install -r requirements-dev.txt \
&& pre-commit install
&& lefthook install
5. Copy over the ``config-example.yml`` template over to the ``bot`` directory. Modify the values as appropriate.

Expand Down
14 changes: 14 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pre-commit:
commands:
bandit:
glob: "*.py"
staged_files: true
run: bandit {staged_files} -c pyproject.toml
ruff-check:
glob: "*.py"
staged_files: true
run: ruff check {staged_files} --fix --exit-non-zero-on-fix --config pyproject.toml
ruff-fmt:
glob: "*.py"
staged_files: true
run: ruff format {staged_files} --config pyproject.toml
42 changes: 35 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.9,<4.0"

[tool.isort]
profile = 'black'
combine_as_imports = true
combine_star = true
line_length = 80

[tool.pyright]
include = ["bot/**"]
exclude = [
Expand All @@ -29,9 +23,43 @@ reportUnnecessaryTypeIgnoreComment = "warning"
[tool.bandit]
skips = ["B311", "B101"]

[tool.ruff]
line-length = 88
indent-width = 4

[tool.ruff.lint]
ignore = ["E501", "N999", "E402", "S101", "ASYNC109"]
ignore = [
"E501",
"N999",
"E402",
"S311",
"ASYNC109",
"S101",

# These are recommended by Ruff if the formatter is to be used: https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
"E114",
"E117",
"D206",
"D300",
"Q000",
"Q001",
"Q002",
"Q003",
"COM812",
"COM819",
"ISC001",
"ISC002"
]
select = ["E", "F", "N", "ASYNC", "S", "ERA"]
fixable = ["ALL"]

[tool.ruff.lint.isort]
combine-as-imports = true

[tool.ruff.format]
docstring-code-format = true

[tool.pytest.ini_options]
minversion = "8.0"
Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
-r requirements.txt

# Development libraries
pre-commit>=3.5.0,<5
lefthook>=1.7.22,<2
pyright>=1.1.355,<2
bandit[toml]>=1.7.10,<2
ruff>=0.3.4,<1
tox>=4.14.2,<5

Expand Down
19 changes: 18 additions & 1 deletion taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,21 @@ tasks:
preconditions:
- test -f docker/docker-compose.dev.yml
cmds:
- docker compose -f docker/docker-compose.dev.yml stop
- docker compose -f docker/docker-compose.dev.yml stop

bot:
preconditions:
- test -f bot/config.yml
cmds:
- python3 bot/catherinebot.py
silent: true

check:
cmds:
- ruff check bot --fix --exit-non-zero-on-fix --config pyproject.toml
silent: true

fmt:
cmds:
- ruff format bot --config pyproject.toml
silent: true

0 comments on commit 8e6e9c3

Please sign in to comment.