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_bots",
|
||||||
"zulip_botserver",
|
"zulip_botserver",
|
||||||
]
|
]
|
||||||
|
target-version = "py38"
|
||||||
line-length = 100
|
line-length = 100
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
crayons
|
crayons
|
||||||
twine
|
twine
|
||||||
black~=23.10.1
|
|
||||||
mock
|
mock
|
||||||
pytest
|
pytest
|
||||||
pytest-cov
|
pytest-cov
|
||||||
|
|
|
@ -59,9 +59,7 @@ def pack(options: argparse.Namespace) -> None:
|
||||||
[deploy]
|
[deploy]
|
||||||
bot={}
|
bot={}
|
||||||
zuliprc=zuliprc
|
zuliprc=zuliprc
|
||||||
""".format(
|
""".format(options.main)
|
||||||
options.main
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
zip_file.writestr("config.ini", bot_config)
|
zip_file.writestr("config.ini", bot_config)
|
||||||
zip_file.close()
|
zip_file.close()
|
||||||
|
|
15
tools/lint
15
tools/lint
|
@ -1,7 +1,6 @@
|
||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import re
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from zulint.command import LinterConfig, add_default_linter_arguments
|
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"
|
"ruff", ["ruff", "check", "--quiet"], ["py"], fix_arg="--fix", description="Python linter"
|
||||||
)
|
)
|
||||||
linter_config.external_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(
|
linter_config.external_linter(
|
||||||
"black",
|
"gitlint", ["tools/lint-commits"], description="Git Lint for commit messages"
|
||||||
["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,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@linter_config.lint
|
@linter_config.lint
|
||||||
|
|
|
@ -45,8 +45,10 @@ the Python version this command is executed with."""
|
||||||
|
|
||||||
if py_version <= (3, 1) and (not options.force):
|
if py_version <= (3, 1) and (not options.force):
|
||||||
print(
|
print(
|
||||||
red + "Provision failed: Cannot create venv with outdated Python version ({}).\n"
|
red
|
||||||
"Maybe try `python3 tools/provision`.".format(py_version_output.strip()) + end_format
|
+ "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)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
@ -301,9 +301,7 @@ if __name__ == "__main__":
|
||||||
zulip configuration file under the jabber_mirror section (exceptions are noted
|
zulip configuration file under the jabber_mirror section (exceptions are noted
|
||||||
in their help sections). Keys have the same name as options with hyphens
|
in their help sections). Keys have the same name as options with hyphens
|
||||||
replaced with underscores. Zulip configuration options go in the api section,
|
replaced with underscores. Zulip configuration options go in the api section,
|
||||||
as normal.""".replace(
|
as normal.""".replace("\n", " ")
|
||||||
"\n", " "
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
"--mode",
|
"--mode",
|
||||||
|
@ -314,9 +312,7 @@ as normal.""".replace(
|
||||||
all messages they send on Zulip to Jabber and all private Jabber messages to
|
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
|
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
|
user and mirrors messages sent to Jabber rooms to Zulip. Defaults to
|
||||||
"personal"'''.replace(
|
"personal"'''.replace("\n", " "),
|
||||||
"\n", " "
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
"--zulip-email-suffix",
|
"--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
|
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
|
"+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
|
be mirrored to the "bar/xmpp" stream in Zulip by user "qux+foo@example.com". This
|
||||||
option does not affect login credentials.""".replace(
|
option does not affect login credentials.""".replace("\n", " "),
|
||||||
"\n", " "
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
"-d",
|
"-d",
|
||||||
|
|
|
@ -84,9 +84,7 @@ message = """**{user}** committed revision @{change} to `{path}`.
|
||||||
```quote
|
```quote
|
||||||
{desc}
|
{desc}
|
||||||
```
|
```
|
||||||
""".format(
|
""".format(user=metadata["user"], change=change, path=changeroot, desc=metadata["desc"])
|
||||||
user=metadata["user"], change=change, path=changeroot, desc=metadata["desc"]
|
|
||||||
)
|
|
||||||
|
|
||||||
message_data: Dict[str, Any] = {
|
message_data: Dict[str, Any] = {
|
||||||
"type": "stream",
|
"type": "stream",
|
||||||
|
|
|
@ -41,8 +41,9 @@ Zulip API configuration:
|
||||||
expanded_test_path = os.path.abspath(os.path.expanduser(test_path))
|
expanded_test_path = os.path.abspath(os.path.expanduser(test_path))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
str(cm.exception),
|
str(cm.exception),
|
||||||
"api_key or email not specified and "
|
"api_key or email not specified and " "file {} does not exist".format(
|
||||||
"file {} does not exist".format(expanded_test_path),
|
expanded_test_path
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -79,9 +79,7 @@ right now.\nPlease try again later",
|
||||||
{"auth_token": "someInvalidKey", "username": "aaron", "goalname": "goal"}
|
{"auth_token": "someInvalidKey", "username": "aaron", "goalname": "goal"}
|
||||||
), patch("requests.get", side_effect=ConnectionError()), self.mock_http_conversation(
|
), patch("requests.get", side_effect=ConnectionError()), self.mock_http_conversation(
|
||||||
"test_invalid_when_handle_message"
|
"test_invalid_when_handle_message"
|
||||||
), patch(
|
), patch("logging.exception"):
|
||||||
"logging.exception"
|
|
||||||
):
|
|
||||||
self.verify_reply("5", "Error. Check your key!")
|
self.verify_reply("5", "Error. Check your key!")
|
||||||
|
|
||||||
def test_error(self) -> None:
|
def test_error(self) -> None:
|
||||||
|
|
|
@ -54,8 +54,7 @@ class ChessHandler:
|
||||||
if bot_handler.storage.contains("is_with_computer"):
|
if bot_handler.storage.contains("is_with_computer"):
|
||||||
is_with_computer = (
|
is_with_computer = (
|
||||||
# `bot_handler`'s `storage` only accepts `str` values.
|
# `bot_handler`'s `storage` only accepts `str` values.
|
||||||
bot_handler.storage.get("is_with_computer")
|
bot_handler.storage.get("is_with_computer") == str(True)
|
||||||
== str(True)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if bot_handler.storage.contains("last_fen"):
|
if bot_handler.storage.contains("last_fen"):
|
||||||
|
|
|
@ -46,9 +46,7 @@ class TestIDoneThisBot(BotTestCase, DefaultTests):
|
||||||
{"api_key": "87654321", "default_team": "testing team 1"}
|
{"api_key": "87654321", "default_team": "testing team 1"}
|
||||||
), self.mock_http_conversation("test_401"), patch(
|
), self.mock_http_conversation("test_401"), patch(
|
||||||
"zulip_bots.bots.idonethis.idonethis.api_noop"
|
"zulip_bots.bots.idonethis.idonethis.api_noop"
|
||||||
), patch(
|
), patch("logging.error"):
|
||||||
"logging.error"
|
|
||||||
):
|
|
||||||
self.verify_reply(
|
self.verify_reply(
|
||||||
"list teams",
|
"list teams",
|
||||||
"I can't currently authenticate with idonethis. Can you check that your API key is correct? "
|
"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 += interface.graph_grid(data.grid()) + "\n"
|
||||||
response += """Phase {}. Take mode: {}.
|
response += """Phase {}. Take mode: {}.
|
||||||
X taken: {}, O taken: {}.
|
X taken: {}, O taken: {}.
|
||||||
""".format(
|
""".format(data.get_phase(), take, data.x_taken, data.o_taken)
|
||||||
data.get_phase(), take, data.x_taken, data.o_taken
|
|
||||||
)
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
@ -116,9 +116,7 @@ class GameAdapter:
|
||||||
`quit`
|
`quit`
|
||||||
* To see rules of this game, type
|
* To see rules of this game, type
|
||||||
`rules`
|
`rules`
|
||||||
{}""".format(
|
{}""".format(self.game_name, self.get_bot_username(), self.move_help_message)
|
||||||
self.game_name, self.get_bot_username(), self.move_help_message
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_commands(self) -> Dict[str, str]:
|
def get_commands(self) -> Dict[str, str]:
|
||||||
action = self.help_message_single_player()
|
action = self.help_message_single_player()
|
||||||
|
@ -644,9 +642,7 @@ class GameAdapter:
|
||||||
message,
|
message,
|
||||||
"Your current game is not in this subject. \n\
|
"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\
|
To move subjects, send your message again, otherwise join the game using the link below.\n\n\
|
||||||
{}".format(
|
{}".format(self.get_formatted_game_object(game_id)),
|
||||||
self.get_formatted_game_object(game_id)
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
self.pending_subject_changes.append(game_id)
|
self.pending_subject_changes.append(game_id)
|
||||||
return
|
return
|
||||||
|
|
|
@ -227,9 +227,7 @@ class ExternalBotHandler:
|
||||||
|
|
||||||
Have you not started the server?
|
Have you not started the server?
|
||||||
Or did you mis-specify the URL?
|
Or did you mis-specify the URL?
|
||||||
""".format(
|
""".format(e)
|
||||||
e
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -238,9 +236,7 @@ class ExternalBotHandler:
|
||||||
print(
|
print(
|
||||||
"""
|
"""
|
||||||
ERROR: {}
|
ERROR: {}
|
||||||
""".format(
|
""".format(msg)
|
||||||
msg
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -338,9 +334,7 @@ class ExternalBotHandler:
|
||||||
The suggested name is {}.conf
|
The suggested name is {}.conf
|
||||||
|
|
||||||
We will proceed anyway.
|
We will proceed anyway.
|
||||||
""".format(
|
""".format(self.bot_config_file, bot_name)
|
||||||
self.bot_config_file, bot_name
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# We expect the caller to pass in None if the user does
|
# We expect the caller to pass in None if the user does
|
||||||
|
|
|
@ -74,18 +74,14 @@ class TerminalBotHandler:
|
||||||
"""
|
"""
|
||||||
stream: {} topic: {}
|
stream: {} topic: {}
|
||||||
{}
|
{}
|
||||||
""".format(
|
""".format(message["to"], message["subject"], message["content"])
|
||||||
message["to"], message["subject"], message["content"]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print(
|
print(
|
||||||
"""
|
"""
|
||||||
PM response:
|
PM response:
|
||||||
{}
|
{}
|
||||||
""".format(
|
""".format(message["content"])
|
||||||
message["content"]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
# Note that message_server is only responsible for storing and assigning an
|
# Note that message_server is only responsible for storing and assigning an
|
||||||
# id to the message instead of actually displaying it.
|
# id to the message instead of actually displaying it.
|
||||||
|
@ -113,9 +109,7 @@ class TerminalBotHandler:
|
||||||
"""
|
"""
|
||||||
update to message #{}:
|
update to message #{}:
|
||||||
{}
|
{}
|
||||||
""".format(
|
""".format(message["message_id"], message["content"])
|
||||||
message["message_id"], message["content"]
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def upload_file_from_path(self, file_path: str) -> Dict[str, Any]:
|
def upload_file_from_path(self, file_path: str) -> Dict[str, Any]:
|
||||||
|
|
Loading…
Add table
Reference in a new issue