Skip to content

Commit dfe160d

Browse files
chore: squash black & isort into ruff (#647)
This project uses `ruff`, `black` and `isort`. However, ruff can handle all the logic for everything. And so this PR squashes them all into one thing. With this change, I also update the target python style version. The only meaningful change there is adding strict to zip. Let me know if you want these zip functions to be strict or not. One note is that the bot can also be updated to format with ruff instead of black. But that is a larger feature change and not in the scope of this PR. --------- Co-authored-by: arielle <me@arielle.codes>
1 parent be34032 commit dfe160d

10 files changed

Lines changed: 19 additions & 120 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,9 @@ repos:
2828
hooks:
2929
- id: uv-lock
3030

31-
- repo: https://github.com/PyCQA/isort
32-
rev: 6.1.0
33-
hooks:
34-
- id: isort
35-
36-
- repo: https://github.com/psf/black
37-
rev: 25.1.0
38-
hooks:
39-
- id: black
40-
language_version: python3
41-
4231
- repo: https://github.com/charliermarsh/ruff-pre-commit
4332
rev: v0.13.3
4433
hooks:
4534
- id: ruff-check
4635
args: [--fix]
36+
- id: ruff-format

alembic.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne
5757
# on newly generated revision scripts. See the documentation for further
5858
# detail and examples
5959

60-
# format using "black" - use the console_scripts runner, against the "black" entrypoint
61-
hooks = black
62-
black.type = console_scripts
63-
black.entrypoint = black
64-
black.options = -l 100 REVISION_SCRIPT_FILENAME
60+
# format using "prek"
61+
hooks = pre_commit
62+
pre_commit.type = console_scripts
63+
pre_commit.entrypoint = prek
64+
pre_commit.options = run --files REVISION_SCRIPT_FILENAME
6565

6666
# Logging configuration
6767
[loggers]

monty/exts/core/bot_features.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ async def show_feature(
184184
colour = (
185185
disnake.Colour.green()
186186
if feature.enabled is True
187-
else disnake.Colour.greyple() if feature.enabled is None else disnake.Colour.red()
187+
else disnake.Colour.greyple()
188+
if feature.enabled is None
189+
else disnake.Colour.red()
188190
)
189191
components: list = [
190192
disnake.ui.Container(

monty/exts/filters/token_remover.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async def on_message(self, msg: disnake.Message) -> None:
111111
if found_tokens:
112112
# now check if the token is valid
113113
ids = await self.check_valid(*found_tokens)
114-
for token, application_id in zip(found_tokens, ids):
114+
for token, application_id in zip(found_tokens, ids, strict=False):
115115
if application_id:
116116
token.application_id = application_id
117117
else:

monty/exts/info/docs/_batch_parser.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def __eq__(self, other: "Union[QueueItem, _cog.DocItem]") -> bool:
7272
if TYPE_CHECKING:
7373

7474
class Deque(collections.deque[QueueItem]):
75-
7675
def index(self, value: Union[QueueItem, _cog.DocItem], start: int = 0, stop: Optional[int] = None) -> int: ...
7776

7877
else:

monty/exts/info/docs/_redis_cache.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ async def set(self, item: "DocItem", value: str) -> None:
4949

5050
async def get(self, item: "DocItem", default: Any = None) -> Optional[str]:
5151
"""Return the Markdown content of the symbol `item` if it exists."""
52-
res = await self._redis.hget(
53-
f"{self.namespace}:{item_key(item)}", item.symbol_id
54-
) # pyright: ignore[reportGeneralTypeIssues]
52+
res = await self._redis.hget(f"{self.namespace}:{item_key(item)}", item.symbol_id) # pyright: ignore[reportGeneralTypeIssues]
5553
if res:
5654
return res.decode()
5755
return default

monty/exts/python/pypi.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,7 @@ async def make_pypi_components(
240240
# and parse the html to get the rendered description
241241
# this means that we don't have to parse the rst or markdown or whatever is the
242242
# project's description content type
243-
description = await self.fetch_description(
244-
package, description, info["description_content_type"] or ""
245-
) # pyright: ignore[reportCallIssue]
243+
description = await self.fetch_description(package, description, info["description_content_type"] or "") # pyright: ignore[reportCallIssue]
246244
if description:
247245
components[0].children.append(disnake.ui.TextDisplay(description))
248246

monty/exts/utils/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def get_info(char: str) -> Tuple[str, str]:
7171
info = f"`{u_code.ljust(10)}`: {name} - {disnake.utils.escape_markdown(char)}"
7272
return (info, u_code)
7373

74-
(char_list, raw_list) = zip(*(get_info(c) for c in characters))
74+
(char_list, raw_list) = zip(*(get_info(c) for c in characters), strict=False)
7575
embed = disnake.Embed().set_author(name="Character Info")
7676

7777
if len(characters) > 1:

pyproject.toml

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ devlibs = [
5454
"python-dotenv<2.0.0,>=1.1.0",
5555
]
5656
tools = [
57-
"black<26.0.0,>=25.9.0",
58-
"isort==6.1.0",
5957
"poethepoet>=0.37.0",
6058
"prek>=0.2.1,<0.3",
6159
"ruff==0.13.3",
@@ -86,37 +84,17 @@ mdformat = [
8684
"mdformat-frontmatter<3.0.0,>=2.0.8",
8785
]
8886

89-
[tool.black]
90-
line-length = 120
91-
target-version = ['py38']
92-
include = '\.pyi?$'
93-
94-
[tool.isort]
95-
profile = "black"
96-
atomic = true
97-
ensure_newline_before_comments = true
98-
force_grid_wrap = 0
99-
include_trailing_comma = true
100-
line_length = 120
101-
lines_after_imports = 2
102-
multi_line_output = 3
103-
use_parentheses = true
104-
known_first_party = ["monty"]
105-
10687
[tool.ruff]
10788
line-length = 120
108-
target-version = "py38"
109-
110-
[tool.ruff.lint.isort]
111-
known-first-party = ["monty"]
112-
89+
target-version = "py310"
11390

11491
[tool.ruff.lint]
11592
select = [
11693
"E", # pycodestyle
11794
"F", # pyflakes
11895
"W", # pycodestyle
11996
"S", # bandit
97+
"I", # isort
12098
# "RUF", # ruff specific exceptions
12199
"ANN", # flake8-annotations
122100
"B", # flake8-bugbear
@@ -176,6 +154,10 @@ ignore = [
176154
"S311", # pseduo-random generators, random is used everywhere for random choices.
177155
]
178156

157+
[tool.ruff.lint.isort]
158+
lines-after-imports = 2
159+
known-first-party = ["monty"]
160+
179161
[tool.ruff.lint.per-file-ignores]
180162
"monty/alembic/*" = ["D"]
181163
"_global_source_snekcode.py" = ["T201"]

uv.lock

Lines changed: 0 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)