def _init_graph_session( cls, options_bootstrapper: OptionsBootstrapper, build_config: BuildConfiguration, run_id: str, options: Options, scheduler: Optional[GraphScheduler] = None, cancellation_latch: Optional[PySessionCancellationLatch] = None, ) -> GraphSession: native = Native() native.set_panic_handler() graph_scheduler_helper = scheduler or EngineInitializer.setup_graph( options_bootstrapper, build_config ) try: global_scope = options.for_global_scope() except UnknownFlagsError as err: cls._handle_unknown_flags(err, options_bootstrapper) raise return graph_scheduler_helper.new_session( run_id, dynamic_ui=global_scope.dynamic_ui, use_colors=global_scope.get("colors", True), session_values=SessionValues( { OptionsBootstrapper: options_bootstrapper, PantsEnvironment: PantsEnvironment(os.environ), } ), cancellation_latch=cancellation_latch, )
def _init_scheduler(self, options_fingerprint: str, options_bootstrapper: OptionsBootstrapper) -> None: """(Re-)Initialize the scheduler. Must be called under the lifecycle lock. """ try: if self._scheduler: logger.info( "initialization options changed: reinitializing pantsd...") else: logger.info("initializing pantsd...") if self._services: self._services.shutdown() build_config = BuildConfigInitializer.get(options_bootstrapper) self._scheduler = EngineInitializer.setup_graph( options_bootstrapper, build_config) bootstrap_options_values = options_bootstrapper.bootstrap_options.for_global_scope( ) setup_warning_filtering( bootstrap_options_values.ignore_pants_warnings or []) self._services = self._services_constructor( bootstrap_options_values, self._scheduler) self._fingerprint = options_fingerprint logger.info("pantsd initialized.") except Exception as e: self._kill_switch.set() self._scheduler = None raise e
def _init_graph_session( cls, options_bootstrapper: OptionsBootstrapper, build_config: BuildConfiguration, options: Options, scheduler: Optional[GraphScheduler] = None, ) -> GraphSession: native = Native() native.set_panic_handler() graph_scheduler_helper = scheduler or EngineInitializer.setup_graph( options_bootstrapper, build_config) try: global_scope = options.for_global_scope() except UnknownFlagsError as err: cls._handle_unknown_flags(err, options_bootstrapper) raise stream_workunits = len( options.for_global_scope().streaming_workunits_handlers) != 0 return graph_scheduler_helper.new_session( RunTracker.global_instance().run_id, dynamic_ui=global_scope.dynamic_ui, use_colors=global_scope.get("colors", True), should_report_workunits=stream_workunits, session_values=SessionValues({ OptionsBootstrapper: options_bootstrapper, PantsEnvironment: PantsEnvironment(os.environ), }), )
def _init_graph_session( cls, options_initializer: OptionsInitializer, options_bootstrapper: OptionsBootstrapper, build_config: BuildConfiguration, env: CompleteEnvironment, run_id: str, options: Options, scheduler: Optional[GraphScheduler] = None, cancellation_latch: Optional[PySessionCancellationLatch] = None, ) -> GraphSession: native_engine.maybe_set_panic_handler() if scheduler is None: dynamic_remote_options, _ = DynamicRemoteOptions.from_options(options, env) bootstrap_options = options.bootstrap_option_values() assert bootstrap_options is not None scheduler = EngineInitializer.setup_graph( bootstrap_options, build_config, dynamic_remote_options ) with options_initializer.handle_unknown_flags(options_bootstrapper, env, raise_=True): global_options = options.for_global_scope() return scheduler.new_session( run_id, dynamic_ui=global_options.dynamic_ui, use_colors=global_options.get("colors", True), session_values=SessionValues( { OptionsBootstrapper: options_bootstrapper, CompleteEnvironment: env, } ), cancellation_latch=cancellation_latch, )
def _init_graph_session( cls, options_initializer: OptionsInitializer, options_bootstrapper: OptionsBootstrapper, build_config: BuildConfiguration, env: CompleteEnvironment, run_id: str, options: Options, scheduler: Optional[GraphScheduler] = None, cancellation_latch: Optional[PySessionCancellationLatch] = None, ) -> GraphSession: native = Native() native.set_panic_handler() graph_scheduler_helper = scheduler or EngineInitializer.setup_graph( options_bootstrapper, build_config, env ) with options_initializer.handle_unknown_flags(options_bootstrapper, env, raise_=True): global_options = options.for_global_scope() return graph_scheduler_helper.new_session( run_id, dynamic_ui=global_options.dynamic_ui, use_colors=global_options.get("colors", True), session_values=SessionValues( { OptionsBootstrapper: options_bootstrapper, CompleteEnvironment: env, } ), cancellation_latch=cancellation_latch, )
def _init_scheduler(self, options_fingerprint: str, options_bootstrapper: OptionsBootstrapper) -> None: """(Re-)Initialize the scheduler. Must be called under the lifecycle lock. """ try: if self._scheduler: logger.info( "initialization options changed: reinitializing pantsd...") else: logger.info("initializing pantsd...") if self._services: self._services.shutdown() with OptionsInitializer.handle_unknown_flags(options_bootstrapper, raise_=True): build_config = BuildConfigInitializer.get(options_bootstrapper) options = OptionsInitializer.create(options_bootstrapper, build_config) self._scheduler = EngineInitializer.setup_graph( options, build_config, executor=self._executor) bootstrap_options_values = options.bootstrap_option_values() assert bootstrap_options_values is not None self._services = self._services_constructor( bootstrap_options_values, self._scheduler) self._fingerprint = options_fingerprint logger.info("pantsd initialized.") except Exception as e: self._kill_switch.set() self._scheduler = None raise e
def _initialize( self, options_fingerprint: str, bootstrap_options: OptionValueContainer, build_config: BuildConfiguration, dynamic_remote_options: DynamicRemoteOptions, scheduler_restart_explanation: str | None, ) -> None: """(Re-)Initialize the scheduler. Must be called under the lifecycle lock. """ try: logger.info( f"{scheduler_restart_explanation}: reinitializing scheduler..." if scheduler_restart_explanation else "Initializing scheduler...") if self._services: self._services.shutdown() self._scheduler = EngineInitializer.setup_graph( bootstrap_options, build_config, dynamic_remote_options, self._executor) self._services = self._services_constructor( bootstrap_options, self._scheduler) self._fingerprint = options_fingerprint logger.info("Scheduler initialized.") except Exception as e: self._kill_switch.set() self._scheduler = None raise e
def _initialize(self, options_fingerprint: str, options_bootstrapper: OptionsBootstrapper) -> None: """(Re-)Initialize the scheduler. Must be called under the lifecycle lock. """ try: if self._scheduler: logger.info( "initialization options changed: reinitializing scheduler..." ) else: logger.info("initializing scheduler...") if self._services: self._services.shutdown() build_config, options = self._options_initializer.build_config_and_options( options_bootstrapper, raise_=True) self._scheduler = EngineInitializer.setup_graph( options_bootstrapper, build_config, executor=self._executor) bootstrap_options_values = options.bootstrap_option_values() assert bootstrap_options_values is not None self._services = self._services_constructor( bootstrap_options_values, self._scheduler) self._fingerprint = options_fingerprint logger.info("scheduler initialized.") except Exception as e: self._kill_switch.set() self._scheduler = None raise e
def create_bootstrap_scheduler( options_bootstrapper: OptionsBootstrapper, executor: PyExecutor | None = None) -> BootstrapScheduler: bc_builder = BuildConfiguration.Builder() # To load plugins, we only need access to the Python/PEX rules. load_build_configuration_from_source(bc_builder, ["pants.backend.python"]) # And to plugin-loading-specific rules. bc_builder.register_rules("_dummy_for_bootstrapping_", plugin_resolver_rules()) # We allow unrecognized options to defer any option error handling until post-bootstrap. bc_builder.allow_unknown_options() return BootstrapScheduler( EngineInitializer.setup_graph( options_bootstrapper.bootstrap_options.for_global_scope(), bc_builder.create(), DynamicRemoteOptions.disabled(), executor, ).scheduler)
def _init_graph_session( cls, options_initializer: OptionsInitializer, options_bootstrapper: OptionsBootstrapper, build_config: BuildConfiguration, env: CompleteEnvironment, run_id: str, options: Options, scheduler: GraphScheduler | None = None, cancellation_latch: PySessionCancellationLatch | None = None, ) -> GraphSession: native_engine.maybe_set_panic_handler() if scheduler is None: dynamic_remote_options, _ = DynamicRemoteOptions.from_options(options, env) bootstrap_options = options.bootstrap_option_values() assert bootstrap_options is not None scheduler = EngineInitializer.setup_graph( bootstrap_options, build_config, dynamic_remote_options ) with options_initializer.handle_unknown_flags(options_bootstrapper, env, raise_=True): global_options = options.for_global_scope() return scheduler.new_session( run_id, dynamic_ui=global_options.dynamic_ui, ui_use_prodash=global_options.dynamic_ui_renderer == DynamicUIRenderer.experimental_prodash, use_colors=global_options.get("colors", True), max_workunit_level=max( global_options.streaming_workunits_level, global_options.level, *( LogLevel[level.upper()] for level in global_options.log_levels_by_target.values() ), ), session_values=SessionValues( { OptionsBootstrapper: options_bootstrapper, CompleteEnvironment: env, } ), cancellation_latch=cancellation_latch, )
def create_bootstrap_scheduler( options_bootstrapper: OptionsBootstrapper, executor: Optional[PyExecutor] = None, ) -> BootstrapScheduler: bc_builder = BuildConfiguration.Builder() # To load plugins, we only need access to the Python/PEX rules. load_build_configuration_from_source(bc_builder, ["pants.backend.python"]) # And to plugin-loading-specific rules. bc_builder.register_rules(plugin_resolver_rules()) # We allow unrecognized options to defer any option error handling until post-bootstrap. bc_builder.allow_unknown_options() return BootstrapScheduler( EngineInitializer.setup_graph( options_bootstrapper, bc_builder.create(), executor=executor, # TODO: We use the default execution options to avoid invoking remote execution auth # plugins. They should be loaded via rules using the bootstrap Scheduler in the future. execution_options=DEFAULT_EXECUTION_OPTIONS, ).scheduler)
def _init_graph_session( options_bootstrapper: OptionsBootstrapper, build_config: BuildConfiguration, options: Options, scheduler: Optional[GraphScheduler] = None, ) -> GraphSession: native = Native() native.set_panic_handler() graph_scheduler_helper = scheduler or EngineInitializer.setup_graph( options_bootstrapper, build_config) global_scope = options.for_global_scope() dynamic_ui = global_scope.dynamic_ui if global_scope.v2 else False use_colors = global_scope.get("colors", True) stream_workunits = len( options.for_global_scope().streaming_workunits_handlers) != 0 return graph_scheduler_helper.new_session( RunTracker.global_instance().run_id, dynamic_ui=dynamic_ui, use_colors=use_colors, should_report_workunits=stream_workunits, )