From 40761fd382069fbbca02dab905b476a8b0e0545e Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Mon, 23 Sep 2024 19:29:44 +0100 Subject: [PATCH 1/4] Add the check-times script Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- check_times.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 check_times.py diff --git a/check_times.py b/check_times.py new file mode 100644 index 0000000..c365c4f --- /dev/null +++ b/check_times.py @@ -0,0 +1,91 @@ +"""Check the frequency of the rebuild loop. + +This must be run in a directory that has the ``docsbuild.log.*`` files. +For example: + +.. code-block:: bash + + $ cd docsbuild-logs + $ scp "adam@docs.nyc1.psf.io:/var/log/docsbuild/docsbuild.log*" . + $ python ../check_times.py +""" + +import datetime as dt +import gzip +from pathlib import Path + + +def get_lines() -> list[str]: + lines = [] + zipped_logs = list(Path.cwd().glob("docsbuild.log.*.gz")) + zipped_logs.sort(key=lambda p: int(p.name.split('.')[-2]), reverse=True) + for logfile in zipped_logs: + with gzip.open(logfile, "rt", encoding="utf-8") as f: + lines += f.readlines() + with open("docsbuild.log", encoding="utf-8") as f: + lines += f.readlines() + return lines + + +def calc_time(lines: list[str]) -> None: + start = end = language = version = start_timestamp = None + reason = lang_ver = '' + + print("Start | Version | Language | Build | Reason") + print(":-- | :--: | :--: | --: | :--:") + + for line in lines: + line = line.strip() + + if ': Should rebuild: ' in line: + if 'no previous state found' in line: + reason = 'brand new' + elif 'new translations' in line: + reason = 'translation' + elif 'Doc/ has changed' in line: + reason = 'docs' + else: + reason = '' + lang_ver = line.split(" ")[3].removesuffix(":") + + if line.endswith("Build start."): + timestamp = line[:23].replace(",", ".") + language, version = line.split(" ")[3].removesuffix(":").split("/") + start = dt.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S.%f") + start_timestamp = f"{line[:16]} GMT" + + if start and ": Build done " in line: + timestamp = line[:23].replace(",", ".") + language, version = line.split(" ")[3].removesuffix(":").split("/") + end = dt.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S.%f") + + if start and end: + duration = (end - start).total_seconds() + fmt_duration = format_seconds(duration) + if lang_ver != f'{language}/{version}': + reason = '' + if True or language == "en": + print(f"{start_timestamp: <20} | {version: <7} | {language: <8} | {fmt_duration :<14} | {reason}") + start = end = start_timestamp = None + + if ': Full build done' in line: + timestamp = f"{line[:16]} GMT" + _, fmt_duration = line.removesuffix(").").split("(") + print(f"{timestamp: <20} | --FULL- | -BUILD-- | {fmt_duration :<14} | -----------") + + if start and end is None: + if True or language == "en": + print(f"{start_timestamp: <20} | {version: <7} | {language: <8} | In progress... | {reason}") + + +def format_seconds(seconds: float) -> str: + hours, minutes = divmod(seconds, 3600) + minutes, _ = divmod(minutes, 60) + hours, minutes = int(hours), int(minutes) + if hours == 0: + return f"{minutes}m" + return f"{hours}h {minutes}m" + + +if __name__ == "__main__": + calc_time(get_lines()) From 1649490b8bdbb9e539fd377104383d25911c3311 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Mon, 23 Sep 2024 19:36:05 +0100 Subject: [PATCH 2/4] Remove outdated tests --- check_times.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/check_times.py b/check_times.py index c365c4f..48a04b6 100644 --- a/check_times.py +++ b/check_times.py @@ -64,8 +64,7 @@ def calc_time(lines: list[str]) -> None: fmt_duration = format_seconds(duration) if lang_ver != f'{language}/{version}': reason = '' - if True or language == "en": - print(f"{start_timestamp: <20} | {version: <7} | {language: <8} | {fmt_duration :<14} | {reason}") + print(f"{start_timestamp: <20} | {version: <7} | {language: <8} | {fmt_duration :<14} | {reason}") start = end = start_timestamp = None if ': Full build done' in line: @@ -74,8 +73,7 @@ def calc_time(lines: list[str]) -> None: print(f"{timestamp: <20} | --FULL- | -BUILD-- | {fmt_duration :<14} | -----------") if start and end is None: - if True or language == "en": - print(f"{start_timestamp: <20} | {version: <7} | {language: <8} | In progress... | {reason}") + print(f"{start_timestamp: <20} | {version: <7} | {language: <8} | In progress... | {reason}") def format_seconds(seconds: float) -> str: From 245637d0ac551e55b28107aa4787a06cfcee1cb5 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Mon, 23 Sep 2024 20:37:21 +0100 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- check_times.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/check_times.py b/check_times.py index 48a04b6..b7dbec8 100644 --- a/check_times.py +++ b/check_times.py @@ -1,19 +1,19 @@ """Check the frequency of the rebuild loop. -This must be run in a directory that has the ``docsbuild.log.*`` files. +This must be run in a directory that has the ``docsbuild.log*`` files. For example: .. code-block:: bash - $ cd docsbuild-logs - $ scp "adam@docs.nyc1.psf.io:/var/log/docsbuild/docsbuild.log*" . - $ python ../check_times.py + $ scp "adam@docs.nyc1.psf.io:/var/log/docsbuild/docsbuild.log*" docsbuild-logs + $ python check_times.py """ import datetime as dt import gzip from pathlib import Path +from build_docs import format_seconds def get_lines() -> list[str]: lines = [] @@ -31,7 +31,7 @@ def calc_time(lines: list[str]) -> None: start = end = language = version = start_timestamp = None reason = lang_ver = '' - print("Start | Version | Language | Build | Reason") + print("Start | Version | Language | Build | Trigger") print(":-- | :--: | :--: | --: | :--:") for line in lines: @@ -52,7 +52,7 @@ def calc_time(lines: list[str]) -> None: timestamp = line[:23].replace(",", ".") language, version = line.split(" ")[3].removesuffix(":").split("/") start = dt.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S.%f") - start_timestamp = f"{line[:16]} GMT" + start_timestamp = f"{line[:16]} UTC" if start and ": Build done " in line: timestamp = line[:23].replace(",", ".") @@ -68,7 +68,7 @@ def calc_time(lines: list[str]) -> None: start = end = start_timestamp = None if ': Full build done' in line: - timestamp = f"{line[:16]} GMT" + timestamp = f"{line[:16]} UTC" _, fmt_duration = line.removesuffix(").").split("(") print(f"{timestamp: <20} | --FULL- | -BUILD-- | {fmt_duration :<14} | -----------") @@ -76,14 +76,6 @@ def calc_time(lines: list[str]) -> None: print(f"{start_timestamp: <20} | {version: <7} | {language: <8} | In progress... | {reason}") -def format_seconds(seconds: float) -> str: - hours, minutes = divmod(seconds, 3600) - minutes, _ = divmod(minutes, 60) - hours, minutes = int(hours), int(minutes) - if hours == 0: - return f"{minutes}m" - return f"{hours}h {minutes}m" - if __name__ == "__main__": calc_time(get_lines()) From 3de813e3414571b8072e957dea7d2650d47e49b5 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Mon, 23 Sep 2024 20:39:42 +0100 Subject: [PATCH 4/4] Format --- .pre-commit-config.yaml | 5 +++++ build_docs.py | 2 +- check_times.py | 42 +++++++++++++++++++++++------------------ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dba593f..c3d2f5f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,6 +13,11 @@ repos: - id: requirements-txt-fixer - id: trailing-whitespace + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.7 + hooks: + - id: ruff-format + - repo: https://github.com/python-jsonschema/check-jsonschema rev: 0.29.2 hooks: diff --git a/build_docs.py b/build_docs.py index a3971a5..07d5c6c 100755 --- a/build_docs.py +++ b/build_docs.py @@ -748,7 +748,7 @@ def build(self): # Disable CPython switchers, we handle them now: def is_mac(): - return platform.system() == 'Darwin' + return platform.system() == "Darwin" run( ["sed", "-i"] diff --git a/check_times.py b/check_times.py index b7dbec8..4b6665d 100644 --- a/check_times.py +++ b/check_times.py @@ -15,21 +15,22 @@ from build_docs import format_seconds + def get_lines() -> list[str]: lines = [] zipped_logs = list(Path.cwd().glob("docsbuild.log.*.gz")) - zipped_logs.sort(key=lambda p: int(p.name.split('.')[-2]), reverse=True) + zipped_logs.sort(key=lambda p: int(p.name.split(".")[-2]), reverse=True) for logfile in zipped_logs: with gzip.open(logfile, "rt", encoding="utf-8") as f: lines += f.readlines() with open("docsbuild.log", encoding="utf-8") as f: - lines += f.readlines() + lines += f.readlines() return lines def calc_time(lines: list[str]) -> None: start = end = language = version = start_timestamp = None - reason = lang_ver = '' + reason = lang_ver = "" print("Start | Version | Language | Build | Trigger") print(":-- | :--: | :--: | --: | :--:") @@ -37,15 +38,15 @@ def calc_time(lines: list[str]) -> None: for line in lines: line = line.strip() - if ': Should rebuild: ' in line: - if 'no previous state found' in line: - reason = 'brand new' - elif 'new translations' in line: - reason = 'translation' - elif 'Doc/ has changed' in line: - reason = 'docs' + if ": Should rebuild: " in line: + if "no previous state found" in line: + reason = "brand new" + elif "new translations" in line: + reason = "translation" + elif "Doc/ has changed" in line: + reason = "docs" else: - reason = '' + reason = "" lang_ver = line.split(" ")[3].removesuffix(":") if line.endswith("Build start."): @@ -62,19 +63,24 @@ def calc_time(lines: list[str]) -> None: if start and end: duration = (end - start).total_seconds() fmt_duration = format_seconds(duration) - if lang_ver != f'{language}/{version}': - reason = '' - print(f"{start_timestamp: <20} | {version: <7} | {language: <8} | {fmt_duration :<14} | {reason}") + if lang_ver != f"{language}/{version}": + reason = "" + print( + f"{start_timestamp: <20} | {version: <7} | {language: <8} | {fmt_duration :<14} | {reason}" + ) start = end = start_timestamp = None - if ': Full build done' in line: + if ": Full build done" in line: timestamp = f"{line[:16]} UTC" _, fmt_duration = line.removesuffix(").").split("(") - print(f"{timestamp: <20} | --FULL- | -BUILD-- | {fmt_duration :<14} | -----------") + print( + f"{timestamp: <20} | --FULL- | -BUILD-- | {fmt_duration :<14} | -----------" + ) if start and end is None: - print(f"{start_timestamp: <20} | {version: <7} | {language: <8} | In progress... | {reason}") - + print( + f"{start_timestamp: <20} | {version: <7} | {language: <8} | In progress... | {reason}" + ) if __name__ == "__main__":