diff --git a/tools/lib/test_script.py b/tools/lib/test_script.py index 5c7780262b..68d241ebf8 100644 --- a/tools/lib/test_script.py +++ b/tools/lib/test_script.py @@ -20,12 +20,12 @@ def get_version_file() -> str: PREAMBLE = ''' Before we run tests, we make sure your provisioning version is correct by looking at var/provision_version, which is at -version %s, and we compare it to the version in source -control (version.py), which is %s. +version {}, and we compare it to the version in source +control (version.py), which is {}. ''' def preamble(version: str) -> str: - text = PREAMBLE % (version, PROVISION_VERSION) + text = PREAMBLE.format(version, PROVISION_VERSION) text += '\n' return text diff --git a/tools/setup/emoji/build_emoji b/tools/setup/emoji/build_emoji index c7dbd693c2..d942a0e8e7 100755 --- a/tools/setup/emoji/build_emoji +++ b/tools/setup/emoji/build_emoji @@ -47,32 +47,32 @@ NODE_MODULES_PATH = os.path.join(ZULIP_PATH, 'node_modules') SPRITE_CSS_FILE_TEMPLATE = """\ div.emoji, span.emoji -{ +{{ display: inline-block; - background-image: url(~emoji-datasource-%(emojiset)s/img/%(alt_name)s/sheets-256/64.png); - background-size: %(background_size)s; + background-image: url(~emoji-datasource-{emojiset}/img/{alt_name}/sheets-256/64.png); + background-size: {background_size}; background-repeat: no-repeat; /* Hide the text. */ - text-indent: 100%%; + text-indent: 100%; white-space: nowrap; overflow: hidden; -} +}} .emoji-1f419 -{ +{{ background-image: url(../emoji/images-google-64/1f419.png) !important; - background-position: 0%% 0%% !important; + background-position: 0% 0% !important; background-size: contain !important; -} +}} -%(emoji_positions)s +{emoji_positions} """ EMOJI_POS_INFO_TEMPLATE = """\ -.emoji-%(codepoint)s { - background-position: %(pos_x)s %(pos_y)s; -} +.emoji-{codepoint} {{ + background-position: {pos_x} {pos_y}; +}} """ # change directory @@ -207,19 +207,22 @@ def generate_sprite_css_files(cache_path: str, will get more complicated. """ - emoji_positions += EMOJI_POS_INFO_TEMPLATE % { - 'codepoint': get_emoji_code(emoji), - 'pos_x': percent(emoji["sheet_x"] / (n - 1)), - 'pos_y': percent(emoji["sheet_y"] / (n - 1)), - } + emoji_positions += EMOJI_POS_INFO_TEMPLATE.format( + codepoint=get_emoji_code(emoji), + pos_x=percent(emoji["sheet_x"] / (n - 1)), + pos_y=percent(emoji["sheet_y"] / (n - 1)), + ) SPRITE_CSS_PATH = os.path.join(cache_path, f'{emojiset}-sprite.css') with open(SPRITE_CSS_PATH, 'w') as f: - f.write(SPRITE_CSS_FILE_TEMPLATE % {'emojiset': emojiset, - 'alt_name': alt_name, - 'emoji_positions': emoji_positions, - 'background_size': background_size, - }) + f.write( + SPRITE_CSS_FILE_TEMPLATE.format( + emojiset=emojiset, + alt_name=alt_name, + emoji_positions=emoji_positions, + background_size=background_size, + ), + ) def setup_emoji_farms(cache_path: str, emoji_data: List[Dict[str, Any]]) -> None: def ensure_emoji_image(emoji_dict: Dict[str, Any], diff --git a/tools/setup/emoji/generate_emoji_names_table b/tools/setup/emoji/generate_emoji_names_table index 90a5ba1e11..63ed0445a5 100755 --- a/tools/setup/emoji/generate_emoji_names_table +++ b/tools/setup/emoji/generate_emoji_names_table @@ -29,18 +29,18 @@ with open(EMOJI_MAP_FILE) as fp: EMOJI_MAP = ujson.load(fp) EMOJI_IMAGE_TEMPLATE = """ - + """ TABLE_ROW_TEMPLATE = """ - %(sorting_info)s - %(emoji_code)s - %(images_html)s - %(zulip_names)s - %(iamcal_names)s - %(gemoji_names)s - %(unicode_name)s + {sorting_info} + {emoji_code} + {images_html} + {zulip_names} + {iamcal_names} + {gemoji_names} + {unicode_name} """ @@ -48,7 +48,7 @@ EMOJI_LISTING_TEMPLATE = """ Zulip emoji names @@ -66,7 +66,7 @@ EMOJI_LISTING_TEMPLATE = """ - %(tbody)s + {tbody} @@ -156,10 +156,10 @@ def get_sorting_info(category: str, sort_order: int) -> str: def get_images_html(emoji_code: str) -> str: images_html = '' for emojiset in EMOJISETS: - images_html += (EMOJI_IMAGE_TEMPLATE % { - 'emoji_code': emoji_code, - 'emojiset': emojiset, - }) + images_html += EMOJI_IMAGE_TEMPLATE.format( + emoji_code=emoji_code, + emojiset=emojiset, + ) return images_html @@ -194,14 +194,13 @@ def main() -> None: tbody = "" for category in SORTED_CATEGORIES: for emoji_entry in emoji_collection[category]: - # We need to use the weird `dict(**kwargs)` format to avoid lint errors. - tbody += TABLE_ROW_TEMPLATE % dict(**emoji_entry) + tbody += TABLE_ROW_TEMPLATE.format(**emoji_entry) with open(OUTPUT_FILE, 'w') as fp: - fp.write(EMOJI_LISTING_TEMPLATE % { - 'tbody': tbody, - 'table_css': TABLE_CSS, - }) + fp.write(EMOJI_LISTING_TEMPLATE.format( + tbody=tbody, + table_css=TABLE_CSS, + )) print("Done! Open http://localhost:9991/static/generated/emoji/emoji_names_table.html " "to view(after starting the dev server).") diff --git a/zerver/lib/markdown/fenced_code.py b/zerver/lib/markdown/fenced_code.py index 8ffdcea36d..21826a6073 100644 --- a/zerver/lib/markdown/fenced_code.py +++ b/zerver/lib/markdown/fenced_code.py @@ -113,8 +113,8 @@ FENCE_RE = re.compile(""" """, re.VERBOSE) -CODE_WRAP = '
%s\n
' -LANG_TAG = ' class="%s"' +CODE_WRAP = '
{}\n
' +LANG_TAG = ' class="{}"' def validate_curl_content(lines: List[str]) -> None: error_msg = """ @@ -363,7 +363,7 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor): def format_code(self, lang: str, text: str) -> str: if lang: - langclass = LANG_TAG % (lang,) + langclass = LANG_TAG.format(lang) else: langclass = '' @@ -390,7 +390,7 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor): code = highliter.hilite() else: - code = CODE_WRAP % (langclass, self._escape(text)) + code = CODE_WRAP.format(langclass, self._escape(text)) return code diff --git a/zerver/lib/markdown/help_relative_links.py b/zerver/lib/markdown/help_relative_links.py index 1f086b7cab..e893721147 100644 --- a/zerver/lib/markdown/help_relative_links.py +++ b/zerver/lib/markdown/help_relative_links.py @@ -30,7 +30,7 @@ gear_instructions = """ 1. From your desktop, click on the **gear** () in the upper right corner. -1. Select %(item)s. +1. Select {item}. """ def gear_handle_match(key: str) -> str: @@ -38,7 +38,7 @@ def gear_handle_match(key: str) -> str: item = f'[{gear_info[key][0]}]({gear_info[key][1]})' else: item = f'**{gear_info[key][0]}**' - return gear_instructions % {'item': item} + return gear_instructions.format(item=item) stream_info = { diff --git a/zerver/lib/markdown/help_settings_links.py b/zerver/lib/markdown/help_settings_links.py index f60cccb116..b08404c8de 100644 --- a/zerver/lib/markdown/help_settings_links.py +++ b/zerver/lib/markdown/help_settings_links.py @@ -56,9 +56,9 @@ settings_markdown = """ 1. From your desktop, click on the **gear** () in the upper right corner. -1. Select **%(setting_type_name)s**. +1. Select **{setting_type_name}**. -1. On the left, click %(setting_reference)s. +1. On the left, click {setting_reference}. """ @@ -105,8 +105,10 @@ class Setting(Preprocessor): setting_link = link_mapping[setting_identifier][2] if relative_settings_links: return f"1. Go to [{setting_name}]({setting_link})." - return settings_markdown % {'setting_type_name': setting_type_name, - 'setting_reference': f"**{setting_name}**"} + return settings_markdown.format( + setting_type_name=setting_type_name, + setting_reference=f"**{setting_name}**", + ) def makeExtension(*args: Any, **kwargs: Any) -> SettingHelpExtension: return SettingHelpExtension(*args, **kwargs)