@@ -658,10 +658,13 @@ def run(self) -> bool:
658
658
self .cpython_repo .switch (self .version .branch_or_tag )
659
659
if self .language .tag != "en" :
660
660
self .clone_translation ()
661
- self .build_venv ()
662
- self .build ()
663
- self .copy_build_to_webroot ()
664
- self .save_state (build_duration = perf_counter () - start_time )
661
+ if self .should_rebuild ():
662
+ self .build_venv ()
663
+ self .build ()
664
+ self .copy_build_to_webroot ()
665
+ self .save_state (build_duration = perf_counter () - start_time )
666
+ else :
667
+ logging .info ("Nothing changed." )
665
668
except Exception as err :
666
669
logging .exception ("Badly handled exception, human, please help." )
667
670
if sentry_sdk :
@@ -920,7 +923,35 @@ def copy_build_to_webroot(self):
920
923
purge (* [prefix + p for p in changed ])
921
924
logging .info ("Publishing done" )
922
925
923
- def save_state (self , build_duration ):
926
+ def should_rebuild (self ):
927
+ state = self .load_state ()
928
+ if not state :
929
+ return True
930
+ cpython_sha = self .cpython_repo .run ("rev-parse" , "HEAD" ).stdout .strip ()
931
+ if self .language .tag != "en" :
932
+ translation_sha = self .translation_repo .run (
933
+ "rev-parse" , "HEAD"
934
+ ).stdout .strip ()
935
+ if translation_sha != state ["translation_sha" ]:
936
+ return True
937
+ if cpython_sha != state ["cpython_sha" ]:
938
+ diff = self .cpython_repo .run (
939
+ "diff" , "--name-only" , state ["cpython_sha" ], cpython_sha
940
+ ).stdout
941
+ if "Doc/" in diff :
942
+ return True
943
+ return False
944
+
945
+ def load_state (self ) -> dict :
946
+ state_file = self .build_root / "state.toml"
947
+ try :
948
+ return tomlkit .loads (state_file .read_text (encoding = "UTF-8" ))[
949
+ f"/{ self .language .tag } /{ self .version .name } /"
950
+ ]
951
+ except KeyError :
952
+ return {}
953
+
954
+ def save_state (self , build_duration : float ):
924
955
"""Save current cpython sha1 and current translation sha1.
925
956
926
957
Using this we can deduce if a rebuild is needed or not.
@@ -939,11 +970,7 @@ def save_state(self, build_duration):
939
970
).stdout .strip ()
940
971
state ["last_build" ] = dt .now (timezone .utc )
941
972
state ["last_build_duration" ] = build_duration
942
-
943
- states .setdefault ("build" , {}).setdefault (self .language .tag , {})[
944
- self .version .name
945
- ] = state
946
-
973
+ states [f"/{ self .language .tag } /{ self .version .name } /" ] = state
947
974
state_file .write_text (tomlkit .dumps (states ), encoding = "UTF-8" )
948
975
949
976
0 commit comments