Skip to content

Commit 30d3e00

Browse files
committed
feat(toxgen): Remove merge conflict-prone last updated timestamp
1 parent d9811fe commit 30d3e00

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

scripts/populate_tox/populate_tox.py

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import hashlib
99
import json
1010
import os
11+
import subprocess
1112
import sys
1213
import time
1314
from bisect import bisect_left
@@ -509,9 +510,7 @@ def _render_dependencies(integration: str, releases: list[Version]) -> list[str]
509510
return rendered
510511

511512

512-
def write_tox_file(
513-
packages: dict, update_timestamp: bool, last_updated: datetime
514-
) -> None:
513+
def write_tox_file(packages: dict) -> None:
515514
template = ENV.get_template("tox.jinja")
516515

517516
context = {"groups": {}}
@@ -530,11 +529,6 @@ def write_tox_file(
530529
}
531530
)
532531

533-
if update_timestamp:
534-
context["updated"] = datetime.now(tz=timezone.utc).isoformat()
535-
else:
536-
context["updated"] = last_updated.isoformat()
537-
538532
rendered = template.render(context)
539533

540534
with open(TOX_FILE, "w") as file:
@@ -623,19 +617,16 @@ def get_file_hash() -> str:
623617

624618

625619
def get_last_updated() -> Optional[datetime]:
626-
timestamp = None
627-
628-
with open(TOX_FILE, "r") as f:
629-
for line in f:
630-
if line.startswith("# Last generated:"):
631-
timestamp = datetime.fromisoformat(line.strip().split()[-1])
632-
break
633-
634-
if timestamp is None:
635-
print(
636-
"Failed to find out when tox.ini was last generated; the timestamp seems to be missing from the file."
620+
timestamp = (
621+
subprocess.run(
622+
["git", "log", "-1", "--pretty=%ct", "../tox.ini"],
623+
capture_output=True,
637624
)
638-
625+
.stdout.decode("utf-8")
626+
.strip()
627+
)
628+
timestamp = datetime.fromtimestamp(int(timestamp), timezone.utc)
629+
print(f"Last tox.ini update: {timestamp}")
639630
return timestamp
640631

641632

@@ -675,7 +666,7 @@ def main(fail_on_changes: bool = False) -> None:
675666
print(f"Running in {'fail_on_changes' if fail_on_changes else 'normal'} mode.")
676667
last_updated = get_last_updated()
677668
if fail_on_changes:
678-
# We need to make the script ignore any new releases after the `last_updated`
669+
# We need to make the script ignore any new releases after the last updated
679670
# timestamp so that we don't fail CI on a PR just because a new package
680671
# version was released, leading to unrelated changes in tox.ini.
681672
print(
@@ -769,9 +760,7 @@ def main(fail_on_changes: bool = False) -> None:
769760
if fail_on_changes:
770761
old_file_hash = get_file_hash()
771762

772-
write_tox_file(
773-
packages, update_timestamp=not fail_on_changes, last_updated=last_updated
774-
)
763+
write_tox_file(packages)
775764

776765
# Sort the release cache file
777766
releases = []

scripts/populate_tox/tox.jinja

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
# or in the script (if you want to change the auto-generated part).
1010
# The file (and all resulting CI YAMLs) then need to be regenerated via
1111
# "scripts/generate-test-files.sh".
12-
#
13-
# Last generated: {{ updated }}
1412

1513
[tox]
1614
requires =

tox.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
# or in the script (if you want to change the auto-generated part).
1010
# The file (and all resulting CI YAMLs) then need to be regenerated via
1111
# "scripts/generate-test-files.sh".
12-
#
13-
# Last generated: 2025-09-24T08:25:49.003370+00:00
1412

1513
[tox]
1614
requires =

0 commit comments

Comments
 (0)