def run(self, start_time: float) -> ExitCode: with maybe_profiled(self.profile_path): spec_parser = SpecsParser() specs = [] for spec_str in self.options.specs: spec, is_ignore = spec_parser.parse_spec(spec_str) specs.append(f"-{spec}" if is_ignore else str(spec)) self.run_tracker.start(run_start_time=start_time, specs=specs) global_options = self.options.for_global_scope() streaming_reporter = StreamingWorkunitHandler( self.graph_session.scheduler_session, run_tracker=self.run_tracker, specs=self.specs, options_bootstrapper=self.options_bootstrapper, callbacks=self._get_workunits_callbacks(), report_interval_seconds=global_options. streaming_workunits_report_interval, allow_async_completion=( global_options.pantsd and global_options.streaming_workunits_complete_async), max_workunit_verbosity=global_options. streaming_workunits_level, ) with streaming_reporter: engine_result = PANTS_FAILED_EXIT_CODE try: engine_result = self._run_inner() finally: metrics = self.graph_session.scheduler_session.metrics() self.run_tracker.set_pantsd_scheduler_metrics(metrics) self.run_tracker.end_run(engine_result) return engine_result
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 run(self): global_options = self.options.for_global_scope() exiter = LocalExiter.wrap_global_exiter(self._run_tracker, self._repro) profiled = maybe_profiled(self.profile_path) with exiter, profiled: 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: help_printer = HelpPrinter( options=self.options, union_membership=self.union_membership) help_output = help_printer.print_help() self._exiter.exit(help_output) v1 = global_options.v1 v2 = global_options.v2 with streaming_reporter.session(): try: engine_result = self._maybe_run_v2(v2) goal_runner_result = self._maybe_run_v1(v1) finally: run_tracker_result = self._finish_run() final_exit_code = self._compute_final_exit_code( engine_result, goal_runner_result, run_tracker_result) self._exiter.exit(final_exit_code)
def handle(self): """Request handler for a single Pailgun request.""" # Parse the Nailgun request portion. _, _, arguments, environment = self.parsed_request() # N.B. the first and second nailgun request arguments (working_dir and command) are currently # ignored in favor of a get_buildroot() call within LocalPantsRunner.run() and an assumption # that anyone connecting to this nailgun server always intends to run pants itself. # Prepend the command to our arguments so it aligns with the expected sys.argv format of python # (e.g. [list', '::'] -> ['./pants', 'list', '::']). arguments.insert(0, './pants') self.logger.info('handling pailgun request: `{}`'.format(' '.join(arguments))) self.logger.debug('pailgun request environment: %s', environment) # We don't support parallel runs in pantsd, and therefore if this pailgun request # triggers any pants command, we want it to not use pantsd at all. # See https://github.com/pantsbuild/pants/issues/7881 for context. environment["PANTS_CONCURRENT"] = "True" # Execute the requested command with optional daemon-side profiling. with maybe_profiled(environment.get('PANTSD_PROFILE')): self._run_pants(self.request, arguments, environment) # NB: This represents the end of pantsd's involvement in the request, but the request will # continue to run post-fork. self.logger.info('pailgun request completed: `{}`'.format(' '.join(arguments)))
def run(self, start_time: float) -> ExitCode: spec_parser = SpecsParser(get_buildroot()) specs = [str(spec_parser.parse_spec(spec)) for spec in self.options.specs] self.run_tracker.start(run_start_time=start_time, specs=specs) 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_reporter = StreamingWorkunitHandler( self.graph_session.scheduler_session, run_tracker=self.run_tracker, callbacks=self._get_workunits_callbacks(), report_interval_seconds=global_options.streaming_workunits_report_interval, ) goals = tuple(self.options.goals) with streaming_reporter.session(): if not goals: return PANTS_SUCCEEDED_EXIT_CODE engine_result = PANTS_FAILED_EXIT_CODE try: engine_result = self._perform_run(goals) except Exception as e: ExceptionSink.log_exception(e) metrics = self.graph_session.scheduler_session.metrics() self.run_tracker.set_pantsd_scheduler_metrics(metrics) self.run_tracker.end_run(engine_result) return engine_result
def handle(self): """Request handler for a single Pailgun request.""" # Parse the Nailgun request portion. _, _, arguments, environment = NailgunProtocol.parse_request( self.request) # N.B. the first and second nailgun request arguments (working_dir and command) are currently # ignored in favor of a get_buildroot() call within LocalPantsRunner.run() and an assumption # that anyone connecting to this nailgun server always intends to run pants itself. # Prepend the command to our arguments so it aligns with the expected sys.argv format of python # (e.g. [list', '::'] -> ['./pants', 'list', '::']). arguments.insert(0, './pants') self.logger.info('handling pailgun request: `{}`'.format( ' '.join(arguments))) self.logger.debug('pailgun request environment: %s', environment) # Execute the requested command with optional daemon-side profiling. with maybe_profiled(environment.get('PANTSD_PROFILE')): self._run_pants(self.request, arguments, environment) # NB: This represents the end of pantsd's involvement in the request, but the request will # continue to run post-fork. self.logger.info('pailgun request completed: `{}`'.format( ' '.join(arguments)))
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: help_printer = HelpPrinter( options=self.options, union_membership=self.union_membership) return help_printer.print_help() v1 = global_options.v1 v2 = global_options.v2 with streaming_reporter.session(): engine_result, goal_runner_result = PANTS_FAILED_EXIT_CODE, PANTS_FAILED_EXIT_CODE try: engine_result = self._maybe_run_v2(v2) goal_runner_result = self._maybe_run_v1(v1) except Exception as e: ExceptionSink.log_exception(e) run_tracker_result = self._finish_run( self._merge_exit_codes(engine_result, goal_runner_result)) return self._merge_exit_codes(engine_result, goal_runner_result, run_tracker_result)
def run(self, start_time: float) -> ExitCode: with maybe_profiled(self.profile_path): spec_parser = SpecsParser(get_buildroot()) specs = [ str(spec_parser.parse_spec(spec)) for spec in self.options.specs ] self.run_tracker.start(run_start_time=start_time, specs=specs) global_options = self.options.for_global_scope() streaming_reporter = StreamingWorkunitHandler( self.graph_session.scheduler_session, run_tracker=self.run_tracker, specs=self.specs, options_bootstrapper=self.options_bootstrapper, callbacks=self._get_workunits_callbacks(), report_interval_seconds=global_options. streaming_workunits_report_interval, pantsd=global_options.pantsd, ) with streaming_reporter: engine_result = PANTS_FAILED_EXIT_CODE try: engine_result = self._run_inner() finally: metrics = self.graph_session.scheduler_session.metrics() self.run_tracker.set_pantsd_scheduler_metrics(metrics) self.run_tracker.end_run(engine_result) return engine_result
def main(): start_time = time.time() with maybe_profiled(os.environ.get('PANTSC_PROFILE')): try: PantsRunner(start_time=start_time).run() except KeyboardInterrupt as e: ExceptionSink.get_global_exiter().exit_and_fail( 'Interrupted by user:\n{}'.format(e))
def main(): exiter = Exiter() exiter.set_except_hook() with maybe_profiled(os.environ.get('PANTSC_PROFILE')): try: PantsRunner(exiter).run() except KeyboardInterrupt: exiter.exit_and_fail(b'Interrupted by user.')
def run_default_entrypoint() -> None: with maybe_profiled(os.environ.get(PANTSC_PROFILE)): start_time = time.time() try: runner = PantsRunner(args=sys.argv, env=os.environ) exit_code = runner.run(start_time) except KeyboardInterrupt as e: print(f"Interrupted by user:\n{e}", file=sys.stderr) exit_code = PANTS_FAILED_EXIT_CODE sys.exit(exit_code)
def main(): start_time = time.time() exiter = Exiter() ExceptionSink.reset_exiter(exiter) with maybe_profiled(os.environ.get('PANTSC_PROFILE')): try: PantsRunner(exiter, start_time=start_time).run() except KeyboardInterrupt as e: exiter.exit_and_fail('Interrupted by user:\n{}'.format(e))
def main(): start_time = time.time() exiter = Exiter() ExceptionSink.reset_exiter(exiter) with maybe_profiled(os.environ.get('PANTSC_PROFILE')): try: PantsRunner(exiter, start_time=start_time).run() except KeyboardInterrupt: exiter.exit_and_fail('Interrupted by user.')
def test_maybe_profiled(self): with temporary_dir() as td: profile_path = os.path.join(td, 'profile.prof') with maybe_profiled(profile_path): for _ in range(5): print('test') # Ensure the profile data was written. self.assertTrue(os.path.exists(profile_path)) # Ensure the profile data is valid. pstats.Stats(profile_path).print_stats()
def main(): with maybe_profiled(os.environ.get("PANTSC_PROFILE")): start_time = time.time() try: runner = PantsRunner(args=sys.argv, env=os.environ) exit_code = runner.run(start_time) except KeyboardInterrupt as e: print("Interrupted by user:\n{}".format(e), file=sys.stderr) exit_code = PANTS_FAILED_EXIT_CODE except Exception as e: logger.exception(e) exit_code = PANTS_FAILED_EXIT_CODE sys.exit(exit_code)
def handle(self): """Request handler for a single Pailgun request.""" # Parse the Nailgun request portion. _, _, arguments, environment = NailgunProtocol.parse_request(self.request) # N.B. the first and second nailgun request arguments (working_dir and command) are currently # ignored in favor of a get_buildroot() call within LocalPantsRunner.run() and an assumption # that anyone connecting to this nailgun server always intends to run pants itself. # Prepend the command to our arguments so it aligns with the expected sys.argv format of python # (e.g. [list', '::'] -> ['./pants', 'list', '::']). arguments.insert(0, './pants') self.logger.info('handling pailgun request: `{}`'.format(' '.join(arguments))) self.logger.debug('pailgun request environment: %s', environment) # Execute the requested command with optional daemon-side profiling. with maybe_profiled(environment.get('PANTSD_PROFILE')): self._run_pants(self.request, arguments, environment)
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 run(self): profile_path = self._env.get('PANTS_PROFILE') with hard_exit_handler(), maybe_profiled(profile_path): self._run()
def run(self): with LocalExiter.wrap_global_exiter(self._run_tracker, self._repro), \ maybe_profiled(self._profile_path): self._run()
def run(self): with hard_exit_handler(), maybe_profiled(self._profile_path): self._run()
def run(self): with maybe_profiled(self._profile_path): self._run()