Skip to content

Commit 7f56ad9

Browse files
committed
ci: Add ruff and build workflows
1 parent 6aadaba commit 7f56ad9

Some content is hidden

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

67 files changed

+656
-494
lines changed

.github/workflows/ruff.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# https://beta.ruff.rs
2+
name: ruff
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
jobs:
11+
ruff:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- run: pip install --user ruff
16+
- run: ruff --format=github .

.github/workflows/run.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "run"
2+
3+
on:
4+
push
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: actions/setup-python@v4
12+
with:
13+
python-version: 3.11
14+
- name: Install dependencies
15+
run: |
16+
python -m pip install -r requirements.txt
17+
python -m pip install disnake-docs disnake-debug
18+
python -m pip install pytest
19+
- name: Run main file
20+
run: python main.py
21+
- name: Run tests
22+
run: pytest .
23+

.pre-commit-config.yaml

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,52 @@ repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
33
rev: v4.4.0
44
hooks:
5+
- id: check-executables-have-shebangs
56
- id: check-toml
67
- id: check-yaml
78
- id: end-of-file-fixer
9+
types: [python]
810
- id: trailing-whitespace
9-
args: [--markdown-linebreak-ext=md]
11+
- id: requirements-txt-fixer
1012

11-
- repo: https://github.com/pre-commit/pygrep-hooks
12-
rev: v1.10.0
13+
- repo: https://github.com/MarcoGorelli/auto-walrus
14+
rev: v0.2.2
1315
hooks:
14-
- id: python-check-blanket-noqa
16+
- id: auto-walrus
1517

16-
- repo: https://github.com/pycqa/flake8
17-
rev: 6.0.0
18+
- repo: https://github.com/charliermarsh/ruff-pre-commit
19+
rev: v0.0.270
1820
hooks:
19-
- id: flake8
20-
# additional_dependencies:
21-
# - flake8-docstrings~=1.6.0
21+
- id: ruff
22+
23+
- repo: https://github.com/psf/black
24+
rev: 23.3.0
25+
hooks:
26+
- id: black
27+
28+
- repo: https://github.com/codespell-project/codespell
29+
rev: v2.2.4
30+
hooks:
31+
- id: codespell
32+
additional_dependencies:
33+
- tomli
34+
35+
- repo: https://github.com/tox-dev/pyproject-fmt
36+
rev: "0.11.2"
37+
hooks:
38+
- id: pyproject-fmt
39+
40+
- repo: https://github.com/abravalheri/validate-pyproject
41+
rev: v0.13
42+
hooks:
43+
- id: validate-pyproject
44+
45+
- repo: https://github.com/pre-commit/mirrors-mypy
46+
rev: v1.3.0
47+
hooks:
48+
- id: mypy
49+
args:
50+
- --ignore-missing-imports
51+
- --install-types # See mirrors-mypy README.md
52+
- --non-interactive
53+
additional_dependencies: [types-requests]

cogs/config.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ async def jokechannel(self, ctx: Context, channel: disnake.TextChannel = None):
4949
channel = await ctx.guild.create_text_channel(name="Joke Channel")
5050

5151
await self.insert_values(channel.id, "joke")
52-
await send_embed(
53-
ctx, None, channel.mention + " now sends jokes on the hour!"
54-
)
52+
await send_embed(ctx, None, channel.mention + " now sends jokes on the hour!")
5553

5654
@command()
5755
@has_permissions(manage_channels=True)
@@ -60,9 +58,7 @@ async def quotechannel(self, ctx: Context, channel: disnake.TextChannel = None):
6058
channel = await ctx.guild.create_text_channel(name="Joke Channel")
6159

6260
await self.insert_values(channel.id, "quote")
63-
await send_embed(
64-
ctx, None, channel.mention + " now sends quotes on the hour!"
65-
)
61+
await send_embed(ctx, None, channel.mention + " now sends quotes on the hour!")
6662

6763
@command()
6864
@has_permissions(manage_channels=True)
@@ -71,9 +67,7 @@ async def factchannel(self, ctx: Context, channel: disnake.TextChannel = None):
7167
channel = await ctx.guild.create_text_channel(name="Joke Channel")
7268

7369
await self.insert_values(channel.id, "fact")
74-
await send_embed(
75-
ctx, None, channel.mention + " now sends facts on the hour!"
76-
)
70+
await send_embed(ctx, None, channel.mention + " now sends facts on the hour!")
7771

