Skip to content

Commit

Permalink
lint: Replace Black with Ruff.
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Kaseorg <[email protected]>
  • Loading branch information
andersk committed Oct 28, 2023
1 parent 2a0eff6 commit a49add3
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 64 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,5 @@ src = [
"zulip_bots",
"zulip_botserver",
]
target-version = "py38"
line-length = 100
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
crayons
twine
black~=23.10.1
mock
pytest
pytest-cov
Expand Down
4 changes: 1 addition & 3 deletions tools/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def pack(options: argparse.Namespace) -> None:
[deploy]
bot={}
zuliprc=zuliprc
""".format(
options.main
)
""".format(options.main)
)
zip_file.writestr("config.ini", bot_config)
zip_file.close()
Expand Down
15 changes: 6 additions & 9 deletions tools/lint
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#! /usr/bin/env python3

import argparse
import re
import sys

from zulint.command import LinterConfig, add_default_linter_arguments
Expand Down Expand Up @@ -36,16 +35,14 @@ def run() -> None:
"ruff", ["ruff", "check", "--quiet"], ["py"], fix_arg="--fix", description="Python linter"
)
linter_config.external_linter(
"gitlint", ["tools/lint-commits"], description="Git Lint for commit messages"
"ruff-format",
["ruff", "format", "--quiet"],
["py"],
check_arg="--check",
description="Python formatter",
)
linter_config.external_linter(
"black",
["black"],
["py"],
description="Reformats Python code",
check_arg=["--check"],
suppress_line=lambda line: line == "All done! ✨ 🍰 ✨\n"
or re.fullmatch(r"\d+ files? would be left unchanged\.\n", line) is not None,
"gitlint", ["tools/lint-commits"], description="Git Lint for commit messages"
)

@linter_config.lint
Expand Down
6 changes: 4 additions & 2 deletions tools/provision
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ the Python version this command is executed with."""

if py_version <= (3, 1) and (not options.force):
print(
red + "Provision failed: Cannot create venv with outdated Python version ({}).\n"
"Maybe try `python3 tools/provision`.".format(py_version_output.strip()) + end_format
red
+ "Provision failed: Cannot create venv with outdated Python version ({}).\n"
"Maybe try `python3 tools/provision`.".format(py_version_output.strip())
+ end_format
)
sys.exit(1)

Expand Down
12 changes: 3 additions & 9 deletions zulip/integrations/jabber/jabber_mirror_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ def config_error(msg: str) -> None:
zulip configuration file under the jabber_mirror section (exceptions are noted
in their help sections). Keys have the same name as options with hyphens
replaced with underscores. Zulip configuration options go in the api section,
as normal.""".replace(
"\n", " "
)
as normal.""".replace("\n", " ")
)
parser.add_option(
"--mode",
Expand All @@ -314,9 +312,7 @@ def config_error(msg: str) -> None:
all messages they send on Zulip to Jabber and all private Jabber messages to
Zulip. In "public" mode, the mirror uses the credentials for a dedicated mirror
user and mirrors messages sent to Jabber rooms to Zulip. Defaults to
"personal"'''.replace(
"\n", " "
),
"personal"'''.replace("\n", " "),
)
parser.add_option(
"--zulip-email-suffix",
Expand All @@ -327,9 +323,7 @@ def config_error(msg: str) -> None:
suffix before sending requests to the Jabber server. For example, specifying
"+foo" will cause messages that are sent to the "bar" room by nickname "qux" to
be mirrored to the "bar/xmpp" stream in Zulip by user "[email protected]". This
option does not affect login credentials.""".replace(
"\n", " "
),
option does not affect login credentials.""".replace("\n", " "),
)
parser.add_option(
"-d",
Expand Down
4 changes: 1 addition & 3 deletions zulip/integrations/perforce/zulip_change-commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@
```quote
{desc}
```
""".format(
user=metadata["user"], change=change, path=changeroot, desc=metadata["desc"]
)
""".format(user=metadata["user"], change=change, path=changeroot, desc=metadata["desc"])

message_data: Dict[str, Any] = {
"type": "stream",
Expand Down
5 changes: 3 additions & 2 deletions zulip/tests/test_default_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ def test_config_path_with_tilde(self, mock_os_path_exists: bool) -> None:
expanded_test_path = os.path.abspath(os.path.expanduser(test_path))
self.assertEqual(
str(cm.exception),
"api_key or email not specified and "
"file {} does not exist".format(expanded_test_path),
"api_key or email not specified and " "file {} does not exist".format(
expanded_test_path
),
)


Expand Down
4 changes: 1 addition & 3 deletions zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def test_invalid_when_handle_message(self) -> None:
{"auth_token": "someInvalidKey", "username": "aaron", "goalname": "goal"}
), patch("requests.get", side_effect=ConnectionError()), self.mock_http_conversation(
"test_invalid_when_handle_message"
), patch(
"logging.exception"
):
), patch("logging.exception"):
self.verify_reply("5", "Error. Check your key!")

def test_error(self) -> None:
Expand Down
3 changes: 1 addition & 2 deletions zulip_bots/zulip_bots/bots/chessbot/chessbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> No
if bot_handler.storage.contains("is_with_computer"):
is_with_computer = (
# `bot_handler`'s `storage` only accepts `str` values.
bot_handler.storage.get("is_with_computer")
== str(True)
bot_handler.storage.get("is_with_computer") == str(True)
)

if bot_handler.storage.contains("last_fen"):
Expand Down
4 changes: 1 addition & 3 deletions zulip_bots/zulip_bots/bots/idonethis/test_idonethis.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def test_bad_key(self) -> None:
{"api_key": "87654321", "default_team": "testing team 1"}
), self.mock_http_conversation("test_401"), patch(
"zulip_bots.bots.idonethis.idonethis.api_noop"
), patch(
"logging.error"
):
), patch("logging.error"):
self.verify_reply(
"list teams",
"I can't currently authenticate with idonethis. Can you check that your API key is correct? "
Expand Down
4 changes: 1 addition & 3 deletions zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,7 @@ def display_game(topic_name, merels_storage):
response += interface.graph_grid(data.grid()) + "\n"
response += """Phase {}. Take mode: {}.
X taken: {}, O taken: {}.
""".format(
data.get_phase(), take, data.x_taken, data.o_taken
)
""".format(data.get_phase(), take, data.x_taken, data.o_taken)

