@@ -54,7 +54,9 @@ def pytask_extend_command_line_interface(cli: click.Group) -> None:
5454@hookimpl
5555def pytask_post_parse (config : dict [str , Any ]) -> None :
5656 """Register the export option."""
57- config ["pm" ].register (ProfilePlugin (RuntimeState .from_root (config ["root" ])))
57+ runtime_state = RuntimeState .from_root (config ["root" ])
58+ config ["pm" ].register (ProfilePlugin (runtime_state ))
59+ config ["pm" ].register (DurationNameSpace (runtime_state ))
5860 config ["pm" ].register (ExportNameSpace )
5961 config ["pm" ].register (FileSizeNameSpace )
6062
@@ -86,15 +88,6 @@ def pytask_execute_task_process_report(
8688 if report .outcome == TaskOutcome .SUCCESS and duration is not None :
8789 self .runtime_state .update_task (task , * duration )
8890
89- @hookimpl
90- def pytask_profile_add_info_on_task (
91- self , session : Session , tasks : list [PTask ], profile : dict [str , dict [str , Any ]]
92- ) -> None :
93- """Add the runtime for tasks to the profile."""
94- _ = session
95- for name , duration in self ._collect_runtimes (tasks ).items ():
96- profile [name ]["Duration (in s)" ] = round (duration , 2 )
97-
9891 @hookimpl
9992 def pytask_unconfigure (self , session : Session ) -> None :
10093 """Flush runtime information on normal build exits."""
@@ -104,13 +97,23 @@ def pytask_unconfigure(self, session: Session) -> None:
10497 return
10598 self .runtime_state .flush ()
10699
107- def _collect_runtimes (self , tasks : list [PTask ]) -> dict [str , float ]:
108- """Collect runtimes."""
109- return {
110- task .name : duration
111- for task in tasks
112- if (duration := self .runtime_state .get_duration (task )) is not None
113- }
100+
101+ class DurationNameSpace :
102+ """A namespace for adding durations to the profile."""
103+
104+ def __init__ (self , runtime_state : RuntimeState ) -> None :
105+ self .runtime_state = runtime_state
106+
107+ @hookimpl
108+ def pytask_profile_add_info_on_task (
109+ self , session : Session , tasks : list [PTask ], profile : dict [str , dict [str , Any ]]
110+ ) -> None :
111+ """Add the runtime for tasks to the profile."""
112+ _ = session
113+ for task in tasks :
114+ duration = self .runtime_state .get_duration (task )
115+ if duration is not None :
116+ profile [task .name ]["Duration (in s)" ] = round (duration , 2 )
114117
115118
116119@click .command (cls = ColoredCommand )
0 commit comments