Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log updates to state.toml #200

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ def full_build(self):
def run(self, http: urllib3.PoolManager) -> bool:
"""Build and publish a Python doc, for a language, and a version."""
start_time = perf_counter()
start_timestamp = dt.now(tz=timezone.utc).replace(microsecond=0)
logging.info("Running.")
try:
self.cpython_repo.switch(self.version.branch_or_tag)
Expand All @@ -619,7 +620,10 @@ def run(self, http: urllib3.PoolManager) -> bool:
self.build_venv()
self.build()
self.copy_build_to_webroot(http)
self.save_state(build_duration=perf_counter() - start_time)
self.save_state(
build_start=start_timestamp,
build_duration=perf_counter() - start_time,
)
except Exception as err:
logging.exception("Badly handled exception, human, please help.")
if sentry_sdk:
Expand Down Expand Up @@ -921,7 +925,7 @@ def load_state(self) -> dict:
except (KeyError, FileNotFoundError):
return {}

def save_state(self, build_duration: float):
def save_state(self, build_start: dt, build_duration: float):
"""Save current CPython sha1 and current translation sha1.

Using this we can deduce if a rebuild is needed or not.
Expand All @@ -932,17 +936,23 @@ def save_state(self, build_duration: float):
except FileNotFoundError:
states = tomlkit.document()

state = {}
state["cpython_sha"] = self.cpython_repo.run("rev-parse", "HEAD").stdout.strip()
key = f"/{self.language.tag}/{self.version.name}/"
state = {
"last_build_start": build_start,
"last_build_duration": round(build_duration, 0),
"cpython_sha": self.cpython_repo.run("rev-parse", "HEAD").stdout.strip(),
}
if self.language.tag != "en":
state["translation_sha"] = self.translation_repo.run(
"rev-parse", "HEAD"
).stdout.strip()
state["last_build"] = dt.now(timezone.utc)
state["last_build_duration"] = build_duration
states[f"/{self.language.tag}/{self.version.name}/"] = state
states[key] = state
state_file.write_text(tomlkit.dumps(states), encoding="UTF-8")

tbl = tomlkit.inline_table()
tbl |= state
logging.info("Saved new rebuild state for %s: %s", key, tbl.as_string())
AA-Turner marked this conversation as resolved.
Show resolved Hide resolved


def symlink(
www_root: Path,
Expand Down