lint: Replace Black with Ruff.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
2a0eff653d
commit
a49add3d02
15 changed files with 31 additions and 64 deletions
|
@ -110,4 +110,5 @@ src = [
|
|||
"zulip_bots",
|
||||
"zulip_botserver",
|
||||
]
|
||||
target-version = "py38"
|
||||
line-length = 100
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
crayons
|
||||
twine
|
||||
black~=23.10.1
|
||||
mock
|
||||
pytest
|
||||
pytest-cov
|
||||
|
|
|
@ -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()
|
||||
|
|
15
tools/lint
15
tools/lint
|
@ -1,7 +1,6 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import sys
|
||||
|
||||
from zulint.command import LinterConfig, add_default_linter_arguments
|
||||
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -301,9 +301,7 @@ if __name__ == "__main__":
|
|||
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",
|
||||
|
@ -314,9 +312,7 @@ as normal.""".replace(
|
|||
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",
|
||||
|
@ -327,9 +323,7 @@ from JIDs and nicks before sending requests to the Zulip server, and remove the
|
|||
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 "qux+foo@example.com". This
|
||||
option does not affect login credentials.""".replace(
|
||||
"\n", " "
|
||||
),
|
||||
option does not affect login credentials.""".replace("\n", " "),
|
||||
)
|
||||
parser.add_option(
|
||||
"-d",
|
||||
|
|
|
@ -84,9 +84,7 @@ message = """**{user}** committed revision @{change} to `{path}`.
|
|||
```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",
|
||||
|
|
|
@ -41,8 +41,9 @@ Zulip API configuration:
|
|||
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
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -79,9 +79,7 @@ right now.\nPlease try again later",
|
|||
{"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:
|
||||
|
|
|
@ -54,8 +54,7 @@ class ChessHandler:
|
|||
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"):
|
||||
|
|
|
@ -46,9 +46,7 @@ class TestIDoneThisBot(BotTestCase, DefaultTests):
|
|||
{"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? "
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -116,9 +116,7 @@ class GameAdapter:
|
|||
`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()
|
||||
|
@ -644,9 +642,7 @@ class GameAdapter:
|
|||
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
|
||||
|
|
|
@ -227,9 +227,7 @@ class ExternalBotHandler:
|
|||
|
||||
Have you not started the server?
|
||||
Or did you mis-specify the URL?
|
||||
""".format(
|
||||
e
|
||||
)
|
||||
""".format(e)
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -238,9 +236,7 @@ class ExternalBotHandler:
|
|||
print(
|
||||
"""
|
||||
ERROR: {}
|
||||
""".format(
|
||||
msg
|
||||
)
|
||||
""".format(msg)
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -338,9 +334,7 @@ class ExternalBotHandler:
|
|||
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
|
||||
|
|
|
@ -74,18 +74,14 @@ class TerminalBotHandler:
|
|||
"""
|
||||
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.
|
||||
|
@ -113,9 +109,7 @@ class TerminalBotHandler:
|
|||
"""
|
||||
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]:
|
||||
|
|
Loading…
Add table
Reference in a new issue