def run(self, start_time: float) -> ExitCode: run_tracker = RunTracker.global_instance() self._start_run(run_tracker, start_time) with maybe_profiled(self.profile_path): global_options = self.options.for_global_scope() if self.options.help_request: return self._print_help(self.options.help_request) streaming_handlers = global_options.streaming_workunits_handlers callbacks = Subsystem.get_streaming_workunit_callbacks( streaming_handlers) streaming_reporter = StreamingWorkunitHandler( self.graph_session.scheduler_session, callbacks=callbacks, report_interval_seconds=global_options. streaming_workunits_report_interval, ) goals = tuple(self.options.goals) with streaming_reporter.session(): engine_result = PANTS_FAILED_EXIT_CODE try: engine_result = self._run_v2(goals) except Exception as e: ExceptionSink.log_exception(e) self._finish_run(run_tracker, engine_result) return engine_result
def test_streaming_workunit_callbacks_bad_module(self) -> None: import_str = "nonexistent_module.AClassThatDoesntActuallyExist" with self.captured_logging(level=logging.WARNING) as captured: callables_list = Subsystem.get_streaming_workunit_callbacks( [import_str]) warnings = captured.warnings() assert len(warnings) == 1 assert len(callables_list) == 0 assert "No module named 'nonexistent_module'" in warnings[0]
def test_streaming_workunit_callbacks_bad_module(caplog) -> None: import_str = "nonexistent_module.AClassThatDoesntActuallyExist" callables_list = Subsystem.get_streaming_workunit_callbacks([import_str]) assert len(callables_list) == 0 warnings = [ record for record in caplog.records if record.levelname == "WARNING" ] assert len(warnings) == 1 assert "No module named 'nonexistent_module'" in warnings[0].msg
def test_streaming_workunit_callbacks_with_invalid_subsystem(self) -> None: import_str = "pants.option.subsystem_test.DummySubsystem" with self.captured_logging(level=logging.WARNING) as captured: callables_list = Subsystem.get_streaming_workunit_callbacks( [import_str]) warnings = captured.warnings() assert len(warnings) == 1 assert "does not have a method named `handle_workunits` defined" in warnings[ 0] assert len(callables_list) == 0
def test_streaming_workunit_callbacks_with_invalid_subsystem(caplog) -> None: import_str = "pants.option.subsystem_test.DummySubsystem" callables_list = Subsystem.get_streaming_workunit_callbacks([import_str]) assert len(callables_list) == 0 warnings = [ record for record in caplog.records if record.levelname == "WARNING" ] assert len(warnings) == 1 assert "does not have a method named `handle_workunits` defined" in warnings[ 0].msg
def test_streaming_workunit_callbacks_good_module_bad_class(self) -> None: import_str = "pants.option.subsystem_test.ANonexistentClass" with self.captured_logging(level=logging.WARNING) as captured: callables_list = Subsystem.get_streaming_workunit_callbacks( [import_str]) warnings = captured.warnings() assert len(warnings) == 1 assert len(callables_list) == 0 assert ( "module 'pants.option.subsystem_test' has no attribute 'ANonexistentClass'" in warnings[0])
def test_streaming_workunit_callbacks_good_module_bad_class(caplog) -> None: import_str = "pants.option.subsystem_test.ANonexistentClass" callables_list = Subsystem.get_streaming_workunit_callbacks([import_str]) assert len(callables_list) == 0 warnings = [ record for record in caplog.records if record.levelname == "WARNING" ] assert len(warnings) == 1 assert ( "module 'pants.option.subsystem_test' has no attribute 'ANonexistentClass'" in warnings[0].msg)
def run(self, start_time: float) -> ExitCode: self._set_start_time(start_time) with maybe_profiled(self.profile_path): global_options = self.options.for_global_scope() streaming_handlers = global_options.streaming_workunits_handlers report_interval = global_options.streaming_workunits_report_interval callbacks = Subsystem.get_streaming_workunit_callbacks( streaming_handlers) streaming_reporter = StreamingWorkunitHandler( self.graph_session.scheduler_session, callbacks=callbacks, report_interval_seconds=report_interval, ) if self.options.help_request: all_help_info = HelpInfoExtracter.get_all_help_info( self.options, self.union_membership, self.graph_session.goal_consumed_subsystem_scopes, ) help_printer = HelpPrinter( bin_name=global_options.pants_bin_name, help_request=self.options.help_request, all_help_info=all_help_info, use_color=global_options.colors, ) return help_printer.print_help() with streaming_reporter.session(): engine_result = PANTS_FAILED_EXIT_CODE try: engine_result = self._run_v2() except Exception as e: ExceptionSink.log_exception(e) run_tracker_result = self._finish_run(engine_result) return self._merge_exit_codes(engine_result, run_tracker_result)
def test_get_streaming_workunit_callbacks(self) -> None: import_str = "pants.option.subsystem_test.WorkunitSubscriptableSubsystem" callables_list = Subsystem.get_streaming_workunit_callbacks( [import_str]) assert len(callables_list) == 1