mirror of https://github.com/zulip/zulip.git
ruff: Fix UP032 Use f-string instead of `format` call.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
ff409342e1
commit
e932e2ce52
|
@ -36,7 +36,7 @@ current_version = version.ZULIP_VERSION
|
||||||
if is_invalid_upgrade(current_version, new_version):
|
if is_invalid_upgrade(current_version, new_version):
|
||||||
print(
|
print(
|
||||||
FAIL + "Your current version is very old. Please first upgrade to version "
|
FAIL + "Your current version is very old. Please first upgrade to version "
|
||||||
"1.4.3 and then upgrade to {}.".format(new_version) + ENDC
|
f"1.4.3 and then upgrade to {new_version}." + ENDC
|
||||||
)
|
)
|
||||||
shutil.rmtree(extract_path)
|
shutil.rmtree(extract_path)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -52,7 +52,7 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
if args.remove:
|
if args.remove:
|
||||||
remove_re = re.compile(
|
remove_re = re.compile(
|
||||||
"#<{0}>{{{{.+}}}}<{0}>(\n)?".format(args.username), re.DOTALL | re.MULTILINE
|
rf"#<{args.username}>{{{{.+}}}}<{args.username}>(\n)?", re.DOTALL | re.MULTILINE
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(authorized_keys, "r+") as f:
|
with open(authorized_keys, "r+") as f:
|
||||||
|
|
|
@ -97,8 +97,8 @@ def assert_droplet_does_not_exist(my_token: str, droplet_name: str, recreate: bo
|
||||||
if droplet.name.lower() == droplet_name:
|
if droplet.name.lower() == droplet_name:
|
||||||
if not recreate:
|
if not recreate:
|
||||||
print(
|
print(
|
||||||
"Droplet {} already exists. Pass --recreate if you "
|
f"Droplet {droplet_name} already exists. Pass --recreate if you "
|
||||||
"need to recreate the droplet.".format(droplet_name)
|
"need to recreate the droplet."
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
|
@ -251,8 +251,8 @@ def create_dns_record(my_token: str, record_name: str, ipv4: str, ipv6: str) ->
|
||||||
|
|
||||||
def print_dev_droplet_instructions(username: str, droplet_domain_name: str) -> None:
|
def print_dev_droplet_instructions(username: str, droplet_domain_name: str) -> None:
|
||||||
print(
|
print(
|
||||||
"""
|
f"""
|
||||||
COMPLETE! Droplet for GitHub user {0} is available at {1}.
|
COMPLETE! Droplet for GitHub user {username} is available at {droplet_domain_name}.
|
||||||
|
|
||||||
Instructions for use are below. (copy and paste to the user)
|
Instructions for use are below. (copy and paste to the user)
|
||||||
|
|
||||||
|
@ -260,16 +260,14 @@ Instructions for use are below. (copy and paste to the user)
|
||||||
Your remote Zulip dev server has been created!
|
Your remote Zulip dev server has been created!
|
||||||
|
|
||||||
- Connect to your server by running
|
- Connect to your server by running
|
||||||
`ssh zulipdev@{1}` on the command line
|
`ssh zulipdev@{droplet_domain_name}` on the command line
|
||||||
(Terminal for macOS and Linux, Bash for Git on Windows).
|
(Terminal for macOS and Linux, Bash for Git on Windows).
|
||||||
- There is no password; your account is configured to use your SSH keys.
|
- There is no password; your account is configured to use your SSH keys.
|
||||||
- Once you log in, you should see `(zulip-py3-venv) ~$`.
|
- Once you log in, you should see `(zulip-py3-venv) ~$`.
|
||||||
- To start the dev server, `cd zulip` and then run `./tools/run-dev`.
|
- To start the dev server, `cd zulip` and then run `./tools/run-dev`.
|
||||||
- While the dev server is running, you can see the Zulip server in your browser at
|
- While the dev server is running, you can see the Zulip server in your browser at
|
||||||
http://{1}:9991.
|
http://{droplet_domain_name}:9991.
|
||||||
""".format(
|
"""
|
||||||
username, droplet_domain_name
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
|
|
|
@ -130,8 +130,8 @@ def custom_headers(headers_json: str) -> Dict[str, str]:
|
||||||
return orjson.loads(headers_json)
|
return orjson.loads(headers_json)
|
||||||
except orjson.JSONDecodeError as ve:
|
except orjson.JSONDecodeError as ve:
|
||||||
raise argparse.ArgumentTypeError(
|
raise argparse.ArgumentTypeError(
|
||||||
"Encountered an error while attempting to parse custom headers: {}\n"
|
f"Encountered an error while attempting to parse custom headers: {ve}\n"
|
||||||
"Note: all strings must be enclosed within \"\" instead of ''".format(ve)
|
"Note: all strings must be enclosed within \"\" instead of ''"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -156,10 +156,8 @@ def send_bot_mock_message(
|
||||||
client.send_message(request)
|
client.send_message(request)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print(
|
print(
|
||||||
"{} contains invalid configuration. "
|
f"{fixture_path} contains invalid configuration. "
|
||||||
'Fields "subject" and "body" are required for non-webhook integrations.'.format(
|
'Fields "subject" and "body" are required for non-webhook integrations.'
|
||||||
fixture_path
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
@ -55,10 +55,8 @@ def set_bot_config(bot_profile: UserProfile, key: str, value: str) -> None:
|
||||||
new_config_size = old_config_size + (new_entry_size - old_entry_size)
|
new_config_size = old_config_size + (new_entry_size - old_entry_size)
|
||||||
if new_config_size > config_size_limit:
|
if new_config_size > config_size_limit:
|
||||||
raise ConfigError(
|
raise ConfigError(
|
||||||
"Cannot store configuration. Request would require {} characters. "
|
f"Cannot store configuration. Request would require {new_config_size} characters. "
|
||||||
"The current configuration size limit is {} characters.".format(
|
f"The current configuration size limit is {config_size_limit} characters."
|
||||||
new_config_size, config_size_limit
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
obj, created = BotConfigData.objects.get_or_create(
|
obj, created = BotConfigData.objects.get_or_create(
|
||||||
bot_profile=bot_profile, key=key, defaults={"value": value}
|
bot_profile=bot_profile, key=key, defaults={"value": value}
|
||||||
|
|
|
@ -11,13 +11,7 @@ def process_zcommands(content: str, user_profile: UserProfile) -> Dict[str, Any]
|
||||||
def change_mode_setting(
|
def change_mode_setting(
|
||||||
setting_name: str, switch_command: str, setting: str, setting_value: int
|
setting_name: str, switch_command: str, setting: str, setting_value: int
|
||||||
) -> str:
|
) -> str:
|
||||||
msg = (
|
msg = f"Changed to {setting_name}! To revert {setting_name}, type `/{switch_command}`."
|
||||||
"Changed to {setting_name}! To revert "
|
|
||||||
"{setting_name}, type `/{switch_command}`.".format(
|
|
||||||
setting_name=setting_name,
|
|
||||||
switch_command=switch_command,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
do_change_user_setting(
|
do_change_user_setting(
|
||||||
user_profile=user_profile,
|
user_profile=user_profile,
|
||||||
setting_name=setting,
|
setting_name=setting,
|
||||||
|
|
|
@ -56,8 +56,8 @@ approach shown above.
|
||||||
custom_headers_dict = orjson.loads(custom_headers)
|
custom_headers_dict = orjson.loads(custom_headers)
|
||||||
except orjson.JSONDecodeError as ve:
|
except orjson.JSONDecodeError as ve:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
"Encountered an error while attempting to parse custom headers: {}\n"
|
f"Encountered an error while attempting to parse custom headers: {ve}\n"
|
||||||
"Note: all strings must be enclosed within \"\" instead of ''".format(ve)
|
"Note: all strings must be enclosed within \"\" instead of ''"
|
||||||
)
|
)
|
||||||
return standardize_headers(custom_headers_dict)
|
return standardize_headers(custom_headers_dict)
|
||||||
|
|
||||||
|
|
|
@ -1719,9 +1719,9 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase, ABC):
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
self.assert_in_response('action="/register/"', result)
|
self.assert_in_response('action="/register/"', result)
|
||||||
self.assert_in_response(
|
self.assert_in_response(
|
||||||
"Your email address, {}, is not "
|
f"Your email address, {email}, is not "
|
||||||
"in one of the domains that are allowed to register "
|
"in one of the domains that are allowed to register "
|
||||||
"for accounts in this organization.".format(email),
|
"for accounts in this organization.",
|
||||||
result,
|
result,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -2543,12 +2543,12 @@ class MarkdownTest(ZulipTestCase):
|
||||||
render_markdown(msg, content).rendered_content,
|
render_markdown(msg, content).rendered_content,
|
||||||
"<p>Look to "
|
"<p>Look to "
|
||||||
'<a class="stream" '
|
'<a class="stream" '
|
||||||
'data-stream-id="{denmark.id}" '
|
f'data-stream-id="{denmark.id}" '
|
||||||
'href="/#narrow/stream/{denmark.id}-Denmark">#{denmark.name}</a> and '
|
f'href="/#narrow/stream/{denmark.id}-Denmark">#{denmark.name}</a> and '
|
||||||
'<a class="stream" '
|
'<a class="stream" '
|
||||||
'data-stream-id="{scotland.id}" '
|
f'data-stream-id="{scotland.id}" '
|
||||||
'href="/#narrow/stream/{scotland.id}-Scotland">#{scotland.name}</a>, '
|
f'href="/#narrow/stream/{scotland.id}-Scotland">#{scotland.name}</a>, '
|
||||||
"there something</p>".format(denmark=denmark, scotland=scotland),
|
"there something</p>",
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_stream_case_sensitivity(self) -> None:
|
def test_stream_case_sensitivity(self) -> None:
|
||||||
|
@ -2622,14 +2622,14 @@ class MarkdownTest(ZulipTestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
render_markdown(msg, content).rendered_content,
|
render_markdown(msg, content).rendered_content,
|
||||||
"<p>This has two links: "
|
"<p>This has two links: "
|
||||||
'<a class="stream-topic" data-stream-id="{denmark.id}" '
|
f'<a class="stream-topic" data-stream-id="{denmark.id}" '
|
||||||
'href="/#narrow/stream/{denmark.id}-{denmark.name}/topic/some.20topic">'
|
f'href="/#narrow/stream/{denmark.id}-{denmark.name}/topic/some.20topic">'
|
||||||
"#{denmark.name} > some topic</a>"
|
f"#{denmark.name} > some topic</a>"
|
||||||
" and "
|
" and "
|
||||||
'<a class="stream-topic" data-stream-id="{scotland.id}" '
|
f'<a class="stream-topic" data-stream-id="{scotland.id}" '
|
||||||
'href="/#narrow/stream/{scotland.id}-{scotland.name}/topic/other.20topic">'
|
f'href="/#narrow/stream/{scotland.id}-{scotland.name}/topic/other.20topic">'
|
||||||
"#{scotland.name} > other topic</a>"
|
f"#{scotland.name} > other topic</a>"
|
||||||
".</p>".format(denmark=denmark, scotland=scotland),
|
".</p>",
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_possible_stream_names(self) -> None:
|
def test_possible_stream_names(self) -> None:
|
||||||
|
@ -2652,10 +2652,7 @@ class MarkdownTest(ZulipTestCase):
|
||||||
href = f"/#narrow/stream/{uni.id}-{quoted_name}"
|
href = f"/#narrow/stream/{uni.id}-{quoted_name}"
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
render_markdown(msg, content).rendered_content,
|
render_markdown(msg, content).rendered_content,
|
||||||
'<p><a class="stream" data-stream-id="{s.id}" href="{href}">#{s.name}</a></p>'.format(
|
f'<p><a class="stream" data-stream-id="{uni.id}" href="{href}">#{uni.name}</a></p>',
|
||||||
s=uni,
|
|
||||||
href=href,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_stream_atomic_string(self) -> None:
|
def test_stream_atomic_string(self) -> None:
|
||||||
|
|
|
@ -1501,8 +1501,7 @@ class StreamMessagesTest(ZulipTestCase):
|
||||||
message = most_recent_message(receiving_user_profile)
|
message = most_recent_message(receiving_user_profile)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
repr(message),
|
repr(message),
|
||||||
"<Message: Denmark / my topic / "
|
f"<Message: Denmark / my topic / <UserProfile: {sender.email} {sender.realm!r}>>",
|
||||||
"<UserProfile: {} {!r}>>".format(sender.email, sender.realm),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_message_mentions(self) -> None:
|
def test_message_mentions(self) -> None:
|
||||||
|
|
|
@ -673,20 +673,16 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase):
|
||||||
self._create_attachments()
|
self._create_attachments()
|
||||||
realm_id = get_realm("zulip").id
|
realm_id = get_realm("zulip").id
|
||||||
host = get_realm("zulip").host
|
host = get_realm("zulip").host
|
||||||
body1 = """Some files here ...[zulip.txt](
|
body1 = f"""Some files here ...[zulip.txt](
|
||||||
http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt)
|
http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt)
|
||||||
http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/temp_file.py ....
|
http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/temp_file.py ....
|
||||||
Some more.... http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/abc.py
|
Some more.... http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/abc.py
|
||||||
""".format(
|
"""
|
||||||
id=realm_id, host=host
|
body2 = f"""Some files here
|
||||||
)
|
http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt ...
|
||||||
body2 = """Some files here
|
http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/hello.txt ....
|
||||||
http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/zulip.txt ...
|
http://{host}/user_uploads/{realm_id}/31/4CBjtTLYZhk66pZrF8hnYGwc/new.py ....
|
||||||
http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/hello.txt ....
|
"""
|
||||||
http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/new.py ....
|
|
||||||
""".format(
|
|
||||||
id=realm_id, host=host
|
|
||||||
)
|
|
||||||
|
|
||||||
msg_ids = [
|
msg_ids = [
|
||||||
self.send_personal_message(self.sender, self.recipient, body1),
|
self.send_personal_message(self.sender, self.recipient, body1),
|
||||||
|
|
|
@ -342,7 +342,7 @@ class AddNewUserHistoryTest(ZulipTestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
repr(message),
|
repr(message),
|
||||||
"<Message: recip / / "
|
"<Message: recip / / "
|
||||||
"<UserProfile: {} {!r}>>".format(user_profile.email, user_profile.realm),
|
f"<UserProfile: {user_profile.email} {user_profile.realm!r}>>",
|
||||||
)
|
)
|
||||||
|
|
||||||
user_message = most_recent_usermessage(user_profile)
|
user_message = most_recent_usermessage(user_profile)
|
||||||
|
|
|
@ -598,7 +598,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
|
||||||
self.subscribe(hamlet, "test")
|
self.subscribe(hamlet, "test")
|
||||||
body = (
|
body = (
|
||||||
f"[f1.txt](http://{host}/user_uploads/" + f1_path_id + ") "
|
f"[f1.txt](http://{host}/user_uploads/" + f1_path_id + ") "
|
||||||
"[f2.txt](http://{}/user_uploads/".format(host) + f2_path_id + ")"
|
f"[f2.txt](http://{host}/user_uploads/" + f2_path_id + ")"
|
||||||
)
|
)
|
||||||
msg_id = self.send_stream_message(hamlet, "test", body, "test")
|
msg_id = self.send_stream_message(hamlet, "test", body, "test")
|
||||||
|
|
||||||
|
@ -608,7 +608,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
|
||||||
|
|
||||||
new_body = (
|
new_body = (
|
||||||
f"[f3.txt](http://{host}/user_uploads/" + f3_path_id + ") "
|
f"[f3.txt](http://{host}/user_uploads/" + f3_path_id + ") "
|
||||||
"[f2.txt](http://{}/user_uploads/".format(host) + f2_path_id + ")"
|
f"[f2.txt](http://{host}/user_uploads/" + f2_path_id + ")"
|
||||||
)
|
)
|
||||||
result = self.client_patch(
|
result = self.client_patch(
|
||||||
"/json/messages/" + str(msg_id),
|
"/json/messages/" + str(msg_id),
|
||||||
|
|
|
@ -41,20 +41,16 @@ def get_target_name(payload: WildValue) -> str:
|
||||||
def get_inbound_message_body(payload: WildValue) -> str:
|
def get_inbound_message_body(payload: WildValue) -> str:
|
||||||
link, outbox, inbox, subject = get_message_data(payload)
|
link, outbox, inbox, subject = get_message_data(payload)
|
||||||
return (
|
return (
|
||||||
"[Inbound message]({link}) from **{outbox}** to **{inbox}**:\n"
|
f"[Inbound message]({link}) from **{outbox}** to **{inbox}**:\n"
|
||||||
"```quote\n*Subject*: {subject}\n```".format(
|
f"```quote\n*Subject*: {subject}\n```"
|
||||||
link=link, outbox=outbox, inbox=inbox, subject=subject
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_outbound_message_body(payload: WildValue) -> str:
|
def get_outbound_message_body(payload: WildValue) -> str:
|
||||||
link, outbox, inbox, subject = get_message_data(payload)
|
link, outbox, inbox, subject = get_message_data(payload)
|
||||||
return (
|
return (
|
||||||
"[Outbound message]({link}) from **{inbox}** to **{outbox}**:\n"
|
f"[Outbound message]({link}) from **{inbox}** to **{outbox}**:\n"
|
||||||
"```quote\n*Subject*: {subject}\n```".format(
|
f"```quote\n*Subject*: {subject}\n```"
|
||||||
link=link, inbox=inbox, outbox=outbox, subject=subject
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue