Skip to content

Commit 2d438bf

Browse files
authored
Merge pull request #200 from AA-Turner/log-state
2 parents bce1bed + 094e52f commit 2d438bf

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

Diff for: build_docs.py

+23-11
Original file line numberDiff line numberDiff line change
@@ -610,16 +610,21 @@ def full_build(self):
610610
def run(self, http: urllib3.PoolManager) -> bool:
611611
"""Build and publish a Python doc, for a language, and a version."""
612612
start_time = perf_counter()
613+
start_timestamp = dt.now(tz=timezone.utc).replace(microsecond=0)
613614
logging.info("Running.")
614615
try:
615616
self.cpython_repo.switch(self.version.branch_or_tag)
616617
if self.language.tag != "en":
617618
self.clone_translation()
618-
if self.should_rebuild():
619+
if trigger_reason := self.should_rebuild():
619620
self.build_venv()
620621
self.build()
621622
self.copy_build_to_webroot(http)
622-
self.save_state(build_duration=perf_counter() - start_time)
623+
self.save_state(
624+
build_start=start_timestamp,
625+
build_duration=perf_counter() - start_time,
626+
trigger=trigger_reason,
627+
)
623628
except Exception as err:
624629
logging.exception("Badly handled exception, human, please help.")
625630
if sentry_sdk:
@@ -885,7 +890,7 @@ def should_rebuild(self):
885890
state = self.load_state()
886891
if not state:
887892
logging.info("Should rebuild: no previous state found.")
888-
return True
893+
return "no previous state"
889894
cpython_sha = self.cpython_repo.run("rev-parse", "HEAD").stdout.strip()
890895
if self.language.tag != "en":
891896
translation_sha = self.translation_repo.run(
@@ -897,7 +902,7 @@ def should_rebuild(self):
897902
state["translation_sha"],
898903
translation_sha,
899904
)
900-
return True
905+
return "new translations"
901906
if cpython_sha != state["cpython_sha"]:
902907
diff = self.cpython_repo.run(
903908
"diff", "--name-only", state["cpython_sha"], cpython_sha
@@ -908,7 +913,7 @@ def should_rebuild(self):
908913
state["cpython_sha"],
909914
cpython_sha,
910915
)
911-
return True
916+
return "Doc/ has changed"
912917
logging.info("Nothing changed, no rebuild needed.")
913918
return False
914919

@@ -921,7 +926,7 @@ def load_state(self) -> dict:
921926
except (KeyError, FileNotFoundError):
922927
return {}
923928

924-
def save_state(self, build_duration: float):
929+
def save_state(self, build_start: dt, build_duration: float, trigger: str):
925930
"""Save current CPython sha1 and current translation sha1.
926931
927932
Using this we can deduce if a rebuild is needed or not.
@@ -932,17 +937,24 @@ def save_state(self, build_duration: float):
932937
except FileNotFoundError:
933938
states = tomlkit.document()
934939

935-
state = {}
936-
state["cpython_sha"] = self.cpython_repo.run("rev-parse", "HEAD").stdout.strip()
940+
key = f"/{self.language.tag}/{self.version.name}/"
941+
state = {
942+
"last_build_start": build_start,
943+
"last_build_duration": round(build_duration, 0),
944+
"triggered_by": trigger,
945+
"cpython_sha": self.cpython_repo.run("rev-parse", "HEAD").stdout.strip(),
946+
}
937947
if self.language.tag != "en":
938948
state["translation_sha"] = self.translation_repo.run(
939949
"rev-parse", "HEAD"
940950
).stdout.strip()
941-
state["last_build"] = dt.now(timezone.utc)
942-
state["last_build_duration"] = build_duration
943-
states[f"/{self.language.tag}/{self.version.name}/"] = state
951+
states[key] = state
944952
state_file.write_text(tomlkit.dumps(states), encoding="UTF-8")
945953

954+
table = tomlkit.inline_table()
955+
table |= state
956+
logging.info("Saved new rebuild state for %s: %s", key, table.as_string())
957+
946958

947959
def symlink(
948960
www_root: Path,

0 commit comments

Comments
 (0)