return response

Expand Down
8 changes: 2 additions & 6 deletions zulip_bots/zulip_bots/game_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ def help_message_single_player(self) -> str:
`quit`
* To see rules of this game, type
`rules`
{}""".format(
self.game_name, self.get_bot_username(), self.move_help_message
)
{}""".format(self.game_name, self.get_bot_username(), self.move_help_message)

def get_commands(self) -> Dict[str, str]:
action = self.help_message_single_player()
Expand Down Expand Up @@ -644,9 +642,7 @@ def parse_message(self, message: Dict[str, Any]) -> None:
message,
"Your current game is not in this subject. \n\
To move subjects, send your message again, otherwise join the game using the link below.\n\n\
{}".format(
self.get_formatted_game_object(game_id)
),
{}".format(self.get_formatted_game_object(game_id)),
)
self.pending_subject_changes.append(game_id)
return
Expand Down
12 changes: 3 additions & 9 deletions zulip_bots/zulip_bots/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ def __init__(
Have you not started the server?
Or did you mis-specify the URL?
""".format(
e
)
""".format(e)
)
sys.exit(1)

Expand All @@ -238,9 +236,7 @@ def __init__(
print(
"""
ERROR: {}
""".format(
msg
)
""".format(msg)
)
sys.exit(1)

Expand Down Expand Up @@ -338,9 +334,7 @@ def get_config_info(self, bot_name: str, optional: bool = False) -> Dict[str, st
The suggested name is {}.conf
We will proceed anyway.
""".format(
self.bot_config_file, bot_name
)
""".format(self.bot_config_file, bot_name)
)

# We expect the caller to pass in None if the user does
Expand Down
12 changes: 3 additions & 9 deletions zulip_bots/zulip_bots/simple_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,14 @@ def send_message(self, message: Dict[str, Any]) -> Dict[str, Any]:
"""
stream: {} topic: {}
{}
""".format(
message["to"], message["subject"], message["content"]
)
""".format(message["to"], message["subject"], message["content"])
)
else:
print(
"""
PM response:
{}
""".format(
message["content"]
)
""".format(message["content"])
)
# Note that message_server is only responsible for storing and assigning an
# id to the message instead of actually displaying it.
Expand Down Expand Up @@ -113,9 +109,7 @@ def update_message(self, message: Dict[str, Any]) -> None:
"""
update to message #{}:
{}
""".format(
message["message_id"], message["content"]
)
""".format(message["message_id"], message["content"])
)

def upload_file_from_path(self, file_path: str) -> Dict[str, Any]:
Expand Down

0 comments on commit a49add3

Please sign in to comment.