8
8
import hashlib
9
9
import json
10
10
import os
11
+ import subprocess
11
12
import sys
12
13
import time
13
14
from bisect import bisect_left
@@ -509,9 +510,7 @@ def _render_dependencies(integration: str, releases: list[Version]) -> list[str]
509
510
return rendered
510
511
511
512
512
- def write_tox_file (
513
- packages : dict , update_timestamp : bool , last_updated : datetime
514
- ) -> None :
513
+ def write_tox_file (packages : dict ) -> None :
515
514
template = ENV .get_template ("tox.jinja" )
516
515
517
516
context = {"groups" : {}}
@@ -530,11 +529,6 @@ def write_tox_file(
530
529
}
531
530
)
532
531
533
- if update_timestamp :
534
- context ["updated" ] = datetime .now (tz = timezone .utc ).isoformat ()
535
- else :
536
- context ["updated" ] = last_updated .isoformat ()
537
-
538
532
rendered = template .render (context )
539
533
540
534
with open (TOX_FILE , "w" ) as file :
@@ -623,19 +617,16 @@ def get_file_hash() -> str:
623
617
624
618
625
619
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 ,
637
624
)
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 } " )
639
630
return timestamp
640
631
641
632
@@ -675,7 +666,7 @@ def main(fail_on_changes: bool = False) -> None:
675
666
print (f"Running in { 'fail_on_changes' if fail_on_changes else 'normal' } mode." )
676
667
last_updated = get_last_updated ()
677
668
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
679
670
# timestamp so that we don't fail CI on a PR just because a new package
680
671
# version was released, leading to unrelated changes in tox.ini.
681
672
print (
@@ -769,9 +760,7 @@ def main(fail_on_changes: bool = False) -> None:
769
760
if fail_on_changes :
770
761
old_file_hash = get_file_hash ()
771
762
772
- write_tox_file (
773
- packages , update_timestamp = not fail_on_changes , last_updated = last_updated
774
- )
763
+ write_tox_file (packages )
775
764
776
765
# Sort the release cache file
777
766
releases = []
0 commit comments