From e747bd81325c0dea10d93ad4e7db0cfe980fa295 Mon Sep 17 00:00:00 2001 From: Tristan Jahnke Date: Wed, 4 Oct 2023 03:32:15 -0500 Subject: [PATCH] scripts/*.py: update coding style (#10761) * convert to f string * use a next function instead of a for-loop * remove uneeded else statement * use in operator instead of multi comparison * conver to f string * adds extra line between function defs * revert/change to PR comment around looping * remove uneeded loops * revert to keep old style choice --- scripts/pdf/render.py | 2 +- scripts/send-to-bot.py | 2 +- scripts/set-alias-page.py | 7 +++---- scripts/set-more-info-link.py | 13 ++++++------- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/scripts/pdf/render.py b/scripts/pdf/render.py index e23fbbfec..a639acfe8 100644 --- a/scripts/pdf/render.py +++ b/scripts/pdf/render.py @@ -26,7 +26,7 @@ def main(loc, colorscheme): # Set up css style sheets csslist = ["basic.css"] if colorscheme != "basic": - csslist.append(colorscheme + ".css") + csslist.append(f"{colorscheme}.css") # A string that stores all pages in HTML format html = ( diff --git a/scripts/send-to-bot.py b/scripts/send-to-bot.py index 6040cf05a..a99b40f76 100755 --- a/scripts/send-to-bot.py +++ b/scripts/send-to-bot.py @@ -29,7 +29,7 @@ Is this intended? If so, just ignore this comment. Otherwise, please double-chec def post_comment(pr_id, body, once): - endpoint = BOT_URL + "/comment" + endpoint = f"{BOT_URL}/comment" if once: endpoint += "/once" diff --git a/scripts/set-alias-page.py b/scripts/set-alias-page.py index 2fa21991e..e0bf453f9 100644 --- a/scripts/set-alias-page.py +++ b/scripts/set-alias-page.py @@ -99,10 +99,9 @@ def get_alias_page(file): if not os.path.isfile(file): return "" with open(file) as f: - lines = f.readlines() - for line in lines: - if re.search(r"^`tldr ", line): - return re.search("`tldr (.+)`", line).group(1) + for line in f: + if match := re.search(r"^`tldr (.+)`", line): + return match[1] return "" diff --git a/scripts/set-more-info-link.py b/scripts/set-more-info-link.py index 8963ac13b..3d0079a18 100755 --- a/scripts/set-more-info-link.py +++ b/scripts/set-more-info-link.py @@ -56,11 +56,10 @@ def get_tldr_root(): if "TLDR_ROOT" in os.environ: return os.environ["TLDR_ROOT"] - else: - print( - "\x1b[31mPlease set TLDR_ROOT to the location of a clone of https://github.com/tldr-pages/tldr." - ) - sys.exit(1) + print( + "\x1b[31mPlease set TLDR_ROOT to the location of a clone of https://github.com/tldr-pages/tldr." + ) + sys.exit(1) def set_link(file, link): @@ -88,9 +87,9 @@ def set_link(file, link): # build new line if locale == "hi": new_line = f"> {labels[locale]} <{link}>ред\n" - elif locale == "ja" or locale == "th": + elif locale in ["ja", "th"]: new_line = f"> {labels[locale]} <{link}>\n" - elif locale == "zh" or locale == "zh_TW": + elif locale in ["zh", "zh_TW"]: new_line = f"> {labels[locale]}<{link}>.\n" else: new_line = f"> {labels[locale]} <{link}>.\n"