2828import json
2929import logging
3030import logging .handlers
31- from functools import total_ordering
31+ from functools import total_ordering , cache
3232from os import readlink
3333import platform
3434import re
@@ -702,6 +702,7 @@ def translation_branch(self):
702702 def build (self ):
703703 """Build this version/language doc."""
704704 logging .info ("Build start." )
705+ start_time = perf_counter ()
705706 sphinxopts = list (self .language .sphinxopts )
706707 sphinxopts .extend (["-q" ])
707708 if self .language .tag != "en" :
@@ -778,7 +779,7 @@ def is_mac():
778779 setup_switchers (
779780 self .versions , self .languages , self .checkout / "Doc" / "build" / "html"
780781 )
781- logging .info ("Build done." )
782+ logging .info ("Build done (%s)." , format_seconds ( perf_counter () - start_time ) )
782783
783784 def build_venv (self ):
784785 """Build a venv for the specific Python version.
@@ -800,6 +801,7 @@ def build_venv(self):
800801 def copy_build_to_webroot (self ):
801802 """Copy a given build to the appropriate webroot with appropriate rights."""
802803 logging .info ("Publishing start." )
804+ start_time = perf_counter ()
803805 self .www_root .mkdir (parents = True , exist_ok = True )
804806 if self .language .tag == "en" :
805807 target = self .www_root / self .version .name
@@ -912,7 +914,9 @@ def copy_build_to_webroot(self):
912914 purge (* prefixes )
913915 for prefix in prefixes :
914916 purge (* [prefix + p for p in changed ])
915- logging .info ("Publishing done" )
917+ logging .info (
918+ "Publishing done (%s)." , format_seconds (perf_counter () - start_time )
919+ )
916920
917921 def should_rebuild (self ):
918922 state = self .load_state ()
@@ -1147,6 +1151,21 @@ def build_docs(args) -> bool:
11471151 return all_built_successfully
11481152
11491153
1154+ @cache
1155+ def format_seconds (seconds : float ) -> str :
1156+ hours , remainder = divmod (seconds , 3600 )
1157+ minutes , seconds = divmod (remainder , 60 )
1158+ seconds = round (seconds )
1159+
1160+ match (hours , minutes , seconds ):
1161+ case 0 , 0 , s :
1162+ return f"{ s } s"
1163+ case 0 , m , s :
1164+ return f"{ m } m { s } s"
1165+ case h , m , s :
1166+ return f"{ h } h { m } m { s } s"
1167+
1168+
11501169def main ():
11511170 """Script entry point."""
11521171 args = parse_args ()
0 commit comments