7872
@command(
7973
aliases=["Welcomer", "welcome"],
@@ -83,7 +77,6 @@ async def factchannel(self, ctx: Context, channel: disnake.TextChannel = None):
8377
async def welcomechannel(
8478
self, ctx: Context, role: disnake.Role = "", *, message: str = ""
8579
):
86-
8780
with open("./dicts/Welcome.json", "r+") as f:
8881
data = json.load(f)
8982
if not role:
@@ -110,7 +103,8 @@ async def welcomechannel(
110103
await ctx.reply(embed=embed)
111104

112105
@command(
113-
aliases=["Unwelcome", "Stop_Welcome"], description="Removes the j.welcome command"
106+
aliases=["Unwelcome", "Stop_Welcome"],
107+
description="Removes the j.welcome command",
114108
)
115109
async def remove_welcome(self, ctx: Context):
116110
with open("./dicts/Welcome.json", "r+") as f:
@@ -130,7 +124,6 @@ async def suggestchannel(self, ctx: Context, channel: disnake.TextChannel):
130124
with open("./dicts/Suggest.json", "r+") as k:
131125
data = json.load(k)
132126
if str(channel.id) not in data:
133-
134127
data[str(channel.id)] = {"Yes": True}
135128
update_json(k, data)
136129
if channel.id != ctx.channel.id:
@@ -187,7 +180,6 @@ async def verifychannel(
187180
).content
188181
).lower()
189182
if received_msg != "y":
190-
191183
embed = disnake.Embed(title="Goodbye!", colour=get_colour())
192184
return await ctx.reply(embed=embed)
193185

@@ -198,14 +190,14 @@ async def verifychannel(
198190
if "Yes" in data[key]:
199191
if data[key]["Yes"]:
200192
if data[key]["Guild"] == ctx.guild.id:
201-
202193
return await ctx.reply("There is already a verify here!")
203194
if not channel:
204195
channel = await ctx.guild.create_text_channel(name="⚘ verify ⚘")
205196
with open("./dicts/VerifyChannel.json", "r+") as k:
206197
if role is None:
207198
await ctx.guild.create_role(
208-
name="⚘ Member ⚘", permissions=disnake.Permissions(send_messages=True)
199+
name="⚘ Member ⚘",
200+
permissions=disnake.Permissions(send_messages=True),
209201
)
210202
membrole = disnake.utils.get(ctx.guild.roles, name="⚘ Member ⚘")
211203
await ctx.guild.create_role(
@@ -222,7 +214,6 @@ async def verifychannel(
222214
read_messages=False,
223215
)
224216
else:
225-
226217
await x.set_permissions(
227218
membrole,
228219
speak=True,
@@ -270,7 +261,6 @@ async def verifychannel(
270261
read_messages=False,
271262
)
272263
else:
273-
274264
await z.set_permissions(
275265
g,
276266
speak=True,
@@ -311,7 +301,6 @@ async def verifychannel(
311301
@command(aliases=["remverify"], description="removes the need for a verification")
312302
@has_permissions(administrator=True)
313303
async def removeverify(self, ctx: Context):
314-
315304
with open("./dicts/VerifyChannel.json", "r+") as k:
316305
data = json.load(k)
317306
for key in data:
@@ -332,9 +321,10 @@ async def leavechannel(self, ctx: Context, channel: disnake.TextChannel = None):
332321
ctx, "Leaving", "This server is already registered!"
333322
)
334323
else:
335-
336324
if not channel:
337-
channel = await ctx.guild.create_text_channel(name="Leaving Channel")
325+
channel = await ctx.guild.create_text_channel(
326+
name="Leaving Channel"
327+
)
338328
data[str(ctx.guild.id)] = {"id": channel.id}
339329
update_json(k, data)
340330
await send_embed(
@@ -345,7 +335,6 @@ async def leavechannel(self, ctx: Context, channel: disnake.TextChannel = None):
345335
@command()
346336
async def removeleavechannel(self, ctx: Context, channel: disnake.TextChannel):
347337
with open("./dicts/LeaveChannel.json", "r+") as k:
348-
349338
data = json.load(k)
350339
if str(ctx.guild.id) not in data:
351340
return await send_embed(

cogs/countries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def findcountry(self, ctx: Context, *, name):
5050
y = []
5151
async with self.bot.client.get("https://restcountries.eu/rest/v2/all") as resp:
5252
x = await resp.json()
53-
for (num, k) in enumerate(x):
53+
for num, k in enumerate(x):
5454
if x[num]["name"].lower().startswith(name[:1]):
5555
y.append(x[num]["name"])
5656
await send_embed(ctx, "Countries relating to " + name, ", ".join(y))

cogs/crime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def jailbase(
6161
json = await resp.json()
6262

6363
choice = random.randint(0, len(json["records"]))
64-
info = json["records"][choice]
64+
json["records"][choice]
6565
await ctx.em(
6666
re.sub(
6767
"\n{2,}",
@@ -95,7 +95,7 @@ async def police(self, ctx: Context) -> None:
9595
) as resp:
9696
json = await resp.json()
9797

98-
police = ", ".join(json[k]["name"] for k in range(0, len(json)))
98+
", ".join(json[k]["name"] for k in range(0, len(json)))
9999
await ctx.em(
100100
"""```yaml
101101
++ -- All police forces in england -- ++

cogs/docs/cog.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ async def rtfm(self, ctx: Context, query):
4848

4949
@commands.command()
5050
async def pypi(self, ctx: Context, package):
51-
embed = disnake.Embed(title="", description="").set_thumbnail(url=self.PYPI_ICON)
51+
embed = disnake.Embed(title="", description="").set_thumbnail(
52+
url=self.PYPI_ICON
53+
)
5254
async with self.bot.client.get(self.URL.format(package=package)) as response:
5355
if response.status == 404:
5456
embed.description = "Package could not be found."
@@ -68,7 +70,9 @@ async def pypi(self, ctx: Context, package):
6870
embed.description = "No summary provided."
6971

7072
else:
71-
embed.description = "There was an error when fetching your PyPi package."
73+
embed.description = (
74+
"There was an error when fetching your PyPi package."
75+
)
7276
await ctx.reply(embed=embed)
7377

7478
@commands.command(aliases=["tags"])
@@ -102,7 +106,8 @@ async def zen(self, ctx: Context, search: int = None) -> None:
102106
if len(lines) > search:
103107
return await ctx.reply(
104108
embed=disnake.Embed(
105-
title=f"The Zen of Python - Line {search}", description=lines[search]
109+
title=f"The Zen of Python - Line {search}",
110+
description=lines[search],
106111
)
107112
)
108113

cogs/docs/exts.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ def parse_object_inv(self, stream, url):
102102

103103
async def build_rtfm_lookup_table(self, page_types):
104104
cache = {}
105-
for (key, page) in page_types.items():
105+
for key, page in page_types.items():
106106
cache[key] = {}
107107
async with self.bot.client.get(page + "/objects.inv") as resp:
108108
if resp.status != 200:
109-
raise RuntimeError("Cannot build rtfm lookup table, try again later.")
109+
raise RuntimeError(
110+
"Cannot build rtfm lookup table, try again later."
111+
)
110112

111113
stream = SphinxObjectFileReader(await resp.read())
112114
cache[key] = self.parse_object_inv(stream, page)

cogs/docs/fuzzy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def partial_ratio(a, b):
2020
blocks = m.get_matching_blocks()
2121

2222
scores = []
23-
for (i, j, n) in blocks:
23+
for i, j, n in blocks:
2424
start = max(j - i, 0)
2525
end = start + len(short)
2626
o = SequenceMatcher(None, short, long[start:end])
@@ -61,7 +61,7 @@ def partial_token_sort_ratio(a, b):
6161

6262
def _extraction_generator(query, choices, scorer=quick_ratio, score_cutoff=0):
6363
try:
64-
for (key, value) in choices.items():
64+
for key, value in choices.items():
6565
score = scorer(query, key)
6666
if score >= score_cutoff:
6767
yield (key, score, value)

cogs/docs/menus.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ def _cast_emoji(obj, *, _custom_emoji=_custom_emoji):
9696
return obj
9797

9898
obj = str(obj)
99-
match = _custom_emoji.match(obj)
100-
if match is not None:
99+
if (match := _custom_emoji.match(obj)) is not None:
101100
groups = match.groupdict()
102101
animated = bool(groups["animated"])
103102
emoji_id = int(groups["id"])
@@ -258,15 +257,15 @@ def __new__(cls, name, bases, attrs, **kwargs):
258257
if inherit_buttons:
259258
# walk MRO to get all buttons even in subclasses
260259
for base in reversed(new_cls.__mro__):
261-
for (elem, value) in base.__dict__.items():
260+
for elem, value in base.__dict__.items():
262261
try:
263262
value.__menu_button__
264263
except AttributeError:
265264
continue
266265
else:
267266
buttons.append(value)
268267
else:
269-
for (elem, value) in attrs.items():
268+
for elem, value in attrs.items():
270269
try:
271270
value.__menu_button__
272271
except AttributeError:
@@ -325,9 +324,8 @@ def __init__(
325324
delete_message_after=False,
326325
clear_reactions_after=False,
327326
check_embeds=False,
328-
message=None
327+
message=None,
329328
):
330-
331329
self.timeout = timeout
332330
self.delete_message_after = delete_message_after
333331
self.clear_reactions_after = clear_reactions_after
@@ -963,7 +961,9 @@ def should_add_reactions(self):
963961
return self._source.is_paginating()
964962

965963
async def _get_kwargs_from_page(self, page):
966-
value = await disnake.utils.maybe_coroutine(self._source.format_page, self, page)
964+
value = await disnake.utils.maybe_coroutine(
965+
self._source.format_page, self, page
966+
)
967967
if isinstance(value, dict):
968968
return value
969969
elif isinstance(value, str):
@@ -1129,7 +1129,7 @@ def __init__(self, entries, *, key, per_page, sort=True):
11291129
self.__entries = entries if not sort else sorted(entries, key=key)
11301130
nested = []
11311131
self.nested_per_page = per_page
1132-
for (k, g) in itertools.groupby(self.__entries, key=key):
1132+
for k, g in itertools.groupby(self.__entries, key=key):
11331133
g = list(g)
11341134
if not g:
11351135
continue

0 commit comments

Comments
 (0)